]> git.imager.perl.org - imager-graph.git/commitdiff
feature control over drawing line and area line markers
authorTony Cook <tony@develop-help.com>
Mon, 2 Aug 2010 09:50:04 +0000 (09:50 +0000)
committerTony Cook <tony@develop-help.com>
Mon, 2 Aug 2010 09:50:04 +0000 (09:50 +0000)
Changes
Graph.pm
lib/Imager/Graph/Horizontal.pm
lib/Imager/Graph/Vertical.pm
t/t12column.t
t/t13stacked_col.t

diff --git a/Changes b/Changes
index b30ab55ee69dd054431383dd3ecce32a26c79554..e6a2dad878f568b4e263f82bf306be1c5c930174 100644 (file)
--- a/Changes
+++ b/Changes
@@ -32,7 +32,6 @@ Other changes:
  - for vertical and horizontal charts, allow the fill of the graph
    area to be controlled separately from the base bg (graph.fill)
 
-
  - tests
 
 Bug fixes:
@@ -50,24 +49,6 @@ Bug fixes:
    add_bar_data_series() and now adds the series as a "bar" series.
    add_column_data_series() did nothing useful for a horizontal chart.
 
-TODO:
-
- - control of drawing markers for:
-
-   - area
-
-   - line
-
- - control of x/yaxis separate from graph area outline
-
- - test line markers
-
- - document:
-
-   - features: horizontal_gridlines, graph_outline, graph_fill
-
-   - graph outline and gridline styles
-
 
 Imager-Graph 0.07 - 21 May 2009
 =================
index 34506ee0599f83033989c97c839a86f43f218871..5694cef4d8fad69353fc548857535fe65543e091 100644 (file)
--- a/Graph.pm
+++ b/Graph.pm
@@ -1266,6 +1266,15 @@ my %style_defs =
            aa => 'lookup(aa)',
           },
    lineaa => 'lookup(aa)',
+
+    line_markers =>[
+      { shape => 'circle',   radius => 4 },
+      { shape => 'square',   radius => 4 },
+      { shape => 'diamond',  radius => 4 },
+      { shape => 'triangle', radius => 4 },
+      { shape => 'x',        radius => 4 },
+      { shape => 'plus',     radius => 4 },
+    ],
   );
 
 =item _error($message)
@@ -1416,14 +1425,6 @@ my %styles =
     colors  => [
      qw(FF0000 00FF00 0000FF C0C000 00C0C0 FF00FF)
     ],
-    line_markers =>[
-      { shape => 'circle',   radius => 4 },
-      { shape => 'square',   radius => 4 },
-      { shape => 'diamond',  radius => 4 },
-      { shape => 'triangle', radius => 4 },
-      { shape => 'x',        radius => 4 },
-      { shape => 'plus',     radius => 4 },
-    ],
     back=>{ fountain=>'linear',
             xa_ratio=>0, ya_ratio=>0,
             xb_ratio=>1.0, yb_ratio=>1.0,
@@ -1562,7 +1563,6 @@ $styles{'ocean_flat'} = {
 
 };
 
-
 =item $self->_style_setup(\%opts)
 
 Uses the values from %opts, the custom style set by methods, the style
index 4466c6834fd80fe1219ff261d1cbe4ffc89a08ef..954cf9f109b6f99a5a9e0e232877916051891e57 100644 (file)
@@ -459,9 +459,11 @@ sub _draw_lines {
 
     my $x2 = $left + ($value_range - $data[$data_size - 1] + $min_value)/$value_range * $graph_width;
 
-    push @marker_positions, [$x2, $y2];
-    foreach my $position (@marker_positions) {
-      $self->_draw_line_marker($position->[0], $position->[1], $series_counter);
+    if ($self->_feature_enabled("linemarkers")) {
+      push @marker_positions, [$x2, $y2];
+      foreach my $position (@marker_positions) {
+       $self->_draw_line_marker($position->[0], $position->[1], $series_counter);
+      }
     }
     $series_counter++;
   }
@@ -603,6 +605,28 @@ sub set_vertical_gridline_style {
   return 1;
 }
 
+=item show_line_markers()
+
+=item show_line_markers($value)
+
+Feature: linemarkers.
+
+If $value is missing or true, draw markers on a line data series.
+
+Note: line markers are drawn by default.
+
+=cut
+
+sub show_line_markers {
+  my ($self, $value) = @_;
+
+  @_ > 1 or $value = 1;
+
+  $self->{custom_style}{features}{linemarkers} = $value;
+
+  return 1;
+}
+
 =item use_automatic_axis()
 
 Automatically scale the Y axis, based on L<Chart::Math::Axis>.  If Chart::Math::Axis isn't installed, this sets an error and returns undef.  Returns 1 if it is installed.
@@ -861,7 +885,7 @@ sub _style_defs {
   my ($self) = @_;
 
   my %work = %{$self->SUPER::_style_defs()};
-  push @{$work{features}}, qw/graph_outline graph_fill/;
+  push @{$work{features}}, qw/graph_outline graph_fill linemarkers/;
   $work{vgrid} =
     {
      color => "lookup(fg)",
index b91dd4bc5aa62920cd5d8a6183124fc799e1dd10..4a92f583ac4a0c1aa76fbfb1afb12983faf0723b 100644 (file)
@@ -38,6 +38,7 @@ use strict;
 use vars qw(@ISA);
 use Imager::Graph;
 @ISA = qw(Imager::Graph);
+use Imager::Fill;
 
 use constant STARTING_MIN_VALUE => 99999;
 
@@ -639,9 +640,11 @@ sub _draw_lines {
 
     my $y2 = $bottom + ($value_range - $data[$data_size - 1] + $min_value)/$value_range * $graph_height;
 
-    push @marker_positions, [$x2, $y2];
-    foreach my $position (@marker_positions) {
-      $self->_draw_line_marker($position->[0], $position->[1], $series_counter);
+    if ($self->_feature_enabled("linemarkers")) {
+      push @marker_positions, [$x2, $y2];
+      foreach my $position (@marker_positions) {
+       $self->_draw_line_marker($position->[0], $position->[1], $series_counter);
+      }
     }
     $series_counter++;
   }
@@ -1057,20 +1060,50 @@ sub set_graph_fill_style {
 
 =item show_area_markers()
 
+=item show_area_markers($value)
+
 Feature: areamarkers.
 
-Draw line markers along the top of area data series.
+If $value is missing or true, draw markers along the top of area data
+series.
+
+eg.
+
+  $chart->show_area_markers();
 
 =cut
 
 sub show_area_markers {
-  my ($self) = @_;
+  my ($self, $value) = @_;
 
-  $self->{custom_style}{features}{areamarkers} = 1;
+  @_ > 1 or $value = 1;
+
+  $self->{custom_style}{features}{areamarkers} = $value;
 
   return 1;
 }
 
+=item show_line_markers()
+
+=item show_line_markers($value)
+
+Feature: linemarkers.
+
+If $value is missing or true, draw markers on a line data series.
+
+Note: line markers are drawn by default.
+
+=cut
+
+sub show_line_markers {
+  my ($self, $value) = @_;
+
+  @_ > 1 or $value = 1;
+
+  $self->{custom_style}{features}{linemarkers} = $value;
+
+  return 1;
+}
 
 =item use_automatic_axis()
 
@@ -1376,7 +1409,7 @@ sub _style_defs {
     {
      opacity => 0.5,
     };
-  push @{$work{features}}, qw/graph_outline graph_fill/;
+  push @{$work{features}}, qw/graph_outline graph_fill linemarkers/;
   $work{hgrid} =
     {
      color => "lookup(fg)",
index b686dcb413199cd99529e11246b6fca3854f6551..a9dbc4ca4daaa619dc35d383a5495050524ab968 100644 (file)
@@ -13,7 +13,7 @@ use Test::More;
 
 use Imager qw(:handy);
 
-plan tests => 3;
+plan tests => 5;
 
 my @warned;
 local $SIG{__WARN__} =
@@ -31,16 +31,32 @@ my $font = Imager::Font::Test->new();
 my @data = ( 100, 180, 80, 20, 2, 1, 0.5 );
 my @labels = qw(alpha beta gamma delta epsilon phi gi);
 
-my $column = Imager::Graph::Column->new();
-ok($column, "creating column chart object");
+{
+  my $column = Imager::Graph::Column->new();
+  ok($column, "creating column chart object");
 
-$column->add_data_series(\@data);
-$column->set_labels(\@labels);
+  $column->add_data_series(\@data);
+  $column->set_labels(\@labels);
 
-my $img1 = $column->draw();
-ok($img1, "drawing column chart");
+  my $img1 = $column->draw();
+  ok($img1, "drawing column chart");
 
-$img1->write(file=>'testout/t12_basic.ppm') or die "Can't save img1: ".$img1->errstr."\n";
+  $img1->write(file=>'testout/t12_column.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 $img1 = $column->draw(features => "outline");
+  ok($img1, "drawing column chart");
+
+  $img1->write(file=>'testout/t12_column2.ppm') or die "Can't save img1: ".$img1->errstr."\n";
+}
 
 unless (is(@warned, 0, "should be no warnings")) {
   diag($_) for @warned;
index c9cdf131cde3b80fd5929949cc1563f30e7dbb64..f3f6209dc8104b003209a406a9e3c45ad8ef9467 100644 (file)
@@ -13,7 +13,7 @@ use Test::More;
 
 use Imager qw(:handy);
 
-plan tests => 3;
+plan tests => 5;
 
 my @warned;
 local $SIG{__WARN__} =
@@ -31,17 +31,36 @@ my $font = Imager::Font::Test->new();
 my @data = ( 100, 180, 80, 20, 2, 1, 0.5 );
 my @labels = qw(alpha beta gamma delta epsilon phi gi);
 
-my $stacked_col = Imager::Graph::StackedColumn->new();
-ok($stacked_col, "creating stacked_col chart object");
+{
+  my $stacked_col = Imager::Graph::StackedColumn->new();
+  ok($stacked_col, "creating stacked_col chart object");
 
-$stacked_col->add_data_series(\@data);
-$stacked_col->set_labels(\@labels);
+  $stacked_col->add_data_series(\@data);
+  $stacked_col->set_labels(\@labels);
 
-my $img1 = $stacked_col->draw();
-ok($img1, "drawing stacked_col chart");
+  my $img1 = $stacked_col->draw();
+  ok($img1, "drawing stacked_col chart");
 
-$img1->write(file=>'testout/t13_basic.ppm') or die "Can't save img1: ".$img1->errstr."\n";
+  $img1->write(file=>'testout/t13_stacked.ppm') or die "Can't save img1: ".$img1->errstr."\n";
+}
+
+{
+  my $stacked_col = Imager::Graph::StackedColumn->new();
+  ok($stacked_col, "creating stacked_col chart object");
+
+  $stacked_col->add_data_series(\@data);
+  $stacked_col->add_data_series([ -50, -30, 20, 10, -10, 25, 10 ]);
+  $stacked_col->set_labels(\@labels);
 
+  my $img1 = $stacked_col->draw
+    (
+     features => "outline",
+     column_padding => 10,
+    );
+  ok($img1, "drawing stacked_col chart");
+
+  $img1->write(file=>'testout/t13_stacked2.ppm') or die "Can't save stacked2: ".$img1->errstr."\n";
+}
 
 unless (is(@warned, 0, "should be no warnings")) {
   diag($_) for @warned;