]> git.imager.perl.org - imager-graph.git/commitdiff
- zero-sized segments were drawn as covering the whole pie. Skip
authorTony Cook <tony@develop-help.com>
Mon, 21 Apr 2008 08:18:27 +0000 (08:18 +0000)
committerTony Cook <tony@develop-help.com>
Mon, 21 Apr 2008 08:18:27 +0000 (08:18 +0000)
   drawing zero sized segments.
   https://rt.cpan.org/Ticket/Display.html?id=34813

Changes
lib/Imager/Graph/Pie.pm
t/t10pie.t
testimg/t10_noother.png [new file with mode: 0644]

diff --git a/Changes b/Changes
index f6c20530ac89db154d3e20c485e96ac91bcc7a37..0b9e82fe25250bda2954a10c6511a8c8280d5103 100644 (file)
--- a/Changes
+++ b/Changes
@@ -14,6 +14,10 @@ Imager-Graph 0.06 - unreleased
    background, and made that the default, so the default graphs aren't
    quite so ugly.
 
    background, and made that the default, so the default graphs aren't
    quite so ugly.
 
+ - zero-sized segments were drawn as covering the whole pie.  Skip
+   drawing zero sized segments.
+   https://rt.cpan.org/Ticket/Display.html?id=34813
+
 Imager-Graph 0.05 - 17 December 2007
 =================
 
 Imager-Graph 0.05 - 17 December 2007
 =================
 
index f7e9177a99735298821c71df3e54fd00ee5dd732..84047dfa736cd3c2096c7fda6343f413185a9f59 100644 (file)
@@ -278,6 +278,8 @@ sub draw {
 
   my @fill_box = ( $cx-$radius, $cy-$radius, $cx+$radius, $cy+$radius );
   for my $item (@info) {
 
   my @fill_box = ( $cx-$radius, $cy-$radius, $cx+$radius, $cy+$radius );
   for my $item (@info) {
+    $item->{begin} < $item->{end}
+      or next;
     my @fill = $self->_data_fill($item->{index}, \@fill_box)
       or return;
     $img->arc(x=>$cx, 'y'=>$cy, r=>$radius, aa => 1,
     my @fill = $self->_data_fill($item->{index}, \@fill_box)
       or return;
     $img->arc(x=>$cx, 'y'=>$cy, r=>$radius, aa => 1,
@@ -289,6 +291,8 @@ sub draw {
     for my $item (@info) {
       my $px = int($cx + $radius * cos($item->{begin}));
       my $py = int($cy + $radius * sin($item->{begin}));
     for my $item (@info) {
       my $px = int($cx + $radius * cos($item->{begin}));
       my $py = int($cy + $radius * sin($item->{begin}));
+      $item->{begin} < $item->{end}
+       or next;
       $img->line(x1=>$cx, y1=>$cy, x2=>$px, y2=>$py, color=>$outcolor);
       for (my $i = $item->{begin}; $i < $item->{end}; $i += PI/180) {
        my $stroke_end = $i + PI/180;
       $img->line(x1=>$cx, y1=>$cy, x2=>$px, y2=>$py, color=>$outcolor);
       for (my $i = $item->{begin}; $i < $item->{end}; $i += PI/180) {
        my $stroke_end = $i + PI/180;
index 39711b74bcd2e552d4b27c30368fdbac6dcb01e0..e8493c9c16d0b61e4a77c596aa837e0f5e7a5457 100644 (file)
@@ -11,8 +11,6 @@ use Test::More;
 
 ++$|;
 
 
 ++$|;
 
-my $testnum = 1;
-
 use Imager qw(:handy);
 
 #my $fontfile = 'ImUgly.ttf';
 use Imager qw(:handy);
 
 #my $fontfile = 'ImUgly.ttf';
@@ -23,7 +21,7 @@ my $font = Imager::Font::Test->new();
 my @data = ( 100, 180, 80, 20, 2, 1, 0.5 );
 my @labels = qw(alpha beta gamma delta epsilon phi gi);
 
 my @data = ( 100, 180, 80, 20, 2, 1, 0.5 );
 my @labels = qw(alpha beta gamma delta epsilon phi gi);
 
-plan tests => 13;
+plan tests => 16;
 
 my $pie = Imager::Graph::Pie->new;
 ok($pie, "creating pie chart object");
 
 my $pie = Imager::Graph::Pie->new;
 ok($pie, "creating pie chart object");
@@ -61,60 +59,74 @@ cmpimg($img2, "testimg/t10_pie2.png", 255956289);
 $img2->write(file=>'testout/t10_pie2.ppm')
   or die "Cannot save pie2: ",$img2->errstr,"\n";
 
 $img2->write(file=>'testout/t10_pie2.ppm')
   or die "Cannot save pie2: ",$img2->errstr,"\n";
 
-my ($im_version) = $Imager::VERSION =~ /(\d\.[\d_]+)/;
+my $img3 = $pie->draw(data=>\@data, labels=>\@labels,
+                     font=>$font, style=>'fount_lin', 
+                     features=>[ 'legend', 'labelspconly', ],
+                     legend=>{ valign=>'center' });
+ok($img3, "third chart")
+  or print "# ",$pie->error,"\n";
+$img3->write(file=>'testout/t10_lin_fount.ppm')
+  or die "Cannot save pie3: ",$img3->errstr,"\n";
+cmpimg($img3, "testimg/t10_lin_fount.png", 180_000);
+
+my $img4 = $pie->draw(data=>\@data, labels=>\@labels,
+                     font=>$font, style=>'fount_rad', 
+                     features=>[ 'legend', 'labelspc', ],
+                     legend=>{ valign=>'bottom', 
+                               halign=>'left',
+                               border=>'000080' });
+ok($img4, "fourth chart")
+  or print "# ",$pie->error,"\n";
+$img4->write(file=>'testout/t10_rad_fount.ppm')
+  or die "Cannot save pie3: ",$img4->errstr,"\n";
+cmpimg($img4, "testimg/t10_rad_fount.png", 120_000);
+
+my $img5 = $pie->draw(data=>\@data, labels=>\@labels,
+                     font=>$font, style=>'mono', 
+                     features=>[ 'allcallouts', 'labelspc' ],
+                     legend=>{ valign=>'bottom', 
+                               halign=>'right' });
+ok($img5, "fifth chart")
+  or print "# ",$pie->error,"\n";
+$img5->write(file=>'testout/t10_mono.ppm')
+  or die "Cannot save pie3: ",$img5->errstr,"\n";
+cmpimg($img5, "testimg/t10_mono.png", 550_000);
+
+my $img6 = $pie->draw(data=>\@data, labels=>\@labels,
+                     font=>$font, style=>'fount_lin', 
+                     features=>[ 'allcallouts', 'labelspc', 'legend' ],
+                     legend=>
+                     {
+                      valign=>'top', 
+                      halign=>'center',
+                      orientation => 'horizontal',
+                      fill => { solid => Imager::Color->new(0, 0, 0, 32) },
+                      patchborder => undef,
+                      #size => 30,
+                     });
+ok($img6, "sixth chart")
+  or print "# ",$pie->error,"\n";
+$img6->write(file=>'testout/t10_hlegend.ppm')
+  or die "Cannot save pie6: ",$img5->errstr,"\n";
+cmpimg($img6, "testimg/t10_hlegend.png", 550_000);
+
 {
 {
-  $im_version > 0.38
-    or skip("very old Imager", 6);
-  my $img3 = $pie->draw(data=>\@data, labels=>\@labels,
-                        font=>$font, style=>'fount_lin', 
-                        features=>[ 'legend', 'labelspconly', ],
-                        legend=>{ valign=>'center' });
-  ok($img3, "third chart")
-    or print "# ",$pie->error,"\n";
-  $img3->write(file=>'testout/t10_lin_fount.ppm')
-    or die "Cannot save pie3: ",$img3->errstr,"\n";
-  cmpimg($img3, "testimg/t10_lin_fount.png", 180_000);
-
-  my $img4 = $pie->draw(data=>\@data, labels=>\@labels,
-                        font=>$font, style=>'fount_rad', 
-                        features=>[ 'legend', 'labelspc', ],
-                        legend=>{ valign=>'bottom', 
-                                  halign=>'left',
-                                  border=>'000080' });
-  ok($img4, "fourth chart")
-    or print "# ",$pie->error,"\n";
-  $img4->write(file=>'testout/t10_rad_fount.ppm')
-    or die "Cannot save pie3: ",$img4->errstr,"\n";
-  cmpimg($img4, "testimg/t10_rad_fount.png", 120_000);
-
-  my $img5 = $pie->draw(data=>\@data, labels=>\@labels,
-                        font=>$font, style=>'mono', 
-                        features=>[ 'allcallouts', 'labelspc' ],
-                        legend=>{ valign=>'bottom', 
-                                  halign=>'right' });
-  ok($img5, "fifth chart")
-    or print "# ",$pie->error,"\n";
-  $img5->write(file=>'testout/t10_mono.ppm')
-    or die "Cannot save pie3: ",$img5->errstr,"\n";
-  cmpimg($img5, "testimg/t10_mono.png", 550_000);
-
-  my $img6 = $pie->draw(data=>\@data, labels=>\@labels,
-                        font=>$font, style=>'fount_lin', 
-                        features=>[ 'allcallouts', 'labelspc', 'legend' ],
-                        legend=>
-                       {
-                        valign=>'top', 
-                        halign=>'center',
-                        orientation => 'horizontal',
-                        fill => { solid => Imager::Color->new(0, 0, 0, 32) },
-                        patchborder => undef,
-                        #size => 30,
-                       });
-  ok($img6, "sixth chart")
-    or print "# ",$pie->error,"\n";
-  $img6->write(file=>'testout/t10_hlegend.ppm')
-    or die "Cannot save pie6: ",$img5->errstr,"\n";
-  cmpimg($img6, "testimg/t10_hlegend.png", 550_000);
+  # RT #34813
+  # zero sized segments were drawn to cover the whole circle
+  my @data = ( 10, 8, 5, 0.000 );
+  my @labels = qw(alpha beta gamma);
+  
+  my $img = $pie->draw
+    (
+     data => \@data, 
+     labels => \@labels, 
+     font => $font,
+     features => [ 'legend', 'labelspc', 'outline' ],
+    );
+  ok($img, "create graph with no 'others'");
+  ok($img->write(file => 'testout/t10_noother.ppm'),
+     "save it");
+  cmpimg($img, 'testimg/t10_noother.png', 500_000);
 }
 
 sub cmpimg {
 }
 
 sub cmpimg {
diff --git a/testimg/t10_noother.png b/testimg/t10_noother.png
new file mode 100644 (file)
index 0000000..fd9f414
Binary files /dev/null and b/testimg/t10_noother.png differ