I will try to get xBottom scale div, walk through data and find minimum and maximum in that interval. Unfortunately there is no signal that is emitted when scale div changes, so I will have to inherit both QwtPlotPanner and QwtPlotMagnifier, which is painful, but ok...
These connections may interest you, using only QwtScaleWidget::scaleDivChanged() didn't handle some plot movements, I don't recall why:
connect(panner, SIGNAL(panned(int,int)),
this, SLOT(updateYAxis()));
connect(axisWidget(xBottom), SIGNAL(scaleDivChanged()),
this, SLOT(updateYAxis()));
connect(panner, SIGNAL(panned(int,int)),
this, SLOT(updateYAxis()));
connect(axisWidget(xBottom), SIGNAL(scaleDivChanged()),
this, SLOT(updateYAxis()));
To copy to clipboard, switch view to plain text mode
You shouldn't need two for loops, or to set the initial min max values. I've pasted in the function similar to what I currently use on a candle plot, I limit the iterations with the bounds values, If you have data from a higher time frame that could be used to avoid most iterations.
void GraphicView::updateYAxis()
{
if (! m_samples.size() || axisAutoScale(yRight))
return;
const double lowerBound = axisScaleDiv(xBottom).lowerBound();
const double upperBound = axisScaleDiv(xBottom).upperBound();
double min, max, begin, end;
if (lowerBound < upperBound)
{
begin = lowerBound;
end = upperBound;
}
else
{
begin = upperBound;
end = lowerBound;
}
if( begin < 0 )
begin = 0;
if( end < 0 )
end = 0;
if( m_samples.size() < begin )
return;
if( m_samples.size() < end )
end = m_samples.size() - 1;
min = m_samples.low().at(begin);
max = m_samples.high().at(begin);
for ( int i = begin + 1; i <= end; ++i )
{
min = qMin( min, m_samples.low().at(i) );
max = qMax( max, m_samples.high().at(i) );
}
setAxisScale(yRight, min, max);
}
void GraphicView::updateYAxis()
{
if (! m_samples.size() || axisAutoScale(yRight))
return;
const double lowerBound = axisScaleDiv(xBottom).lowerBound();
const double upperBound = axisScaleDiv(xBottom).upperBound();
double min, max, begin, end;
if (lowerBound < upperBound)
{
begin = lowerBound;
end = upperBound;
}
else
{
begin = upperBound;
end = lowerBound;
}
if( begin < 0 )
begin = 0;
if( end < 0 )
end = 0;
if( m_samples.size() < begin )
return;
if( m_samples.size() < end )
end = m_samples.size() - 1;
min = m_samples.low().at(begin);
max = m_samples.high().at(begin);
for ( int i = begin + 1; i <= end; ++i )
{
min = qMin( min, m_samples.low().at(i) );
max = qMax( max, m_samples.high().at(i) );
}
setAxisScale(yRight, min, max);
}
To copy to clipboard, switch view to plain text mode
Bookmarks