From 26c93f4692a1c7394e59ae82b5eb50df90e03c06 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Mon, 21 Apr 2008 08:18:27 +0000 Subject: [PATCH] - zero-sized segments were drawn as covering the whole pie. Skip drawing zero sized segments. https://rt.cpan.org/Ticket/Display.html?id=34813 --- Changes | 4 ++ lib/Imager/Graph/Pie.pm | 4 ++ t/t10pie.t | 124 ++++++++++++++++++++++------------------ testimg/t10_noother.png | Bin 0 -> 4382 bytes 4 files changed, 76 insertions(+), 56 deletions(-) create mode 100644 testimg/t10_noother.png diff --git a/Changes b/Changes index f6c2053..0b9e82f 100644 --- 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. + - 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 ================= diff --git a/lib/Imager/Graph/Pie.pm b/lib/Imager/Graph/Pie.pm index f7e9177..84047df 100644 --- a/lib/Imager/Graph/Pie.pm +++ b/lib/Imager/Graph/Pie.pm @@ -278,6 +278,8 @@ sub draw { 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, @@ -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})); + $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; diff --git a/t/t10pie.t b/t/t10pie.t index 39711b7..e8493c9 100644 --- a/t/t10pie.t +++ b/t/t10pie.t @@ -11,8 +11,6 @@ use Test::More; ++$|; -my $testnum = 1; - 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); -plan tests => 13; +plan tests => 16; 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"; -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 { diff --git a/testimg/t10_noother.png b/testimg/t10_noother.png new file mode 100644 index 0000000000000000000000000000000000000000..fd9f414642d36a4ad95a939e4ed69ba941520db0 GIT binary patch literal 4382 zcma)9cQo8xxBd+iBM2tSt3(WvAbJ;d$mr1}T1M|RQNkp_kS2N%q7M_IM2VUZH4zcr z=mrr)8zqc37_SyTKwVu77mnKF!7wEX?006k4r;9KH01%qe z0a_}`j2xT1BxN{%PuDsS0O(o%b`X%6%|V%j1nC)SK_UmI~o5xo3#of%gsEOKPv3nG< znJ7iW@Xc6RrZofAx~LALsy@!i7zl4|MOnF8rvYeQ27LexP{AqjSjGs0Fx)uVt|P%G zEzb=AkWzKmA9q#(4qy-jy5(ypL>SZoKz#G<4^7&g6QB%ee_9v-W(KHefqwxr{4WsV z5J!N6-WL3kKM#W|521{NDHfDqfce7YY4NjcS(K0}GhS#u(gnE7950ysfd-6bq(uvw zPamQr=b&)7E~~u6XX{}%F!fJvifIs-;@;moK;ZwqjP5x-6eOm#@X`g$jLBJ1!SY`R zjU;mitq~aI!!4NyrGMxBBJtpZEOie%bDTTr-EP3Iz6O!Rv&AS?+f@YW=Wix zmnppWvm1Y3u)|>QaUG+8eJ+R=|Iw-SyP&7l|DxWb9d)BvS$pz~LTkptjv5$6xC5ezzcxQ`%pT+^29kIIqi7p=5Yt8pxwa`-qKQ^Ie}C%^N{&2T8RuIn9T^29=;)4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