From 5790dce4ecd6f61eadcb478f1a08f90cfa7d5312 Mon Sep 17 00:00:00 2001 From: thundergnat Date: Fri, 15 Jul 2011 13:53:35 -0700 Subject: [PATCH 1/3] Added y-axis attribute to set the y axis at something other than the minimum if desired. --- lib/SVG/Plot.pm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/SVG/Plot.pm b/lib/SVG/Plot.pm index 867f6d9..30a1ee8 100644 --- a/lib/SVG/Plot.pm +++ b/lib/SVG/Plot.pm @@ -34,6 +34,8 @@ has $.label-spacing = ($.height - $.plot-height) / 20; has @.colors = <#3333ff #ffdd66 #aa2222 #228844 #eebb00 #8822bb>; +has $.y-axis = 0; + 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] $.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] $.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] $.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] $.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] $.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] $.y-axis, @.values.map: { [min] @($_) }; my $datasets = +@.values; my $step_x = $.plot-width / $max_x; From 80b888bd882cf844ce6e2835d4adfc4f263443d1 Mon Sep 17 00:00:00 2001 From: thundergnat Date: Sat, 16 Jul 2011 07:14:03 -0700 Subject: [PATCH 2/3] Change minimum y scaling attribute to $.min-y-axis as suggested. Added some usage notes to the POD. --- lib/SVG/Plot.pm | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/SVG/Plot.pm b/lib/SVG/Plot.pm index 30a1ee8..3fb1e2d 100644 --- a/lib/SVG/Plot.pm +++ b/lib/SVG/Plot.pm @@ -34,7 +34,7 @@ has $.label-spacing = ($.height - $.plot-height) / 20; has @.colors = <#3333ff #ffdd66 #aa2222 #228844 #eebb00 #8822bb>; -has $.y-axis = 0; +has $.min-y-axis = Inf; multi method plot(:$full = True, :$stacked-bars!) { @@ -89,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] $.y-axis, @.values.map: { [min] @($_) }) min 0; + my $min_y = ([min] $.min-y-axis, @.values.map: { [min] @($_) }) min 0; my $datasets = +@.values; @@ -134,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] $.y-axis, @.values.map: { [min] @($_) }; + my $min_y = [min] $.min-y-axis, @.values.map: { [min] @($_) }; my $datasets = +@.values; my $step_x = $.plot-width / $max_x; @@ -172,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] $.y-axis, @lower.map: { [min] @($_) }; + my $min_y = [min] $.min-y-axis, @lower.map: { [min] @($_) }; my $datasets = +@.values; my $step_x = $.plot-width / $max_x; @@ -236,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] $.y-axis, @.values.map: { [min] @($_) }; + my $min_y = [min] $.min-y-axis, @.values.map: { [min] @($_) }; my $datasets = +@.values; @@ -282,7 +282,7 @@ multi method plot(:$full = True, :$xy-lines!) { } my $max_y = [max] @.values.map: { [max] @($_) }; - my $min_y = [min] $.y-axis, @.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"; @@ -331,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] $.y-axis, @.values.map: { [min] @($_) }; + my $min_y = [min] $.min-y-axis, @.values.map: { [min] @($_) }; my $datasets = +@.values; my $step_x = $.plot-width / $max_x; @@ -688,6 +688,11 @@ dependent on C<$.plot-width> and C<$.label-font-size>. Distance between I axis and labels. Also affects width of I ticks and distance of labels and I ticks. +=head2 $.min-y-axis + +By default the C axis is scaled between the minimum and maximum y values. +Set this if you want the C axis to scale off of a different lower bound. + =head1 LICENSE AND COPYRIGHT Copyright (C) 2009 by Moritz Lenz and the SVG::Plot contributors (see file @@ -713,4 +718,4 @@ law. =end Pod -# vim: ft=perl6 +# vim: ft=perl6 \ No newline at end of file From 3d3e111bad2af72c44674c3492cb02d2ec9c35ca Mon Sep 17 00:00:00 2001 From: thundergnat Date: Sat, 16 Jul 2011 07:18:16 -0700 Subject: [PATCH 3/3] Added some further documentation. --- lib/SVG/Plot.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/SVG/Plot.pm b/lib/SVG/Plot.pm index 3fb1e2d..eada241 100644 --- a/lib/SVG/Plot.pm +++ b/lib/SVG/Plot.pm @@ -692,6 +692,8 @@ distance of labels and I ticks. By default the C axis is scaled between the minimum and maximum y values. Set this if you want the C 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 +value. =head1 LICENSE AND COPYRIGHT