PDA

View Full Version : QwtPlotPanner makes plot look jumpy due to tick labels.



amoswood
4th June 2010, 22:13
Problem

I have implemented the QwtPlotPanner for my plots to pan the plots around. However when I move the canvas using the panner with the axis tick labels turned on, it makes the plot look jumpy because of how the tick labels are drawn.

From what I have noticed when the tick label is large, it is centered under the tick mark. This centering cause the plot canvas to shrink so that the plot canvas physically becomes smaller and gap between the canvas and the right side is gapped (see the gapped_plot.png attachment below).

4733

Then when you pan the plot, the gap will go away as the axis tick label moves to the left or the right (see the nongapped_plot.png attachment below).

4734

Panning the plot quickly makes it look like the plot is jumpy and will give you a headache after awhile.

Behind The Scenes
I am adjusting the plot to try and have the canvas and the scales line up. Maybe this is my problem?

QwtPlot::plotLayout()->setMargin(2);
QwtPlot::plotLayout()->setAlignCanvasToScales(true);

Help Me!

My goal is to get the canvas to stay the same size always. That means that when the tick axis label is centered under the tick mark and the label would be clipped by the edge of the plot that I don't want it to show.

Has anyone else ran into this issue and can help me?

Uwe
5th June 2010, 09:46
My goal is to get the canvas to stay the same size always.
Then don't tell the layout engine explicitly to align the canvas to the scales.

Uwe

PS: You could set a minimumExtent to your left scale ( like in the event_filter example ) to avoid that the canvas is resized, when the number of digits for the tick labels changes.

amoswood
8th June 2010, 17:09
Then don't tell the layout engine explicitly to align the canvas to the scales.
I tried this which helps a little bit. However, the canvas doesn't move now but the scales will jump in size when there are long tick labels.

After looking into it more, I think that I found the issue but I am unable to figure out how to figure it.

Findings and Example Scenario:

I have a plot which has a xBottom scale of 0 to 10000. When using even normal sized font of 10pt, the right side tick label of "10,000" uses about 50-60 pixels to display. When that label is centered under the tick mark, the right portion uses 25-30 pixels of space. Now when the QwtScaleWidget::getBorderDistHint() function gets called, it calls the QwtScaleDraw::getBorderDistHint() function and it returns the "end" parameter to be 25-30 pixels to accomodate the "10,000" tick label.

4747
Figure 1: 0 to 10000 Plot

Now because of the long tick label and the fact that the canvas and scale widget are not aligned (see QwtPlotLayout::setAlignCanvasToScale() function), the scale goes from 0 to 10000 while the canvas displays values from about -10 to 10700. The difference is because the tick label causes the tick mark to adjust so that the label can be displayed.

So where the "jumpy" looks comes in happens when you change the scale of the xBottom scale to be -1 to 9999. When this happens, the "10,000" tick label doesn't need to show anymore and the QwtScaleDraw::getBorderDistHint() function returns 0 for the "end" parameter. Effectively, the scale widget goes from -1 to 9999 and the canvas aligns naturally and goes from -1 to 9999. Thus, the sudden change in scale ranges for the canvas and scale widget cause it look jumpy when panning.

4748
Figure 2: -1 to 9999 Plot

Solutions:

I would think that sub-classing from the QwtScaleDraw class to overload the getBorderDistHint() function would be the way to handle this by always passing back a 0 for the "end" parameter. However, this function is not virtual for some reason.
Sub-class from the QwtScaleWidget class to hold a custom QwtScaleDraw class and work around the issue that way. I see that the QwtScaleWidget class has virtual members which makes me think that I can sub-class from it. However, I don't see a way to create or set the scale widgets in the QwtPlot class.
??? - Now I am stuck???

Any help or ideas on how to work around this?

Uwe
10th June 2010, 05:15
Youal ready got the answer im my previous mail.

Uwe

amoswood
10th June 2010, 13:31
Youal ready got the answer im my previous mail.
The only thing that the previous mail answered is that to use minimumExtent. I don't understand how to make that work.

The difference is that I don't know if the tick label is going to be 5 pixels long or 50 pixels long and I don't want to set the minimumExtent to be 50 pixels all of the time. It seems like having the ability to make one of the methods above have a virtual function is the way to go.

Since you, Uwe, designed and wrote it, why didn't you make some of the functions virtual like the QwtScaleDraw::getBorderDistHint() function?