PDA

View Full Version : QwtDataSeries boundingRect() update to yMin and yMax on zoom



jeffL1349
10th August 2017, 19:44
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



MyDataSeries::MyDataSeries(struct MyData_struct *myData, qint64 startTime, double maxY, double minY)
{
_myData = myData;
_startTime = startTime;
_maxY = maxY;
_minY = minY;
}

size_t SacDataSeries::size() const
{
return _myData->npts;
}

QPointF SacDataSeries::sample( size_t i ) const
{
return QPointF( _startTime + (i * _myData->delta*1000), _myData->data[i] );
}

QRectF SacDataSeries::boundingRect() const
{
return QRect( 0.0, _minY , size() * (_myData->delta*1000), _maxY - (_minY) );
}

jeffL1349
11th August 2017, 17:10
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


//Find current x window
QwtInterval intvA = plot->axisInterval (QwtPlot::xBottom);
double minX = intvA.minValue();
double maxX = intvA.maxValue();

double minY;
double maxY;

//Convert ms -> sec,
//remove offset,
//then divide by the sample rate to get correct index values for myData
minX = ((minX/1000) - myData->startTime_t)/myData->delta ;
maxX = ((maxX/1000) - myData->startTime_t)/myData->delta ;

//To hold values in window
double yVals[int(maxX-minX)];

//read in values
int ind = 0;
for(int i = minX; i < maxX; i ++)
{
yVals[ind] = myData->data[i];
ind++;
}

//find min and max
maxY = max(maxX-minX, yVals,&err);
minY = min(maxX-minX, yVals,&err);

//rescale Y axis
plot->setAxisScale(QwtPlot::yLeft, minY,maxY);
plot->replot();



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



...
int datalen = int(maxX-minX);

double yVals[datalen];
int ind = 0;
for(int i = minX; i < maxX; i ++)
{
//check to see if current location is out of bounds
if(i >= 0 && i <= myData->numPoints)
{
yVals[ind] = myData->data[i];
ind++;
}
}