labels between ticks
Brought to you by:
rathmann
Labels for axes scales are always for the major tick labels. But sometimes it would be better to have labels for intervals between 2 ticks.
F.e. instead of having tick labels at "1.1.2007" and "31.12.2007" it would be better to display 2007 between them.
Anonymous
A few conceptional ideas about this feature:
Regular X/Y curve plots
Suppose you can specify whether to draw labels at or in between ticks (i.e. "interval" mode).
Instead of
drawLabel(double)
you would now have eitherdrawLabel(double leftTick, double rightTick)
ordrawLabel(QwtInterval &)
While this API would work for users who subclass QwtAbstractScaleDraw and re-implement
drawLabel(QwtInterval &)
, there is no good default implementation, especially when considering non-linear scale engines.What value/text should be printed in "interval" mode for a logarithmic scale or root scale...?
This could be resolved by using a "virtual" tick, meaning the scale engine can be requested to provide the value for a tick in the middle between two labels and then the original
drawLabel(double)
function could be called, but just with a number that corresponds to the middle of the intervals. This would be a meaningful default implementation and still leave the opportunity for derived classes drawing any arbitrary value at the position (they may need to query the scale engine for the neighboring tick locations, if needed). In the case of datetime interval drawing, the neighboring ticks would not even be needed.Bar plots
In case of BarPlots, however, there is a specific way on how to interpret an "interval" mode.
Since the bars are drawn centered around the tick, an "interval" mode would mean that the ticks (and grid lines) are shifted so that grid lines enclose a bar group, an the label is drawn in between the ticks.
These are different application cases which may need to be distinguished as follows:
Suggestion for implementation
Within QwtAbstractScaleDraw::draw(), in the section where labels are drawn, implement a section for "TickLabel" and for "IntervalLabel" code. In case of IntervalLabel, ask the scale engine to provide a value for the middle of the interval. Then call drawLabel() as before with the double value.
Last edit: Andreas Nicolai 2018-06-21
Note:
QwtAbstractScaleDraw
does not have access to the scale engine and probably doesn't need access.Solution proposal: add "
QwtScaleDiv::IntervalTick
" and let scale engines generate the double numbers for the intervalsMind: Interval is always defined as the space between major ticks... otherwise we would have "MajorIntervalLabel" and "MinorIntervalLabel".... bad idea
Another option might be modify QwtScaleDiv, so that the positions for the ticks and those for the labels can be independent.