Commit | Line | Data |
---|---|---|
86f73dc2 TC |
1 | #!perl -w |
2 | use strict; | |
3 | use Imager::Graph::Bar; | |
4 | use lib 't/lib'; | |
5 | use Imager::Font::Test; | |
6 | use Test::More; | |
119bb3de TC |
7 | use Imager::Test qw(is_image); |
8 | use Imager::Graph::Test 'cmpimg'; | |
86f73dc2 TC |
9 | |
10 | -d 'testout' | |
11 | or mkdir "testout", 0700 | |
12 | or die "Could not create output directory: $!"; | |
13 | ||
14 | ++$|; | |
15 | ||
16 | use Imager qw(:handy); | |
17 | ||
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"; | |
21 | my $font = Imager::Font::Test->new(); | |
22 | ||
23 | my @data1 = | |
24 | ( | |
25 | 100, 180, 80, 20, 2, 1, 0.5 , | |
26 | ); | |
27 | my @labels = qw(alpha beta gamma delta epsilon phi gi); | |
28 | ||
29 | plan tests => 22; | |
30 | ||
31 | # this may change output quality too | |
32 | print "# Imager version: $Imager::VERSION\n"; | |
33 | print "# Font type: ",ref $font,"\n"; | |
34 | ||
35 | { | |
36 | my $colm = Imager::Graph::Bar->new; | |
37 | ok($colm, "creating chart object"); | |
38 | $colm->set_x_tics(10); | |
39 | ||
40 | $colm->add_data_series(\@data1, "Test Bar"); | |
41 | ||
42 | my $img1; | |
43 | { # default outline of chart area | |
44 | $img1 = $colm->draw | |
45 | ( | |
46 | labels => \@labels, | |
47 | font => $font, | |
48 | title => "Test", | |
49 | ) | |
50 | or print "# ", $colm->error, "\n"; | |
51 | ||
52 | ok($img1, "made the image"); | |
53 | ||
54 | ok($img1->write(file => "testout/x51col_def.ppm"), | |
55 | "save to testout"); | |
56 | ||
5a50139d | 57 | cmpimg($img1, "xtestimg/x51col_def.png", 80_000); |
86f73dc2 TC |
58 | } |
59 | ||
60 | { # no outline | |
61 | my $img2 = $colm->draw | |
62 | ( | |
63 | labels => \@labels, | |
64 | font => $font, | |
65 | title => "Test", | |
66 | features => [ qw/nograph_outline/ ], | |
67 | ) | |
68 | or print "# ", $colm->error, "\n"; | |
69 | ||
70 | isnt($img1, $img2, "make sure they're different images"); | |
71 | ||
72 | ok($img2, "made the image"); | |
73 | ||
74 | ok($img2->write(file => "testout/x51col_noout.ppm"), | |
75 | "save to testout"); | |
76 | ||
5a50139d | 77 | cmpimg($img2, "xtestimg/x51col_noout.png", 80_000); |
86f73dc2 TC |
78 | } |
79 | ||
80 | { | |
81 | # check no state remembered from nograph_outline | |
82 | my $img5 = $colm->draw | |
83 | ( | |
84 | labels => \@labels, | |
85 | font => $font, | |
86 | title => "Test", | |
87 | ) | |
88 | or print "# ", $colm->error, "\n"; | |
89 | ok($img5, "make with border again to check no state held"); | |
90 | is_image($img1, $img5, "check no state held"); | |
91 | } | |
92 | ||
93 | { # styled outline | |
94 | my $img6 = $colm->draw | |
95 | ( | |
96 | labels => \@labels, | |
97 | font => $font, | |
98 | title => "Test styled outline", | |
99 | graph => | |
100 | { | |
101 | outline => | |
102 | { | |
103 | color => "#fff", | |
104 | style => "dashed", | |
105 | }, | |
106 | }, | |
107 | ); | |
108 | ok($img6, "make chart with dashed outline of graph area"); | |
109 | ok($img6->write(file => "testout/x51col_dashout.ppm"), | |
110 | "save it"); | |
5a50139d | 111 | cmpimg($img6, "xtestimg/x51col_dashout.png", 80_000); |
86f73dc2 TC |
112 | } |
113 | ||
114 | { # no outline, styled fill | |
115 | my $img7 = $colm->draw | |
116 | ( | |
117 | labels => \@labels, | |
118 | font => $font, | |
119 | title => "Test styled outline", | |
120 | features => "nograph_outline", | |
121 | graph => | |
122 | { | |
123 | fill => { solid => "ffffff80" }, | |
124 | }, | |
125 | ) | |
126 | or print "# ", $colm->error, "\n"; | |
127 | ok($img7, "made the image"); | |
128 | ok($img7->write(file => "testout/x51col_fill.ppm"), | |
129 | "save it"); | |
5a50139d | 130 | cmpimg($img7, "xtestimg/x51col_fill.png", 120_000); |
86f73dc2 TC |
131 | } |
132 | ||
133 | { # gridlines | |
134 | my $img8 = $colm->draw | |
135 | ( | |
136 | labels => \@labels, | |
137 | font => $font, | |
138 | title => "gridlines", | |
139 | features => "vertical_gridlines", | |
140 | vgrid => { style => "dashed", color => "#A0A0A0" }, | |
141 | ) | |
142 | or print "# ", $colm->error, "\n"; | |
143 | ok($img8, "made the gridline image"); | |
144 | ok($img8->write(file => "testout/x51col_grid.ppm"), | |
145 | "save it"); | |
5a50139d | 146 | cmpimg($img8, "xtestimg/x51col_grid.png", 80_000); |
86f73dc2 TC |
147 | } |
148 | ||
149 | { # gridlines (set by method) | |
150 | my $colm2 = Imager::Graph::Bar->new; | |
151 | $colm2->show_vertical_gridlines(); | |
152 | $colm2->set_vertical_gridline_style(style => "dashed", color => "#A0A0A0"); | |
153 | $colm2->set_labels(\@labels); | |
154 | $colm2->set_title("gridlines"); | |
155 | $colm2->add_data_series(\@data1, "Test Bar"); | |
156 | $colm2->set_x_tics(10); | |
157 | $colm2->set_font($font); | |
158 | ||
159 | my $img9 = $colm2->draw | |
160 | ( | |
161 | #labels => \@labels, | |
162 | #font => $font, | |
163 | #title => "gridlines", | |
164 | #features => "vertical_gridlines", | |
165 | #vgrid => { style => "dashed", color => "#A0A0A0" }, | |
166 | ) | |
167 | or print "# ", $colm2->error, "\n"; | |
168 | ok($img9, "made the gridline image (set by methods)"); | |
169 | ok($img9->write(file => "testout/x51col_gridm.ppm"), | |
170 | "save it"); | |
5a50139d | 171 | cmpimg($img9, "xtestimg/x51col_grid.png", 80_000); |
86f73dc2 TC |
172 | } |
173 | } | |
174 | ||
175 | END { | |
176 | unless ($ENV{IMAGER_GRAPH_KEEP_FILES}) { | |
177 | unlink "testout/x51col_def.ppm"; | |
178 | unlink "testout/x51col_noout.ppm"; | |
179 | unlink "testout/x51col_dashout.ppm"; | |
180 | unlink "testout/x51col_fill.ppm"; | |
181 | unlink "testout/x51col_grid.ppm"; | |
182 | unlink "testout/x51col_gridm.ppm"; | |
183 | } | |
184 | } | |
185 |