[pkg-GD-devel] Bug#489184: libgd-graph-perl: GD::Graph::pie "3D" rendering bugs

Peter Samuelson peter at p12n.org
Thu Jul 3 19:16:39 UTC 2008


Package: libgd-graph-perl
Version: 1.44-3
Tags: patch

GD::Graph::pie has a crude 3D effect enabled by default, but the
rendering of the Z direction is fragile; it fails to fill the correct
colors in several corner cases.  I'm attaching a patch to fix these,
plus a test script.  Of the 10 png files the script outputs to $TMPDIR,
the only correct one without my patch is test_08.png.
-- 
Peter Samuelson | org-tld!p12n!peter | http://p12n.org/
-------------- next part --------------
diff -u'rNx*~' GDGraph-1.44_01/Graph/pie.pm GDGraph-working/Graph/pie.pm
--- GDGraph-1.44_01/Graph/pie.pm	2007-05-01 23:06:32.000000000 -0500
+++ GDGraph-working/Graph/pie.pm	2008-07-03 13:56:56.000000000 -0500
@@ -289,6 +289,8 @@
 
     for (my $i = 0; $i < @values; $i++)
     {
+        next unless $values[$i];
+
         # Set the data colour
         my $dc = $self->set_clr_uniq($self->pick_data_clr($i + 1));
 
@@ -400,7 +402,7 @@
             # Ah, but if this wraps all the way around the back
             # then both pieces of the front need to be filled.
             # sbonds.
-            if ($pa > $pb ) 
+            if ($pa >= $pb)
             {
                 # This takes care of the left bit on the front
                 # Since we know exactly where we are, and in which
@@ -436,9 +438,8 @@
         }
         elsif ( # both in back, but wrapping around the front
                 # CONTRIB kedlubnowski, Dan Rosendorf 
-            $pa > 90 && $pb > 90 && $pa >= $pb
-            or $pa < -90 && $pb < -90 && $pa >= $pb
-            or $pa < -90 && $pb > 90
+               $pa >= $pb && ($pa < 0 || $pb > 0)
+               or $pa < 0 && $pb > 0
         ) 
         {   
             $pa=$ANGLE_OFFSET - 180;
-------------- next part --------------
#!/usr/bin/perl -w

use GD::Graph::pie;

my $fileN = 1;
sub output {
    my $filename = sprintf '%s/test_%02d.png', $ENV{TMPDIR}||'/tmp', $fileN++;
    open my $out, '>', $filename;
    print $out shift->png;
    close $out;
    print "$filename\n";
}

my $pie = GD::Graph::pie->new(450, 300);
$pie->set(start_angle => 45);
output $pie->plot([['100%, angled'], [1]]);

$pie = GD::Graph::pie->new(450, 300);
$pie->set(start_angle => 90);
output $pie->plot([['100%, horiz. left'], [1]]);

$pie = GD::Graph::pie->new(450, 300);
$pie->set(start_angle => -90);
output $pie->plot([['100%, horiz. right'], [1]]);

$pie = GD::Graph::pie->new(450, 300);
$pie->set(start_angle => -90);
output $pie->plot([['100%, 0%', ''], [1, 0]]);

$pie = GD::Graph::pie->new(450, 300);
$pie->set(start_angle => -90);
output $pie->plot([['99%', '1%'], [99, 1]]);

$pie = GD::Graph::pie->new(450, 300);
$pie->set(start_angle => 90);
output $pie->plot([['50%', '50%'], [50, 50]]);

$pie = GD::Graph::pie->new(450, 300);
$pie->set(start_angle => -90);
output $pie->plot([['50%', '50%'], [50, 50]]);

$pie = GD::Graph::pie->new(450, 300);
$pie->set(start_angle => -90);
output $pie->plot([['25%', '25%', '50%'], [25, 25, 50]]);

$pie = GD::Graph::pie->new(450, 300);
$pie->set(start_angle => -90);
output $pie->plot([['50%', '25%', '25%'], [50, 25, 25]]);

$pie = GD::Graph::pie->new(450, 300);
$pie->set(start_angle => -90);
output $pie->plot([['50%', '15%', '20%', '15%'], [50, 15, 20, 15]]);


More information about the pkg-GD-devel mailing list