RE: Number of major ticks strategy
Brought to you by:
rathmann
|
From: Murphy, S. <sm...@wa...> - 2019-05-07 18:26:09
|
> > Growing the plot isn't really a problem, but when the user shrinks the
> > plot I think I need to reduce the number of major tick marks just to
> > keep them from getting to crammed in on each other.
>
> The major ticks by itself do not need more space than the other ticks - the fact,
> that you have tick labels for each major tick make the difference.
>
> So your problem is not necessarily about reducing the number of major ticks, it is
> about getting rid of tick labels.
I'll have to run this past the main users. My hunch is that they would actually prefer
to see less major ticks, but have them all labeled vs. seeing more ticks with only some of
them labeled. But it's a good point you raised, I hadn't really considered the idea of
just removing some of the labels.
>
> This could be done like this:
>
> class YourScaleDraw : public QwtScaleDraw {
> public:
> QwtText label( double value ) const override
> {
> const auto& map = scaleMap();
> const auto& sd = scaleDiv();
>
> const bool showLabel = ...
>
> return showLabel ? QwtScaleDraw::label( value ) : QwtText();
> }
> };
>
> With sd you can identify if value is for the ticks at the borders, with
> sd.pdist() you know about the available space in pixels.
>
> What is missing is the font, that is coming from the QwtScaleWidget. So you
> would need to write some code, so that it is available in YourScaleDraw::label().
>
> > I was just wondering if anyone has already come up with a strategy for
> > handling this (or if I'm just missing something in the API that
> > already does this)?
>
> No, the minimumSizeHint() depends on the height/width of the tick labels and if
> you go below that size there is no conflict resolution strategy implemented.
Ok, good to know that I'm not overlooking something obvious.
> > -I need to specify the min/max values of the scale AND see those exact
> > values on the top & bottom of the scale widget. So if for example, I
> > set the range from 17 to 43, the label for the bottommost tick mark
> > needs to say 17, and the label for the topmost needs to say 43.
> > Similarly if I set it from -20 to 100, I need to see -20 and
> > 100 at the two ends of the scale.
>
> The calculation of the boundaries/ticks is the job of the scale engine.
> QwtLinearScaleEngine has a couple of config options - like
> QwtScaleEngine::Floating.
>
> Of course you can also implement your own type of scale engine if
> QwtLinearScaleEngine does not offer what you need. As you don't want to align
> the boundaries all you need to do is to override YourScaleEngine::divideScale to
> calculate the ticks for a given interval.
>
> Finally you can always bypass using the scale engine by setting up the
> boundaries/ticks manually using QwtPlot::setAxisScaleDiv().
I'll play around with the different options you've outlined and see which works
best. Thanks for the pointers!
Sean
This message has been scanned for malware by Forcepoint. www.forcepoint.com
|