+ Reply to Thread
Results 1 to 2 of 2

Thread: QwtDataSeries boundingRect() update to yMin and yMax on zoom

  1. #1
    Join Date
    Feb 2017
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QwtDataSeries boundingRect() update to yMin and yMax on zoom

    Hi,
    I'm having trouble understanding how to update my boundingRect() yMin and yMax values when the plot is zoomed using the QwtPlotZoomer. Ideally I'd like the YAxis to be autoscaled to the Zoom window.

    My understanding is that I need to somehow update my boundingRect() in my overloaded QwtDataSeries object but I have not found a solution.
    My YAxis values are always autoscaled to the min/max values of the entire data series as that's what is passed into the constructor

    Qt Code:
    1. MyDataSeries::MyDataSeries(struct MyData_struct *myData, qint64 startTime, double maxY, double minY)
    2. {
    3. _myData = myData;
    4. _startTime = startTime;
    5. _maxY = maxY;
    6. _minY = minY;
    7. }
    8.  
    9. size_t SacDataSeries::size() const
    10. {
    11. return _myData->npts;
    12. }
    13.  
    14. QPointF SacDataSeries::sample( size_t i ) const
    15. {
    16. return QPointF( _startTime + (i * _myData->delta*1000), _myData->data[i] );
    17. }
    18.  
    19. QRectF SacDataSeries::boundingRect() const
    20. {
    21. return QRect( 0.0, _minY , size() * (_myData->delta*1000), _maxY - (_minY) );
    22. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2017
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QwtDataSeries boundingRect() update to yMin and yMax on zoom

    Found workaround but it's kinda ugly:
    Find current x window, iterate over my data struct and find the max and min y values that way.

    It would be really great to have a plot->minY() plot->maxY() that gets the max value of a curve in the current X axis boundaries, but I don't think this exists in qwt

    Workaround
    Qt Code:
    1. //Find current x window
    2. QwtInterval intvA = plot->axisInterval (QwtPlot::xBottom);
    3. double minX = intvA.minValue();
    4. double maxX = intvA.maxValue();
    5.  
    6. double minY;
    7. double maxY;
    8.  
    9. //Convert ms -> sec,
    10. //remove offset,
    11. //then divide by the sample rate to get correct index values for myData
    12. minX = ((minX/1000) - myData->startTime_t)/myData->delta ;
    13. maxX = ((maxX/1000) - myData->startTime_t)/myData->delta ;
    14.  
    15. //To hold values in window
    16. double yVals[int(maxX-minX)];
    17.  
    18. //read in values
    19. int ind = 0;
    20. for(int i = minX; i < maxX; i ++)
    21. {
    22. yVals[ind] = myData->data[i];
    23. ind++;
    24. }
    25.  
    26. //find min and max
    27. maxY = max(maxX-minX, yVals,&err);
    28. minY = min(maxX-minX, yVals,&err);
    29.  
    30. //rescale Y axis
    31. plot->setAxisScale(QwtPlot::yLeft, minY,maxY);
    32. plot->replot();
    To copy to clipboard, switch view to plain text mode 



    Added after 18 minutes:


    Just added checks to allow QwtPanner to work with this as well,
    Checks for if the panner takes the data out of the bounds of the X axis

    Qt Code:
    1. ...
    2. int datalen = int(maxX-minX);
    3.  
    4. double yVals[datalen];
    5. int ind = 0;
    6. for(int i = minX; i < maxX; i ++)
    7. {
    8. //check to see if current location is out of bounds
    9. if(i >= 0 && i <= myData->numPoints)
    10. {
    11. yVals[ind] = myData->data[i];
    12. ind++;
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jeffL1349; 11th August 2017 at 18:20.

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 6th June 2016, 08:35
  2. Replies: 7
    Last Post: 8th March 2016, 07:26
  3. how to Update the boundingRect of a QGraphicsItemGroup
    By zhy0808 in forum Qt Programming
    Replies: 3
    Last Post: 12th July 2011, 20:48
  4. QWTPlot Zoom: cannot zoom negative value
    By jwieland in forum Qwt
    Replies: 0
    Last Post: 8th January 2010, 16:16
  5. Replies: 1
    Last Post: 16th November 2009, 05:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts