Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
Dec 26, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions lib/SVG/Plot.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ has $.label-spacing = ($.height - $.plot-height) / 20;


has @.colors = <#3333ff #ffdd66 #aa2222 #228844 #eebb00 #8822bb>; has @.colors = <#3333ff #ffdd66 #aa2222 #228844 #eebb00 #8822bb>;


has $.min-y-axis = Inf;

multi method plot(:$full = True, :$stacked-bars!) { multi method plot(:$full = True, :$stacked-bars!) {


my $label-skip = ceiling(@.values[0] / $.max-x-labels); 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. # the minimum is only interesting if it's smaller than 0.
# if all the values are non-negative, the bars should still start # if all the values are non-negative, the bars should still start
# at 0 # 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; 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 $label-skip = ceiling(@.values[0] / $.max-x-labels);
my $max_x = @.values[0].elems; my $max_x = @.values[0].elems;
my $max_y = [max] @.values.map: { [max] @($_) }; 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 $datasets = +@.values;


my $step_x = $.plot-width / $max_x; 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 $label-skip = ceiling(@.values[0] / $.max-x-labels);
my $max_x = @.values[0].elems; my $max_x = @.values[0].elems;
my $max_y = [max] @upper.map: { [max] @($_) }; 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 $datasets = +@.values;


my $step_x = $.plot-width / $max_x; 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 $min_x = [min] @.x;


my $max_y = [max] @.values.map: { [max] @($_) }; 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 $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 $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 { if $max_y == $min_y {
die "There's just one y value ($max_x), refusing to plot\n"; 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 $label-skip = ceiling(@.values[0] / $.max-x-labels);
my $max_x = @.values[0].elems; my $max_x = @.values[0].elems;
my $max_y = [max] @.values.map: { [max] @($_) }; 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 $datasets = +@.values;


my $step_x = $.plot-width / $max_x; 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 between I<x> axis and labels. Also affects width of I<y> ticks and
distance of labels and I<y> ticks. 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 =head1 LICENSE AND COPYRIGHT


Copyright (C) 2009 by Moritz Lenz and the SVG::Plot contributors (see file Copyright (C) 2009 by Moritz Lenz and the SVG::Plot contributors (see file
Expand All @@ -711,4 +720,4 @@ law.


=end Pod =end Pod


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