]> git.imager.perl.org - imager-graph.git/commitdiff
hoist line marker drawing into the base class
authorTony Cook <tony@develop-help.com>
Mon, 26 Jul 2010 11:18:43 +0000 (11:18 +0000)
committerTony Cook <tony@develop-help.com>
Mon, 26 Jul 2010 11:18:43 +0000 (11:18 +0000)
add new marker types suitable for the mono style

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

index 5a4165a29009215c90e89042aac749528ca661f6..34506ee0599f83033989c97c839a86f43f218871 100644 (file)
--- a/Graph.pm
+++ b/Graph.pm
@@ -1362,6 +1362,21 @@ my %styles =
            blur=>undef,
           },
     aa => 0,
+    line_markers =>
+    [
+     { shape => "x", radius => 4 },
+     { shape => "plus", radius => 4 },
+     { shape => "open_circle", radius => 4 },
+     { shape => "open_diamond", radius => 5 },
+     { shape => "open_square", radius => 4 },
+     { shape => "open_triangle", radius => 4 },
+     { shape => "x", radius => 8 },
+     { shape => "plus", radius => 8 },
+     { shape => "open_circle", radius => 8 },
+     { shape => "open_diamond", radius => 10 },
+     { shape => "open_square", radius => 8 },
+     { shape => "open_triangle", radius => 8 },
+    ],
    },
    fount_lin =>
    {
@@ -2568,7 +2583,110 @@ sub _feature_enabled {
   return $self->{_style}{features}{$name};
 }
 
+sub _line_marker {
+  my ($self, $index) = @_;
+
+  my $markers = $self->{'_style'}{'line_markers'};
+  if (!$markers) {
+    return;
+  }
+  my $marker = $markers->[$index % @$markers];
+
+  return $marker;
+}
+
+sub _draw_line_marker {
+  my $self = shift;
+  my ($x1, $y1, $series_counter) = @_;
+
+  my $img = $self->_get_image();
+
+  my $style = $self->_line_marker($series_counter);
+  return unless $style;
+
+  my $type = $style->{'shape'};
+  my $radius = $style->{'radius'};
+
+  my $line_aa = $self->_get_number("lineaa");
+  my $fill_aa = $self->_get_number("fill.aa");
+
+  if ($type eq 'circle') {
+    my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
+    $img->circle(x => $x1, y => $y1, r => $radius, aa => $fill_aa, filled => 1, @fill);
+  }
+  elsif ($type eq 'open_circle') {
+    my $color = $self->_data_color($series_counter);
+    $img->circle(x => $x1, y => $y1, r => $radius, aa => $fill_aa, filled => 0, color => $color);
+  }
+  elsif ($type eq 'open_square') {
+    my $color = $self->_data_color($series_counter);
+    $img->box(xmin => $x1 - $radius, ymin => $y1 - $radius, xmax => $x1 + $radius, ymax => $y1 + $radius, filled => 0, color => $color);
+  }
+  elsif ($type eq 'open_triangle') {
+    my $color = $self->_data_color($series_counter);
+    $img->polyline(
+        points => [
+                    [$x1 - $radius, $y1 + $radius],
+                    [$x1 + $radius, $y1 + $radius],
+                    [$x1, $y1 - $radius],
+                    [$x1 - $radius, $y1 + $radius],
+                  ],
+        color => $color, aa => $line_aa);
+  }
+  elsif ($type eq 'open_diamond') {
+    my $color = $self->_data_color($series_counter);
+    $img->polyline(
+        points => [
+                    [$x1 - $radius, $y1],
+                    [$x1, $y1 + $radius],
+                    [$x1 + $radius, $y1],
+                    [$x1, $y1 - $radius],
+                    [$x1 - $radius, $y1],
+                  ],
+                 color => $color, aa => $line_aa);
+  }
+  elsif ($type eq 'square') {
+    my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
+    $img->box(xmin => $x1 - $radius, ymin => $y1 - $radius, xmax => $x1 + $radius, ymax => $y1 + $radius, @fill);
+  }
+  elsif ($type eq 'diamond') {
+    # The gradient really doesn't work for diamond
+    my $color = $self->_data_color($series_counter);
+    $img->polygon(
+        points => [
+                    [$x1 - $radius, $y1],
+                    [$x1, $y1 + $radius],
+                    [$x1 + $radius, $y1],
+                    [$x1, $y1 - $radius],
+                  ],
+        filled => 1, color => $color, aa => $fill_aa);
+  }
+  elsif ($type eq 'triangle') {
+    # The gradient really doesn't work for triangle
+    my $color = $self->_data_color($series_counter);
+    $img->polygon(
+        points => [
+                    [$x1 - $radius, $y1 + $radius],
+                    [$x1 + $radius, $y1 + $radius],
+                    [$x1, $y1 - $radius],
+                  ],
+        filled => 1, color => $color, aa => $fill_aa);
+
+  }
+  elsif ($type eq 'x') {
+    my $color = $self->_data_color($series_counter);
+    $img->line(x1 => $x1 - $radius, y1 => $y1 -$radius, x2 => $x1 + $radius, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
+    $img->line(x1 => $x1 + $radius, y1 => $y1 -$radius, x2 => $x1 - $radius, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
+  }
+  elsif ($type eq 'plus') {
+    my $color = $self->_data_color($series_counter);
+    $img->line(x1 => $x1, y1 => $y1 -$radius, x2 => $x1, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
+    $img->line(x1 => $x1 + $radius, y1 => $y1, x2 => $x1 - $radius, y2 => $y1, aa => $line_aa, color => $color) || die $img->errstr;
+  }
+}
+
 1;
+
 __END__
 
 =back
index bfab4ea44c55e8656ed0dcf571149e2cbd465fed..4466c6834fd80fe1219ff261d1cbe4ffc89a08ef 100644 (file)
@@ -470,76 +470,6 @@ sub _draw_lines {
   return;
 }
 
-sub _line_marker {
-  my ($self, $index) = @_;
-
-  my $markers = $self->{'_style'}{'line_markers'};
-  if (!$markers) {
-    return;
-  }
-  my $marker = $markers->[$index % @$markers];
-
-  return $marker;
-}
-
-sub _draw_line_marker {
-  my $self = shift;
-  my ($x1, $y1, $series_counter) = @_;
-
-  my $img = $self->_get_image();
-
-  my $style = $self->_line_marker($series_counter);
-  return unless $style;
-
-  my $type = $style->{'shape'};
-  my $radius = $style->{'radius'};
-
-  my $line_aa = $self->_get_number("lineaa");
-  my $fill_aa = $self->_get_number("fill.aa");
-  if ($type eq 'circle') {
-    my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
-    $img->circle(x => $x1, y => $y1, r => $radius, aa => $fill_aa, filled => 1, @fill);
-  }
-  elsif ($type eq 'square') {
-    my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
-    $img->box(xmin => $x1 - $radius, ymin => $y1 - $radius, xmax => $x1 + $radius, ymax => $y1 + $radius, @fill);
-  }
-  elsif ($type eq 'diamond') {
-    # The gradient really doesn't work for diamond
-    my $color = $self->_data_color($series_counter);
-    $img->polygon(
-        points => [
-                    [$x1 - $radius, $y1],
-                    [$x1, $y1 + $radius],
-                    [$x1 + $radius, $y1],
-                    [$x1, $y1 - $radius],
-                  ],
-        filled => 1, color => $color, aa => $fill_aa);
-  }
-  elsif ($type eq 'triangle') {
-    # The gradient really doesn't work for triangle
-    my $color = $self->_data_color($series_counter);
-    $img->polygon(
-        points => [
-                    [$x1 - $radius, $y1 + $radius],
-                    [$x1 + $radius, $y1 + $radius],
-                    [$x1, $y1 - $radius],
-                  ],
-        filled => 1, color => $color, aa => $fill_aa);
-
-  }
-  elsif ($type eq 'x') {
-    my $color = $self->_data_color($series_counter);
-    $img->line(x1 => $x1 - $radius, y1 => $y1 -$radius, x2 => $x1 + $radius, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
-    $img->line(x1 => $x1 + $radius, y1 => $y1 -$radius, x2 => $x1 - $radius, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
-  }
-  elsif ($type eq 'plus') {
-    my $color = $self->_data_color($series_counter);
-    $img->line(x1 => $x1, y1 => $y1 -$radius, x2 => $x1, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
-    $img->line(x1 => $x1 + $radius, y1 => $y1, x2 => $x1 - $radius, y2 => $y1, aa => $line_aa, color => $color) || die $img->errstr;
-  }
-}
-
 sub _draw_bars {
   my $self = shift;
   my $style = $self->{'_style'};
index ac31453e37267949befb7397e458f29fb002bb93..f06f7ead00843662c4d14ab84fb2dd68f8f38d35 100644 (file)
@@ -755,76 +755,6 @@ sub _draw_area {
   return 1;
 }
 
-sub _line_marker {
-  my ($self, $index) = @_;
-
-  my $markers = $self->{'_style'}{'line_markers'};
-  if (!$markers) {
-    return;
-  }
-  my $marker = $markers->[$index % @$markers];
-
-  return $marker;
-}
-
-sub _draw_line_marker {
-  my $self = shift;
-  my ($x1, $y1, $series_counter) = @_;
-
-  my $img = $self->_get_image();
-
-  my $style = $self->_line_marker($series_counter);
-  return unless $style;
-
-  my $type = $style->{'shape'};
-  my $radius = $style->{'radius'};
-
-  my $line_aa = $self->_get_number("lineaa");
-  my $fill_aa = $self->_get_number("fill.aa");
-  if ($type eq 'circle') {
-    my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
-    $img->circle(x => $x1, y => $y1, r => $radius, aa => $fill_aa, filled => 1, @fill);
-  }
-  elsif ($type eq 'square') {
-    my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
-    $img->box(xmin => $x1 - $radius, ymin => $y1 - $radius, xmax => $x1 + $radius, ymax => $y1 + $radius, @fill);
-  }
-  elsif ($type eq 'diamond') {
-    # The gradient really doesn't work for diamond
-    my $color = $self->_data_color($series_counter);
-    $img->polygon(
-        points => [
-                    [$x1 - $radius, $y1],
-                    [$x1, $y1 + $radius],
-                    [$x1 + $radius, $y1],
-                    [$x1, $y1 - $radius],
-                  ],
-        filled => 1, color => $color, aa => $fill_aa);
-  }
-  elsif ($type eq 'triangle') {
-    # The gradient really doesn't work for triangle
-    my $color = $self->_data_color($series_counter);
-    $img->polygon(
-        points => [
-                    [$x1 - $radius, $y1 + $radius],
-                    [$x1 + $radius, $y1 + $radius],
-                    [$x1, $y1 - $radius],
-                  ],
-        filled => 1, color => $color, aa => $fill_aa);
-
-  }
-  elsif ($type eq 'x') {
-    my $color = $self->_data_color($series_counter);
-    $img->line(x1 => $x1 - $radius, y1 => $y1 -$radius, x2 => $x1 + $radius, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
-    $img->line(x1 => $x1 + $radius, y1 => $y1 -$radius, x2 => $x1 - $radius, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
-  }
-  elsif ($type eq 'plus') {
-    my $color = $self->_data_color($series_counter);
-    $img->line(x1 => $x1, y1 => $y1 -$radius, x2 => $x1, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
-    $img->line(x1 => $x1 + $radius, y1 => $y1, x2 => $x1 - $radius, y2 => $y1, aa => $line_aa, color => $color) || die $img->errstr;
-  }
-}
-
 sub _draw_columns {
   my $self = shift;
   my $style = $self->{'_style'};