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();
//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();
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
...
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++;
}
}
...
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++;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks