Bug#359943: libchart-perl: integer_ticks_only doesn't honor
max_y_ticks
Niko Tyni
ntyni at iki.fi
Sun Apr 2 20:23:35 UTC 2006
forwarded 359943 http://rt.cpan.org/Public/Bug/Display.html?id=18502
tags 359943 patch
thanks
On Sun, Mar 26, 2006 at 08:40:06PM +0200, Bill Allombert wrote:
> You get 200 Y ticks (which are unreadable) disregarding the max_y_ticks of
> 6. If you remove integer_ticks_only, you get just 3 ticks.
Hi,
the attached patch should fix this. I have forwarded it upstream as well,
as CPAN #18502 ,<http://rt.cpan.org/Public/Bug/Display.html?id=18502>.
In the case of max_y_ticks, if the result would go over that, the tick
interval is increased. This will override 'skip_int_ticks', if needed.
In the case of min_y_ticks, if the result is below that, first the tick
interval is decreased (overriding 'skip_int_ticks', if needed). If that
doesn't help, the range of the scale is increased by either increasing
the maximum value or decreasing the minimum value. If both are fixed,
there's nothing to be done.
I'm going to wait a while to see what upstream thinks about this
before including the patch in the Debian packaging. Please try the patch
and tell me if it works for you.
Cheers,
--
Niko Tyni ntyni at iki.fi
-------------- next part --------------
--- libchart-perl-2.4.1-3/Chart/Base.pm 2006-04-02 22:19:29.000000000 +0300
+++ libchart-perl-2.4.1-4/Chart/Base.pm 2006-04-02 22:06:17.974305320 +0300
@@ -1911,6 +1911,42 @@
$tickInterval = $skip;
$tickCount = ($p_max - $p_min ) / $skip + 1;
+ # Honor max_y_ticks, even if that means overriding skip_int_ticks.
+ if ($tickCount > $self->{'max_y_ticks'}) {
+ $tickInterval = ($p_max - $p_min) / ($self->{'max_y_ticks'} - 1);
+ $tickInterval = 1 + int($tickInterval)
+ if $tickInterval != int($tickInterval);
+ $tickCount = int(($p_max - $p_min ) / $tickInterval + 1);
+ }
+
+ # Honor min_y_ticks if we can, first by reducing tick interval
+ # (even if that means overriding skip_int_ticks)
+ # and then by increasing the range if allowed.
+ if ($tickCount < $self->{'min_y_ticks'}) {
+ $tickInterval = ($p_max - $p_min) / ($self->{'min_y_ticks'} - 1);
+ $tickInterval = 1 + int($tickInterval)
+ if $tickInterval != int($tickInterval);
+ $tickCount = int(($p_max - $p_min ) / $tickInterval + 1);
+
+ if ($tickCount < $self->{'min_y_ticks'} &&
+ (!$f_max || !$f_min)) {
+ # Reducing interval didn't work, we have to increase the range.
+ # Just don't do it if both min_val and max_val were specified.
+
+ my $minRange = $tickInterval * ($self->{'min_y_ticks'} - 1);
+ if (!$f_max) {
+ $d_max = $d_min + $minRange;
+ $p_max = $self->_round2Tick($d_max, 1, 1);
+ } elsif (!$f_min) {
+ $d_min = $d_max - $minRange;
+ $p_min = $self->_round2Tick($d_min, 1, -1);
+ }
+ $tickInterval = ($p_max - $p_min) / ($self->{'min_y_ticks'} - 1);
+ $tickInterval = 1 + int($tickInterval)
+ if $tickInterval != int($tickInterval);
+ $tickCount = int(($p_max - $p_min ) / $tickInterval + 1);
+ }
+ }
# Now sort out an array of tick labels.
More information about the pkg-perl-maintainers
mailing list