]> git.imager.perl.org - imager-graph.git/blobdiff - Graph.pm
Updates the MANIFEST
[imager-graph.git] / Graph.pm
index c200dabe0dba8c1f2030aca51cd8f411917f4b22..e74c00675aae5be98a4b1494f02aef938e399294 100644 (file)
--- a/Graph.pm
+++ b/Graph.pm
@@ -11,6 +11,7 @@ Imager::Graph - Perl extension for producing Graphs using the Imager library.
   my $chart = Imager::Graph::Sub_class->new;
   my $img = $chart->draw(data=> \@data, ...)
     or die $chart->error;
+  $img->write(file => 'image.png');
 
 =head1 DESCRIPTION
 
@@ -28,7 +29,7 @@ use vars qw($VERSION);
 use Imager qw(:handy);
 use Imager::Fountain;
 
-$VERSION = '0.06';
+$VERSION = '0.07';
 
 # the maximum recursion depth in determining a color, fill or number
 use constant MAX_DEPTH => 10;
@@ -89,6 +90,9 @@ sub add_data_series {
   my $graph_data = $self->{'graph_data'} || [];
 
   push @$graph_data, { data => $data_ref, series_name => $series_name };
+  if (defined $series_name) {
+    push @{$self->{'labels'}}, $series_name;
+  }
 
   $self->{'graph_data'} = $graph_data;
   return;
@@ -172,7 +176,7 @@ sub _get_style {
 
 =item error
 
-Returns an error message.  Only value if the draw() method returns false.
+Returns an error message.  Only valid if the draw() method returns false.
 
 =cut
 
@@ -196,7 +200,7 @@ the value can be a hashref containing sub values.
 The C<style> parameter will selects a basic color set, and possibly
 sets other related parameters.  See L</"STYLES">.
 
- my $font = Imager::Font->new(file => 'Im_ugly.ttf');
+ my $font = Imager::Font->new(file => 'ImUgly.ttf');
  my $img = $chart->draw(
                  data    => \@data,
                  font    => $font,
@@ -1151,10 +1155,12 @@ my %style_defs =
   (
    back=> 'lookup(bg)',
    line=> 'lookup(fg)',
+   aa => 1,
    text=>{
           color => 'lookup(fg)',
           font  => 'lookup(font)',
           size  => 14,
+         aa    => 'lookup(aa)',
          },
    title=>{ 
            color  => 'lookup(text.color)', 
@@ -1162,10 +1168,12 @@ my %style_defs =
            halign => 'center', 
            valign => 'top',
            size   => 'scale(text.size,2.0)',
+          aa     => 'lookup(text.aa)',
           },
    legend =>{
              color          => 'lookup(text.color)',
              font           => 'lookup(text.font)',
+            aa             => 'lookup(text.aa)',
              size           => 'lookup(text.size)',
              patchsize      => 'scale(legend.size,0.9)',
              patchgap       => 'scale(legend.patchsize,0.3)',
@@ -1184,6 +1192,8 @@ my %style_defs =
                outside  => 'lookup(callout.size)',
                leadlen  => 'scale(0.8,callout.size)',
                gap      => 'scale(callout.size,0.3)',
+              aa       => 'lookup(text.aa)',
+              lineaa   => 'lookup(lineaa)',
               },
    label => {
              font          => 'lookup(text.font)',
@@ -1194,6 +1204,8 @@ my %style_defs =
              pad           => 'scale(label.size,0.2)',
              pcformat      => sub { sprintf "%s (%.0f%%)", $_[0], $_[1] },
              pconlyformat  => sub { sprintf "%.1f%%", $_[0] },
+            aa            => 'lookup(text.aa)',
+            lineaa        => 'lookup(lineaa)',
              },
    dropshadow => {
                   fill    => { solid => Imager::Color->new(0, 0, 0, 96) },
@@ -1207,10 +1219,18 @@ my %style_defs =
                  },
    outline => {
                line =>'lookup(line)',
+              lineaa => 'lookup(lineaa)',
               },
    size=>256,
    width=>'scale(1.5,size)',
    height=>'lookup(size)',
+
+   # yes, the handling of fill and line AA is inconsistent, lack of
+   # forethought, unfortunately
+   fill => {
+           aa => 'lookup(aa)',
+          },
+   lineaa => 'lookup(aa)',
   );
 
 =item _error($message)
@@ -1306,6 +1326,7 @@ my %styles =
     pie =>{
            blur=>undef,
           },
+    aa => 0,
    },
    fount_lin =>
    {
@@ -1345,6 +1366,14 @@ 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,
@@ -1413,49 +1442,49 @@ $styles{'ocean'} = {
               xa_ratio => 0, ya_ratio=>0, xb_ratio=>1.0, yb_ratio=>1.0,
               segments => Imager::Fountain->simple(
                                                     positions=>[0, 1],
-                                                    colors=>[ NC('FFFFFF'), NC('E6E2AF') ]),
+                                                    colors=>[ NC('EFEDCF'), NC('E6E2AF') ]),
             },
              {
               fountain =>'linear',
               xa_ratio => 0, ya_ratio=>0, xb_ratio=>1.0, yb_ratio=>1.0,
               segments => Imager::Fountain->simple(
                                                     positions=>[0, 1],
-                                                    colors=>[ NC('FFFFFF'), NC('A7A37E') ]),
+                                                    colors=>[ NC('DCD7AB'), NC('A7A37E') ]),
             },
              {
               fountain =>'linear',
               xa_ratio => 0, ya_ratio=>0, xb_ratio=>1.0, yb_ratio=>1.0,
               segments => Imager::Fountain->simple(
                                                     positions=>[0, 1],
-                                                    colors=>[ NC('FFFFFF'), NC('80B4A2') ]),
+                                                    colors=>[ NC('B2E5D4'), NC('80B4A2') ]),
             },
             {
               fountain =>'linear',
               xa_ratio => 0, ya_ratio=>0, xb_ratio=>1.0, yb_ratio=>1.0,
               segments => Imager::Fountain->simple(
                                                     positions=>[0, 1],
-                                                    colors=>[ NC('FFFFFF'), NC('046380') ]),
+                                                    colors=>[ NC('7aaab9'), NC('046380') ]),
             },
             {
               fountain =>'linear',
               xa_ratio => 0, ya_ratio=>0, xb_ratio=>1.0, yb_ratio=>1.0,
               segments => Imager::Fountain->simple(
                                                     positions=>[0, 1],
-                                                    colors=>[ NC('FFFFFF'), NC('877EA7') ]),
+                                                    colors=>[ NC('c3b8e9'), NC('877EA7') ]),
             },
             {
               fountain =>'linear',
               xa_ratio => 0, ya_ratio=>0, xb_ratio=>1.0, yb_ratio=>1.0,
               segments => Imager::Fountain->simple(
                                                     positions=>[0, 1],
-                                                    colors=>[ NC('FFFFFF'), NC('67A35E') ]),
+                                                    colors=>[ NC('A3DF9A'), NC('67A35E') ]),
             },
             {
               fountain =>'linear',
               xa_ratio => 0, ya_ratio=>0, xb_ratio=>1.0, yb_ratio=>1.0,
               segments => Imager::Fountain->simple(
                                                     positions=>[0, 1],
-                                                    colors=>[ NC('FFFFFF'), NC('B4726F') ]),
+                                                    colors=>[ NC('E19C98'), NC('B4726F') ]),
             },
     ],
     colors  => [
@@ -1468,6 +1497,22 @@ $styles{'ocean'} = {
 
 };
 
+$styles{'ocean_flat'} = {
+    fills=>
+    [
+     qw(E6E2AF A7A37E 80B4A2 046380 877EA7 67A35E B4726F)
+    ],
+    colors  => [
+     qw(E6E2AF A7A37E 80B4A2 046380 877EA7 67A35E B4726F)
+    ],
+    fg=>'000000',
+    negative_bg=>'EEEEEE',
+    bg=>'FFFFFF',
+    features=>{ dropshadow=>1 },
+
+};
+
+
 =item $self->_style_setup(\%opts)
 
 Uses the values from %opts to build a customized hash describing the
@@ -1869,6 +1914,9 @@ and draw() methods intended for use in defining text styles.
 
 Returns an empty list on failure.
 
+Returns the following attributes: font, color, size, aa, sizew
+(optionally)
+
 =cut
 
 sub _text_style {
@@ -1896,6 +1944,7 @@ sub _text_style {
   $work{size} = $self->_get_number("$name.size");
   $work{sizew} = $self->_get_number("$name.sizew")
     if $work{sizew};
+  $work{aa} = $self->_get_number("$name.aa");
 
   %work;
 }
@@ -1920,6 +1969,28 @@ sub _text_bbox {
   return @bbox[0..3];
 }
 
+=item _line_style($name)
+
+Return parameters suitable for calls to Imager's line(), polyline(),
+and box() methods.
+
+For now this returns only color and aa parameters, but future releases
+of Imager may support extra parameters.
+
+=cut
+
+sub _line_style {
+  my ($self, $name) = @_;
+
+  my %line;
+  $line{color} = $self->_get_color("$name.line")
+    or return;
+  $line{aa} = $self->_get_number("$name.lineaa");
+  defined $line{aa} or $line{aa} = $self->_get_number("aa");
+
+  return %line;
+}
+
 sub _align_box {
   my ($self, $box, $chart_box, $name) = @_;