PDA

View Full Version : Rolling Y Axis needed



baray98
2nd October 2012, 07:54
Hi all,

I want to make a Yleft axis have a rolling effect . Example :

3 -|
2 -|
1 -|
0 -|

now as you pan going up it will look,

2 -|
1 -|
0 -|
3 -|

if you pan some more ....

1 -|
0 -|
3 -|
2 -|

it will always keep the interval's width to be 4 in this case.

How can I implement this? any help would be appreciated.

-baray98-

wysota
2nd October 2012, 09:07
A minimal approach is to implement a custom QwtScaleDraw and reimplement its label() method. Note that it will only change what is displayed on the axis, internally the values will still be taken from the original domain (e.g. double).

baray98
2nd October 2012, 19:00
thanks for the suggestion .. but i am aiming for a domain change as well meaning if my data contain a point (1,1) and my Y is showing
0 -|
3 -|
2 -|
1 -|
0 -|
3 -|
2 -|
1 -|

I am explecting to see two points drawn.

wysota
2nd October 2012, 19:04
I'm afraid for that you need to implement a QwtScaleEngine subclass that will recalculate your scale and reimplement QwtPlotCurve::drawCurve() which is a bit of work.

Uwe
2nd October 2012, 20:08
Sounds like one of the QwtPlot::drawXY methods needs to be overloaded, where the overloaded draw method is called several times ( for each domain ) with different canvas maps. The maps can be build by translating the original map by the domain height.

This height can be calculated from the original canvas map:


qAbs( yMap.transform( 4 ) - yMap.transform( 0 ) ).
When you need to display values outside the area [0-3] you need to add some clipping code.

But when you don't have many points it might be easier to implement your own type of plot item - but we don't have enough information to recommend how to proceed.

Uwe

baray98
2nd October 2012, 20:33
this sounds like a lot of work to me. I will consider sticking to the linear scale engine and have a translator in between my data and the yScale so my data knows what is shown and translate y values. for the label, i will do what wysota suggested on scale widget.

thanks for the help guys

baray98

P.S.

Is there any signal from scale widget when it changes it range and content?

Uwe
3rd October 2012, 09:00
Is there any signal from scale widget when it changes it range and content?

QwtScaleWidget::scaleDivChanged() - but other options are overloading QwtPlotCurve::updateScaleDiv() or QwtSeriesData::setRectOfInterest(). Depends on where your translator sits.

Maybe it is possible to do the translation and duplication in a class derived from QwtSeriesData.

Uwe