Skip to content

Commit

Permalink
Merge pull request #1 from thundergnat/master
Browse files Browse the repository at this point in the history
Added a y-axis attribute to set the y axis at something other than the minimum if desired
  • Loading branch information
moritz committed Dec 26, 2014
2 parents d8bdbdf + 3d3e111 commit 2e7ab96
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/SVG/Plot.pm
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -711,4 +720,4 @@ law.
=end Pod

# vim: ft=perl6
# vim: ft=perl6

0 comments on commit 2e7ab96

Please sign in to comment.