From: Tony Cook Date: Sat, 5 May 2012 04:23:39 +0000 (+1000) Subject: [rt #59532] allow negative_bg to be a fill for vertical charts X-Git-Tag: v0.10~12 X-Git-Url: http://git.imager.perl.org/imager-graph.git/commitdiff_plain/90f723b57c531249f0934c9e1bb80bc69f663ebb [rt #59532] allow negative_bg to be a fill for vertical charts --- diff --git a/lib/Imager/Graph/Vertical.pm b/lib/Imager/Graph/Vertical.pm index 4a92f58..2fbb8e8 100644 --- a/lib/Imager/Graph/Vertical.pm +++ b/lib/Imager/Graph/Vertical.pm @@ -281,13 +281,12 @@ sub draw { } if ($min_value < 0) { + my @neg_box = ( $left + 1, $zero_position, $left+$graph_width- 1, $top+$graph_height - 1 ); + my @neg_fill = $self->_get_fill('negative_bg', \@neg_box) + or return; $img->box( - color => $self->_get_color('negative_bg'), - xmin => $left + 1, - xmax => $left+$graph_width- 1, - ymin => $zero_position, - ymax => $top+$graph_height - 1, - filled => 1, + @neg_fill, + box => \@neg_box, ); $img->line( x1 => $left+1, diff --git a/t/t12column.t b/t/t12column.t index a9dbc4c..60cd763 100644 --- a/t/t12column.t +++ b/t/t12column.t @@ -13,7 +13,7 @@ use Test::More; use Imager qw(:handy); -plan tests => 5; +plan tests => 7; my @warned; local $SIG{__WARN__} = @@ -58,6 +58,37 @@ my @labels = qw(alpha beta gamma delta epsilon phi gi); $img1->write(file=>'testout/t12_column2.ppm') or die "Can't save img1: ".$img1->errstr."\n"; } +{ + my $column = Imager::Graph::Column->new(); + ok($column, "creating column chart object"); + + $column->add_data_series(\@data); + $column->add_data_series([ -50, -30, 20, 10, -10, 25, 10 ]); + $column->set_labels(\@labels); + + my $fountain = Imager::Fountain->simple(colors => [ "#C0C0FF", "#E0E0FF" ], + positions => [ 0, 1 ]); + + my %fill = + ( + fountain => "linear", + segments => $fountain, + xa_ratio => -0.1, + ya_ratio => 0.5, + xb_ratio => 1.1, + yb_ratio => 0.55, + ); + + my $img1 = $column->draw + ( + features => "outline", + negative_bg => \%fill, + ); + ok($img1, "drawing column chart - negative_bg is a fill"); + + $img1->write(file=>'testout/t12_column3.ppm') or die "Can't save img1: ".$img1->errstr."\n"; +} + unless (is(@warned, 0, "should be no warnings")) { diag($_) for @warned; }