Before this morning, I never really looked too carefully at the pie charts I was generating with GD::Graph. Then I had an epiphany, and suddenly they were the ugliest things anywhere. So I set about making them more beautiful.
- Anti-aliasing. I generate the pie four times larger than it needs to be, and then I use copyResampled from the GD library to shrink it down. No more jaggies, and the rather obvious stray pixels disappear.
- Three-dimensional shadow. To emphasize the 3d look, I had to make a small change to the GD::Graph::pie module itself. Mine was in /usr/lib/perl5/site_perl/5.8.4/GD/Graph/pie.pm, but YMMV. I applied this patch:
--- pie.pm 2004-10-12 11:10:30.272020883 -0400 +++ /usr/lib/perl5/site_perl/5.8.4/GD/Graph/pie.pm 2004-10-12 07:55:54.000000000 -0400 @@ -240,8 +240,13 @@
for (my $i = 0; $i < @values; $i++) {
-
my @col = $self->pick_data_clr($i + 1);
-
# Set the data colour
-
my $dc = $self->set_clr_uniq($self->pick_data_clr($i + 1));
-
my $dc = $self->set_clr_uniq(@col);
-
# Set the 3d shadow color (15% darker)
-
my $sc = $self->set_clr_uniq( map {$_ * 0.85} @col ); # Set the angles of the pie slice # Angle 0 faces down, positive angles are clockwise
@@ -292,7 +297,7 @@ { $self->{graph}->fillToBorder( $fill->[0], $fill->[1] + $self->{pie_height}/2,
-
$ac, $dc);
-
}$ac, $sc); } }
-
- Minor size tweaks. I think the graphs look much better when they're thicker (thickness about 10% total image height), and when the image is a little larger, and I even used 120x90, a magic 4:3 ratio.