Add some features to GD::Graph

brian_d_foy on 2003-01-24T07:24:27

To make your moonphase picctures to look like mine , you need to make some changes to GD::Graph.

tibook_brian[3096]$ diff -b -u /usr/local/src/cpan/build/GDGraph-1.35/Graph/axestype.pm axestype.pm
--- /usr/local/src/cpan/build/GDGraph-1.35/Graph/axestype.pm    Tue Jun 11 06:38:27 2002
+++ axestype.pm Thu Jan 23 22:55:42 2003
@@ -16,6 +16,7 @@
 use strict;
  
 use GD::Graph;
+use GD::Graph::colour qw(_rgb);
 use GD::Graph::utils qw(:all);
 use Carp;
 
@@ -181,6 +182,12 @@
     # XXX mixed
     default_type    => 'lines',
     types           => undef,
+
+       # added for brian d foy
+       plot_background_clr => 'white',
+       tick_clr            => 'blue',
+       border_clr          => 'white',
+       border              => 0,
 );
 
 sub _has_default { 
@@ -890,6 +897,13 @@
     my ($l, $r, $b, $t) = 
         ( $self->{left}, $self->{right}, $self->{bottom}, $self->{top} );
     
+       if( $self->{plot_background_clr} )
+       {
+               my $g = $self->{graph};
+               my $clr = $g->colorAllocate(_rgb($self->{plot_background_clr}));
+               $g->filledRectangle($l+1, $t+1, $r-1, $b-1, $clr)
+       }
+
     # Sanity check for zero_axis and zero_axis_only
     unless ($self->{y_min}[1] < 0 && $self->{y_max}[1] > 0)
     {
@@ -918,6 +932,14 @@
         my ($x, $y) = $self->val_to_pixel(0, 0, 1);
 

$self->{graph}->line($l, $y, $r, $y, $self->{fgci}); } + + if( $self->{border} ) + { + my $g = $self->{graph}; + my $clr = $g->colorAllocate(_rgb($self->{border_clr})); + $g->rectangle(0,0,$self->{width}-1,$self->{height}-1, $clr); + } + } # @@ -1042,6 +1064,12 @@ { my $self = shift; + my $g = $self->{graph}; + + my $tick_clr = $self->{tick_clr} + ? $g->colorAllocate(_rgb($self->{tick_clr})) + : $self->{fgci}; + for (my $i = 0; $i < $self->{_data}->num_points; $i++) { my ($x, $y) = $self->val_to_pixel($i + 1, 0, 1); @@ -1059,12 +1087,12 @@ if ($self->{x_long_ticks}) { $self->{graph}->line($self->{left}, $y, $self->{right}, $y, - $self->{fgci}); + $tick_clr); } else { $self->{graph}->line( $x, $y, $x + $self->{x_tick_length}, $y, - $self->{fgci}); + $tick_clr); } } @@ -1095,6 +1123,12 @@ { my $self = shift; + my $g = $self->{graph}; + + my $tick_clr = $self->{tick_clr} + ? $g->colorAllocate(_rgb($self->{tick_clr})) + : $self->{fgci}; + for (my $i = 0; $i < $self->{_data}->num_points; $i++) { my ($x, $y) = $self->val_to_pixel($i + 1, 0, 1); @@ -1112,12 +1146,12 @@ if ($self->{x_long_ticks}) { $self->{graph}->line($x, $self->{bottom}, $x, $self->{top}, - $self->{fgci}); + $tick_clr); } else { $self->{graph}->line($x, $y, $x, $y - $self->{x_tick_length}, - $self->{fgci}); + $tick_clr); } } @@ -1187,6 +1221,12 @@ { my $self = shift; + my $g = $self->{graph}; + + my $tick_clr = $self->{tick_clr} + ? $g->colorAllocate(_rgb($self->{tick_clr})) + : $self->{fgci}; + for my $i (0 .. $self->{x_tick_number}) { my ($value, $x, $y); @@ -1217,13 +1257,13 @@ if ( $self->{x_tick_length} >= 0 ) { $self->{graph}->line($x, $self->{bottom}, - $x, $self->{top}, $self->{fgci}); + $x, $self->{top}, $tick_clr); } else { $self->{graph}->line( $x, $self->{bottom} - $self->{x_tick_length}, - $x, $self->{top}, $self->{fgci}); + $x, $self->{top}, $tick_clr); } } else