Skip to content

Loading…

Added a y-axis attribute to set the y axis at something other than the minimum if desired #1

Merged
merged 3 commits into from

2 participants

@thundergnat

Defaults to 0. Set to +Inf (or some other suitably large value) to get previous behaviour. For a use case see: http://rosettacode.org/wiki/Plot_coordinate_pairs#Perl_6
May or may not be something you want, but I find it useful.
Cheers.

@moritz
Owner

I like the idea of this patch, but neither the name nor the default.

'$.y-axis' only tells us that the y axis is affected, but not how. Maybe '$.min-y-axis'?

Since many plots don't include the 0 in y axis, Inf should be the default.

@moritz moritz merged commit 2e7ab96 into moritz:master
@moritz
Owner

Thanks, and sorry that it took so long, I simply forgot to look at the issue tracker :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 15, 2011
  1. @thundergnat
Commits on Jul 16, 2011
  1. @thundergnat

    Change minimum y scaling attribute to $.min-y-axis as suggested. Adde…

    thundergnat committed
    …d some usage notes to the POD.
  2. @thundergnat
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 7 deletions.
  1. +16 −7 lib/SVG/Plot.pm
View
23 lib/SVG/Plot.pm
@@ -34,6 +34,8 @@ has $.label-spacing = ($.height - $.plot-height) / 20;
has @.colors = <#3333ff #ffdd66 #aa2222 #228844 #eebb00 #8822bb>;
+has $.min-y-axis = Inf;
+
multi method plot(:$full = True, :$stacked-bars!) {
my $label-skip = ceiling(@.values[0] / $.max-x-labels);
@@ -87,7 +89,7 @@ multi method plot(:$full = True, :$bars!) {
# the minimum is only interesting if it's smaller than 0.
# if all the values are non-negative, the bars should still start
# at 0
- my $min_y = ([min] @.values.map: { [min] @($_) }) min 0;
+ my $min_y = ([min] $.min-y-axis, @.values.map: { [min] @($_) }) min 0;
my $datasets = +@.values;
@@ -132,7 +134,7 @@ multi method plot(:$full = True, :$points!) {
my $label-skip = ceiling(@.values[0] / $.max-x-labels);
my $max_x = @.values[0].elems;
my $max_y = [max] @.values.map: { [max] @($_) };
- my $min_y = [min] @.values.map: { [min] @($_) };
+ my $min_y = [min] $.min-y-axis, @.values.map: { [min] @($_) };
my $datasets = +@.values;
my $step_x = $.plot-width / $max_x;
@@ -170,7 +172,7 @@ multi method plot(:$full = True, :$points-with-errors!,
my $label-skip = ceiling(@.values[0] / $.max-x-labels);
my $max_x = @.values[0].elems;
my $max_y = [max] @upper.map: { [max] @($_) };
- my $min_y = [min] @lower.map: { [min] @($_) };
+ my $min_y = [min] $.min-y-axis, @lower.map: { [min] @($_) };
my $datasets = +@.values;
my $step_x = $.plot-width / $max_x;
@@ -234,7 +236,7 @@ multi method plot(:$full = True, :$xy-points!) {
my $min_x = [min] @.x;
my $max_y = [max] @.values.map: { [max] @($_) };
- my $min_y = [min] @.values.map: { [min] @($_) };
+ my $min_y = [min] $.min-y-axis, @.values.map: { [min] @($_) };
my $datasets = +@.values;
@@ -280,7 +282,7 @@ multi method plot(:$full = True, :$xy-lines!) {
}
my $max_y = [max] @.values.map: { [max] @($_) };
- my $min_y = [min] @.values.map: { [min] @($_) };
+ my $min_y = [min] $.min-y-axis, @.values.map: { [min] @($_) };
if $max_y == $min_y {
die "There's just one y value ($max_x), refusing to plot\n";
@@ -329,7 +331,7 @@ multi method plot(:$full = True, :$lines!) {
my $label-skip = ceiling(@.values[0] / $.max-x-labels);
my $max_x = @.values[0].elems;
my $max_y = [max] @.values.map: { [max] @($_) };
- my $min_y = [min] @.values.map: { [min] @($_) };
+ my $min_y = [min] $.min-y-axis, @.values.map: { [min] @($_) };
my $datasets = +@.values;
my $step_x = $.plot-width / $max_x;
@@ -686,6 +688,13 @@ dependent on C<$.plot-width> and C<$.label-font-size>.
Distance between I<x> axis and labels. Also affects width of I<y> ticks and
distance of labels and I<y> ticks.
+=head2 $.min-y-axis
+
+By default the C<y> axis is scaled between the minimum and maximum y values.
+Set this if you want the C<y> axis to scale off of a different lower bound.
+Only has an effect if the C<$.min-y-axis> value is less then the minimum C<y>
+value.
+
=head1 LICENSE AND COPYRIGHT
Copyright (C) 2009 by Moritz Lenz and the SVG::Plot contributors (see file
@@ -711,4 +720,4 @@ law.
=end Pod
-# vim: ft=perl6
+# vim: ft=perl6
Something went wrong with that request. Please try again.