1 Attachment(s)
Avoiding Truncated Labels
G'day All,
I've been experimenting with the Qwt histogram and cpuplot examples trying to produce a chart on a time axis. The labels on my x axis are rotated dates. The rightmost date was slightly truncated at its top-right extremity but I fixed that with a bit of code lifted from the cpuplot example. The left most label in my graph (see blue box below) is badly truncated. The time labels in the cpuplot example are not similarly truncated.
The plot layout code looks like:
Code:
plot.setMargin(5);
plot.
setCanvasBackground(QColor(Qt
::white));
plot.setTitle("Hours by Month");
plot.
setAxisTitle(QwtPlot::yLeft,
"Hours");
plot.
setAxisTitle(QwtPlot::xBottom,
"Date");
plot.
setAxisScaleDraw(QwtPlot::xBottom,
new TimeScaleDraw
(QDate::currentDate()));
plot.
setAxisLabelRotation(QwtPlot::xBottom,
-50.0);
plot.
setAxisLabelAlignment(QwtPlot::xBottom, Qt
::AlignLeft | Qt
::AlignBottom);
// From cpuplot example to stop rightmost label being truncated
scaleWidget->setMinBorderDist(0, fmh / 2);
a bunch of code building QwtScaleDiv tick data, then
Code:
plot.
setAxisScaleDiv(QwtPlot::xBottom, sd
);
followed by an essentially unmodified (colours aside) histogram example.
I thought it might be a z-order issue with the y-axis scale overwriting, but I couldn't find a way to change this. What do I need to tweak to sort this out?
Regards,
Chris
Qwt 5.2.0, Qt 4.5.1, Linux
Re: Avoiding Truncated Labels
In general the layout engine of QwtPlot should stretch the bottom scale below the left one, so that there is space enough for the tick labels of the bottom scale. And this is exactly what happens in the cpuplot example.
From your code snippet it is difficult to say, what's wrong in your application. Your screenshot might be from a situation, where the layout has not been recalculated (missing replot) after you have assigned your scale properties. ( You can manually resize the plot window to check this. )
If you compare your code with the cpuplot example - can you see any substantial differences ?
Uwe
1 Attachment(s)
Re: Avoiding Truncated Labels
G'day Uwe,
Thanks for your reply. Resizing the window does not alter the x scale: the truncated labels stay truncated. I cannot see any operative part of the cpuplot example that affects this; as you say, it seems to be the default behaviour.
I have attached the full source If you'd like to look (and forgive the blatant plagiarism ;) ).
Regards,
Chris
Edit: Had a bit more of a play with this. If I explicitly set
Code:
plot.
setAxisScale(QwtPlot::xBottom,
-100,
1);
in the code attached then the label is good. If, as in my broken example, you leave this out (auto scale) the label is truncated. I can probably live with this in the intended application.
Re: Avoiding Truncated Labels
The layout engine of QwtPlot assumes, that the first major tick is at the left and the last one is at the right side of the scale. But in your code its the other way round.
I will think about how to fix this bug in Qwt ( manually generated ticks need to be ordered, after they have been passed with setScaleDiv).
In the meantime you could simply turn the order of your ticks.
Uwe
Re: Avoiding Truncated Labels
Thanks Uwe. In rolling the code into a real application I had rewritten it the other way around anyway.
I would not bother handling the tick marks in reverse order, just document that they should be left-to-right or bottom-to-top.
Re: Avoiding Truncated Labels
Even better than documenting a bug is to fix it. ( Done in the 5.2 and trunk branches. )
Uwe