allow the outline and background of the graph data area to be
authorTony Cook <tony@develop-help.com>
Mon, 5 Jul 2010 10:58:21 +0000 (10:58 +0000)
committerTony Cook <tony@develop-help.com>
Mon, 5 Jul 2010 10:58:21 +0000 (10:58 +0000)
independently controlled

fix a variable name

Graph.pm
lib/Imager/Graph/Vertical.pm

index e74c006..a6692a5 100644 (file)
--- a/Graph.pm
+++ b/Graph.pm
@@ -1217,10 +1217,18 @@ my %style_defs =
                               coef=>[0.1, 0.2, 0.4, 0.6, 0.7, 0.9, 1.2, 
                                      0.9, 0.7, 0.6, 0.4, 0.2, 0.1 ] },
                  },
+   # controls the outline of graph elements representing data, eg. pie
+   # slices, bars or columns
    outline => {
                line =>'lookup(line)',
               lineaa => 'lookup(lineaa)',
               },
+   # controls the outline and background of the data area of the chart
+   graph =>
+   {
+    fill => "lookup(bg)",
+    outline => "lookup(fg)",
+   },
    size=>256,
    width=>'scale(1.5,size)',
    height=>'lookup(size)',
@@ -1559,14 +1567,20 @@ sub _style_setup {
   }
 
   # features are handled specially
-  $work{features} = {};
+  my %features;
+  $work{features} = \%features;
   for my $src (@search_list) {
     if ($src->{features}) {
       if (ref $src->{features}) {
         if (ref($src->{features}) =~ /ARRAY/) {
           # just set those features
           for my $feature (@{$src->{features}}) {
-            $work{features}{$feature} = 1;
+           if ($feature =~ /^no(.+)$/) {
+             delete $features{$1};
+           }
+           else {
+             $features{$feature} = 1;
+           }
           }
         }
         elsif (ref($src->{features}) =~ /HASH/) {
@@ -1583,8 +1597,6 @@ sub _style_setup {
       }
     }
   }
-  #use Data::Dumper;
-  #print Dumper(\%work);
 
   $self->{_style} = \%work;
 }
index 47038f3..8a2e38b 100644 (file)
@@ -202,30 +202,33 @@ sub draw {
   my $tic_distance = ($graph_height-1) / ($tic_count - 1);
   $graph_height = int($tic_distance * ($tic_count - 1));
 
-  my $bottom = $chart_box[1];
-  my $left   = $chart_box[0];
+  my $top  = $chart_box[1];
+  my $left = $chart_box[0];
 
   $self->{'_style'}{'graph_width'} = $graph_width;
   $self->{'_style'}{'graph_height'} = $graph_height;
 
-  my @graph_box = ($left, $bottom, $left + $graph_width, $bottom + $graph_height);
+  my @graph_box = ($left, $top, $left + $graph_width, $top + $graph_height);
   $self->_set_graph_box(\@graph_box);
 
-  $img->box(
-            color   => $self->_get_color('outline.line'),
-            xmin    => $left,
-            xmax    => $left+$graph_width,
-            ymin    => $bottom,
-            ymax    => $bottom+$graph_height,
-            );
+  my @fill_box = ( $left, $top, $left+$graph_width, $top+$graph_height );
+  if ($self->{_style}{features}{graph_outline}) {
+    $img->box(
+             color   => $self->_get_color('graph.outline'),
+             xmin    => $left,
+             xmax    => $left+$graph_width,
+             ymin    => $top,
+             ymax    => $top+$graph_height,
+            );
+    ++$fill_box[0];
+    ++$fill_box[1];
+    --$fill_box[2];
+    --$fill_box[3];
+  }
 
   $img->box(
-            color   => $self->_get_color('bg'),
-            xmin    => $left + 1,
-            xmax    => $left+$graph_width - 1,
-            ymin    => $bottom + 1,
-            ymax    => $bottom+$graph_height-1 ,
-            filled  => 1,
+            $self->_get_fill('graph.fill'),
+           box => \@fill_box,
             );
 
   my $min_value = $self->_get_min_value();
@@ -234,7 +237,7 @@ sub draw {
 
   my $zero_position;
   if ($value_range) {
-    $zero_position =  $bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height-1);
+    $zero_position =  $top + $graph_height - (-1*$min_value / $value_range) * ($graph_height-1);
   }
 
   if ($min_value < 0) {
@@ -243,7 +246,7 @@ sub draw {
             xmin    => $left + 1,
             xmax    => $left+$graph_width- 1,
             ymin    => $zero_position,
-            ymax    => $bottom+$graph_height - 1,
+            ymax    => $top+$graph_height - 1,
             filled  => 1,
     );
     $img->line(
@@ -1282,8 +1285,14 @@ sub _style_defs {
     {
      opacity => 0.5,
     };
+  push @{$work{features}}, qw/graph_outline graph_fill/;
 
   return \%work;
 }
 
+sub _composite {
+  my ($self) = @_;
+  return ( $self->SUPER::_composite(), "graph" );
+}
+
 1;