Recent

Author Topic: TAChart: minor ticks, minor grid, logarithmic scaling  (Read 23516 times)

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: TAChart: minor ticks, minor grid, logarithmic scaling
« Reply #15 on: August 10, 2011, 01:07:39 am »
Quote
It was due to a different bug. Should be fixed in r31911
Yes, it's working now.

Quote
try to find a good set of 5 logarithmic steps between values 200 and 300
I'd say: the range is less than 2 decades so let's use the non-logarithmic algorithm, i.e. calculate the marks as it were a linear scale. If the range is larger use the logarithmic method, i.e. use the log values to calculate the mark positions as if it were a linear scale also, but use the logs. For example: axis range from 1 to 1000, the logs are 1 and 3 respectively. --> marks at 1, 2, 3 --> revert the log --> marks at 1, 100, 1000. The mark finding algorithm will try to place marks also at intermediate values, e.g. 1.5 and 2.5, but the algorithm should have a clear option to force only integer marks, i.e. full decade marks, since this is the normal situation with logarithmic diagrams.
We're talking about the default behavior here, so if the user wants marks at different positions he can still use his own ChartSource for the axis as I had noted in a previous posting.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: TAChart: minor ticks, minor grid, logarithmic scaling
« Reply #16 on: August 20, 2011, 09:33:44 pm »
Maybe, I am doing things wrong, and maybe I am misunderstanding the concept, but it is difficult to get reasonable intervals with the new method when changing the default settings.

In my opinion, if the aipUseNiceSteps is set, the system should always try to find "nice steps" with highest priority. However, when I increase the MinLength value (with aipUseMinLength and aipUseMaxLength set) the axis shows crooked labels; I do this to avoid overlapping labels in case of large zoom factors. I would expect that MinLength is the minimum pixel distance between marks or minors; if "nice" labels get too close the interval should switch to the next "nice" interval such that it is greater than the MinLength interval. But this does not occur.

To reproduce: place a chart on a form, Align = alClient. Change the extent of the xaxis to range from 990 to 1000. Resize the form horizontally, the labels adapt nicely with the default settings. Now change the xaxis intervals' MinLength to 30 (from 20). During resizing the form, the labels will occasionally show crooked values.


Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TAChart: minor ticks, minor grid, logarithmic scaling
« Reply #17 on: August 21, 2011, 03:42:44 am »
I recommend increasing MaxLength to 100.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: TAChart: minor ticks, minor grid, logarithmic scaling
« Reply #18 on: August 21, 2011, 11:16:43 am »
I see - this is much better. But how can it be that crooked labels are found at all if the NiceLabels option is set?

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TAChart: minor ticks, minor grid, logarithmic scaling
« Reply #19 on: August 21, 2011, 11:44:43 am »
See http://wiki.lazarus.freepascal.org/TAChart_documentation#Axis_intervals

Basically, TChart tries to find a step satisfying all three criteria:
MinLength, MaxLength and NiceSteps. If it fails, it ignores NiceSteps and
simply uses MaxLength (converted to axis coordinates).

Specifying too strict criteria increases the chances of failure.
It is quite possible that default values should be changed
(for example, to MinLength=20 and MaxLength=100) --
I welcome your opinion on this.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: TAChart: minor ticks, minor grid, logarithmic scaling
« Reply #20 on: August 21, 2011, 12:02:23 pm »
Quote
If it fails, it ignores NiceSteps and simply uses MaxLength
I did not look into your implementation, but how can the algorithm fail, at least on a linear axis? When the axis range goes from 0 to 100, ticks should be at 0, 10, 20 etc (or 0, 20,..., or 0, 50, 100, depending on the chart size). When the axis range goes from 99 to 100 the ticks should be at 99.0, 99.1, etc (or (99.0, 99.2, ..., or 99.0, 99.5, 100.0, depending on chart size) - I don't see a reason why this should not be possible.

Quote
MinLength=20 and MaxLength=100
That would be fine. On a log axis, however, this is still not a good solution; as I wrote in another thread, the marks should be at full powers of the base (usually 10), no intermediate ticks except if the axis range is too small.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TAChart: minor ticks, minor grid, logarithmic scaling
« Reply #21 on: August 21, 2011, 12:53:04 pm »
Quote
how can the algorithm fail, at least on a linear axis?

Roughly speaking, it takes candidate step values, e.g. 1.0, 0.5, 0.2, 0.1, 0.05, 0.02, ...
and for each step calculates interval length in pixels.
If that interval is between MinLength and MaxLength, the candidate is accepted,
otherwise rejected.
Usually, first candidates are rejected because a step is too long, and last ones
because a step is too short.
If MinLength and MaxLength are too close, it is quite possible that there is not a single acceptable candidate -- for example, suppose scaling factor = 100.
Then step=1.0 gives an interval of 100 pixels,
step=0.5 gives an interval of 50 pixels, step of 0.2 gives an interval of 20 pixels, etc.
If you set MinLength=30 and MaxLength=40, then all steps will be rejected.

 

TinyPortal © 2005-2018