3 use Imager::Graph::Pie;
6 or mkdir "testout", 0700
7 or die "Could not create output directory: $!";
14 use Imager qw(:handy);
16 # setting this to another font file will cause failed tests
17 # but may produce nicer text
18 my $fontfile; # = '/mnt/c/windows/fonts/arial.ttf';
20 my @data = ( 100, 180, 80, 20, 2, 1, 0.5 );
21 my @labels = qw(alpha beta gamma delta epsilon phi gi);
23 my $pie = Imager::Graph::Pie->new;
24 ok($pie, "creating pie chart object");
26 # this may change output quality too
27 #Imager::Font->priorities('ft2');
28 $fontfile = 'ImUgly.ttf' unless $fontfile and -e $fontfile;
29 my $font = Imager::Font->new(file=>$fontfile, aa=>1)
30 or die "Cannot create font object: ",Imager->errstr,"\n";
32 print "# Imager version: $Imager::VERSION\n";
33 print "# Font type: ",ref $font,"\n";
35 my $img1 = $pie->draw(data=>\@data, labels=>\@labels, font=>$font,
36 title=>{ text=>'Imager::Graph::Pie', size=>32 },
37 features=>{ outline=>1, labels=>1, pieblur=>0, },
38 outline=>{ line => '404040' },
40 or print "# ",$pie->error,"\n";
42 ok($img1, "drawing first pie chart");
43 cmpimg($img1, "testimg/t10_pie1.png", 196880977);
44 unlink('testout/t10_pie1.png');
45 $img1->write(file=>'testout/t10_pie1.png')
46 or die "Cannot save pie1: ",$img1->errstr,"\n";
48 my $img2 = $pie->draw(data=>\@data,
51 title=>{ text=>'Imager::Graph::Pie', size=>36 },
52 features=>{ labelspconly=>1, _debugblur=>1,
54 legend=>{ border=>'000000', fill=>'FF8080', },
55 fills=>[ qw(404040 606060 808080 A0A0A0 C0C0C0 E0E0E0) ],
57 or print "# ",$pie->error,"\n";
59 ok($img2, "drawing second pie chart");
60 cmpimg($img2, "testimg/t10_pie2.png", 255956289);
61 unlink('testout/t10_pie2.png');
62 $img2->write(file=>'testout/t10_pie2.png')
63 or die "Cannot save pie2: ",$img2->errstr,"\n";
65 my ($im_version) = $Imager::VERSION =~ /(\d\.[\d_]+)/;
66 if ($im_version > 0.38) {
67 my $img3 = $pie->draw(data=>\@data, labels=>\@labels,
68 font=>$font, style=>'fount_lin',
69 features=>[ 'legend', 'labelspconly', ],
70 legend=>{ valign=>'center' });
71 ok($img3, "third chart");
72 $img3->write(file=>'testout/t10_lin_fount.png')
73 or die "Cannot save pie3: ",$img3->errstr,"\n";
74 cmpimg($img3, "testimg/t10_lin_fount.png", 180_000);
76 my $img4 = $pie->draw(data=>\@data, labels=>\@labels,
77 font=>$font, style=>'fount_rad',
78 features=>[ 'legend', 'labelspc', ],
79 legend=>{ valign=>'bottom',
82 ok($img4, "fourth chart");
83 $img4->write(file=>'testout/t10_rad_fount.png')
84 or die "Cannot save pie3: ",$img4->errstr,"\n";
85 cmpimg($img4, "testimg/t10_rad_fount.png", 120_000);
87 my $img5 = $pie->draw(data=>\@data, labels=>\@labels,
88 font=>$font, style=>'mono',
89 features=>[ 'allcallouts', 'labelspc' ],
90 legend=>{ valign=>'bottom',
92 ok($img5, "fifth chart");
93 $img5->write(file=>'testout/t10_mono.png')
94 or die "Cannot save pie3: ",$img5->errstr,"\n";
95 cmpimg($img5, "testimg/t10_mono.png", 550_000);
98 skip("Imager not new enough", 6);
102 my ($test, $comment) = @_;
105 print "ok ",$testnum++," # $comment\n";
108 print "not ok ",$testnum++," # $comment\n";
113 my ($comment, $count) = @_;
117 print "ok ",$testnum++," # skipped $comment\n";
122 my ($img, $file, $limit) = @_;
126 if ($Imager::formats{png}) {
127 my $cmpimg = Imager->new;
128 $cmpimg->read(file=>$file)
129 or return ok(0, "Cannot read $file: ".$cmpimg->errstr);
130 my $diff = Imager::i_img_diff($img->{IMG}, $cmpimg->{IMG});
131 ok($diff < $limit, "Comparison to $file ($diff)");
134 skip("no png support");