]> git.imager.perl.org - imager-graph.git/commitdiff
[rt #59532] allow negative_bg to be a fill for vertical charts
authorTony Cook <tony@develop-help.com>
Sat, 5 May 2012 04:23:39 +0000 (14:23 +1000)
committerTony Cook <tony@develop-help.com>
Sat, 5 May 2012 04:23:39 +0000 (14:23 +1000)
lib/Imager/Graph/Vertical.pm
t/t12column.t

index 4a92f583ac4a0c1aa76fbfb1afb12983faf0723b..2fbb8e800b7f2d91e9f57ba55f039219744208a5 100644 (file)
@@ -281,13 +281,12 @@ sub draw {
   }
 
   if ($min_value < 0) {
   }
 
   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(
     $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,
     );
     $img->line(
             x1 => $left+1,
index a9dbc4ca4daaa619dc35d383a5495050524ab968..60cd763b762e6dd85b13eff318e8e4b93a9beb8b 100644 (file)
@@ -13,7 +13,7 @@ use Test::More;
 
 use Imager qw(:handy);
 
 
 use Imager qw(:handy);
 
-plan tests => 5;
+plan tests => 7;
 
 my @warned;
 local $SIG{__WARN__} =
 
 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";
 }
 
   $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;
 }
 unless (is(@warned, 0, "should be no warnings")) {
   diag($_) for @warned;
 }