Menu

#55 labels between ticks

open
nobody
None
5
2018-06-21
2014-09-22
No

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.

Discussion

  • Andreas Nicolai

    Andreas Nicolai - 2018-06-21

    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 either drawLabel(double leftTick, double rightTick) or drawLabel(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:

    1. regular handling, x-values determine tick position and label is drawn at the tick for the given value
    2. tick-based interval handling, ticks remain as they were but labels are drawn between ticks (basically at a "virtual" tick) with the value-at-the-interval-middle generated from the scale engine.
    3. bar-plot-interval-mode: here the ticks are calculated differently, so that ticks and major grid lines enclose a group of bars. Using the "interval" mode (option 2), this could be accomplished by modifying the scale engine to generate ticks that are shifted by half the interval width. Option 2 will then call drawLabel() at the center points of the intervals, which would correspond to the original tick position without shifting. Hence, this bar-plot-interval-mode simple needs option 2 to work and a custom shifted scale engine (which is only a few lines of code).

    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
  • Andreas Nicolai

    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 intervals

    Mind: Interval is always defined as the space between major ticks... otherwise we would have "MajorIntervalLabel" and "MinorIntervalLabel".... bad idea

     
  • Uwe Rathmann

    Uwe Rathmann - 2018-06-21

    Another option might be modify QwtScaleDiv, so that the positions for the ticks and those for the labels can be independent.

     

Anonymous
Anonymous

Add attachments
Cancel