]> git.imager.perl.org - imager-graph.git/blame - t/t10pie.t
- add a new style "primary" which is primary_red with a light grey
[imager-graph.git] / t / t10pie.t
CommitLineData
35574351
TC
1#!perl -w
2use strict;
3use Imager::Graph::Pie;
86cab8ec
TC
4use lib 't/lib';
5use Imager::Font::Test;
bfcf9414 6use Test::More;
35574351
TC
7
8-d 'testout'
9 or mkdir "testout", 0700
10 or die "Could not create output directory: $!";
11
12++$|;
35574351
TC
13
14my $testnum = 1;
15
16use Imager qw(:handy);
17
86cab8ec
TC
18#my $fontfile = 'ImUgly.ttf';
19#my $font = Imager::Font->new(file=>$fontfile, type => 'ft2', aa=>1)
20# or plan skip_all => "Cannot create font object: ",Imager->errstr,"\n";
21my $font = Imager::Font::Test->new();
35574351
TC
22
23my @data = ( 100, 180, 80, 20, 2, 1, 0.5 );
24my @labels = qw(alpha beta gamma delta epsilon phi gi);
25
33a928b7 26plan tests => 13;
bfcf9414 27
35574351
TC
28my $pie = Imager::Graph::Pie->new;
29ok($pie, "creating pie chart object");
30
31# this may change output quality too
35574351
TC
32
33print "# Imager version: $Imager::VERSION\n";
34print "# Font type: ",ref $font,"\n";
35
36my $img1 = $pie->draw(data=>\@data, labels=>\@labels, font=>$font,
37 title=>{ text=>'Imager::Graph::Pie', size=>32 },
38 features=>{ outline=>1, labels=>1, pieblur=>0, },
39 outline=>{ line => '404040' },
bfcf9414 40 );
35574351 41
bfcf9414
TC
42ok($img1, "drawing first pie chart")
43 or print "# ",$pie->error,"\n";
35574351 44cmpimg($img1, "testimg/t10_pie1.png", 196880977);
bfcf9414 45$img1->write(file=>'testout/t10_pie1.ppm')
35574351
TC
46 or die "Cannot save pie1: ",$img1->errstr,"\n";
47
48my $img2 = $pie->draw(data=>\@data,
49 labels=>\@labels,
50 font=>$font,
51 title=>{ text=>'Imager::Graph::Pie', size=>36 },
52 features=>{ labelspconly=>1, _debugblur=>1,
53 legend=>1 },
7b94e723 54 legend=>{ border=>'000000', fill=>'C0C0C0', },
35574351 55 fills=>[ qw(404040 606060 808080 A0A0A0 C0C0C0 E0E0E0) ],
bfcf9414 56 );
35574351 57
bfcf9414
TC
58ok($img2, "drawing second pie chart")
59 or print "# ",$pie->error,"\n";
35574351 60cmpimg($img2, "testimg/t10_pie2.png", 255956289);
bfcf9414 61$img2->write(file=>'testout/t10_pie2.ppm')
35574351
TC
62 or die "Cannot save pie2: ",$img2->errstr,"\n";
63
64my ($im_version) = $Imager::VERSION =~ /(\d\.[\d_]+)/;
bfcf9414
TC
65{
66 $im_version > 0.38
67 or skip("very old Imager", 6);
35574351
TC
68 my $img3 = $pie->draw(data=>\@data, labels=>\@labels,
69 font=>$font, style=>'fount_lin',
70 features=>[ 'legend', 'labelspconly', ],
71 legend=>{ valign=>'center' });
bfcf9414
TC
72 ok($img3, "third chart")
73 or print "# ",$pie->error,"\n";
74 $img3->write(file=>'testout/t10_lin_fount.ppm')
35574351
TC
75 or die "Cannot save pie3: ",$img3->errstr,"\n";
76 cmpimg($img3, "testimg/t10_lin_fount.png", 180_000);
77
78 my $img4 = $pie->draw(data=>\@data, labels=>\@labels,
79 font=>$font, style=>'fount_rad',
80 features=>[ 'legend', 'labelspc', ],
81 legend=>{ valign=>'bottom',
82 halign=>'left',
83 border=>'000080' });
bfcf9414
TC
84 ok($img4, "fourth chart")
85 or print "# ",$pie->error,"\n";
86 $img4->write(file=>'testout/t10_rad_fount.ppm')
35574351
TC
87 or die "Cannot save pie3: ",$img4->errstr,"\n";
88 cmpimg($img4, "testimg/t10_rad_fount.png", 120_000);
89
90 my $img5 = $pie->draw(data=>\@data, labels=>\@labels,
91 font=>$font, style=>'mono',
92 features=>[ 'allcallouts', 'labelspc' ],
93 legend=>{ valign=>'bottom',
94 halign=>'right' });
bfcf9414
TC
95 ok($img5, "fifth chart")
96 or print "# ",$pie->error,"\n";
97 $img5->write(file=>'testout/t10_mono.ppm')
35574351
TC
98 or die "Cannot save pie3: ",$img5->errstr,"\n";
99 cmpimg($img5, "testimg/t10_mono.png", 550_000);
33a928b7
TC
100
101 my $img6 = $pie->draw(data=>\@data, labels=>\@labels,
102 font=>$font, style=>'fount_lin',
103 features=>[ 'allcallouts', 'labelspc', 'legend' ],
104 legend=>
105 {
106 valign=>'top',
107 halign=>'center',
108 orientation => 'horizontal',
109 fill => { solid => Imager::Color->new(0, 0, 0, 32) },
110 patchborder => undef,
111 #size => 30,
112 });
113 ok($img6, "sixth chart")
114 or print "# ",$pie->error,"\n";
115 $img6->write(file=>'testout/t10_hlegend.ppm')
116 or die "Cannot save pie6: ",$img5->errstr,"\n";
117 cmpimg($img6, "testimg/t10_hlegend.png", 550_000);
35574351 118}
35574351
TC
119
120sub cmpimg {
121 my ($img, $file, $limit) = @_;
122
123 $limit ||= 10000;
124
bfcf9414
TC
125 SKIP:
126 {
127 $Imager::formats{png}
128 or skip("No PNG support", 1);
129
35574351
TC
130 my $cmpimg = Imager->new;
131 $cmpimg->read(file=>$file)
132 or return ok(0, "Cannot read $file: ".$cmpimg->errstr);
133 my $diff = Imager::i_img_diff($img->{IMG}, $cmpimg->{IMG});
bfcf9414 134 cmp_ok($diff, '<', $limit, "Comparison to $file ($diff)");
35574351
TC
135 }
136}