]>
Commit | Line | Data |
---|---|---|
1 | #!perl -w | |
2 | use strict; | |
3 | use Imager::Graph::Line; | |
4 | use lib 't/lib'; | |
5 | use Imager::Font::Test; | |
6 | use Test::More; | |
7 | use Imager::Test qw(is_image); | |
8 | use Imager::Graph::Test 'cmpimg'; | |
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 => 29; | |
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 $vert = Imager::Graph::Vertical->new; | |
37 | ok($vert, "creating chart object"); | |
38 | $vert->set_y_tics(10); | |
39 | ||
40 | $vert->add_line_data_series(\@data1, "Test Line"); | |
41 | ||
42 | my $img1; | |
43 | { # default outline of chart area | |
44 | $img1 = $vert->draw | |
45 | ( | |
46 | labels => \@labels, | |
47 | font => $font, | |
48 | title => "Test", | |
49 | ) | |
50 | or print "# ", $vert->error, "\n"; | |
51 | ||
52 | ok($img1, "made the image"); | |
53 | ||
54 | ok($img1->write(file => "testout/x50line_def.ppm"), | |
55 | "save to testout"); | |
56 | ||
57 | cmpimg($img1, "xtestimg/x50line_def.png", 60_000); | |
58 | } | |
59 | ||
60 | { # no outline | |
61 | my $img2 = $vert->draw | |
62 | ( | |
63 | labels => \@labels, | |
64 | font => $font, | |
65 | title => "Test", | |
66 | features => [ qw/nograph_outline/ ], | |
67 | ) | |
68 | or print "# ", $vert->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/x50line_noout.ppm"), | |
75 | "save to testout"); | |
76 | ||
77 | cmpimg($img2, "xtestimg/x50line_noout.png", 60_000); | |
78 | ||
79 | my $img3 = $vert->draw | |
80 | ( | |
81 | labels => \@labels, | |
82 | font => $font, | |
83 | title => "Test", | |
84 | features => "nograph_outline", | |
85 | ) | |
86 | or print "# ", $vert->error, "\n"; | |
87 | ok($img3, "made with scalar features"); | |
88 | is_image($img3, $img2, "check that both feature mechanisms act the same"); | |
89 | ||
90 | my $img4 = $vert->draw | |
91 | ( | |
92 | labels => \@labels, | |
93 | font => $font, | |
94 | title => "Test", | |
95 | features => { "graph_outline" => 0 }, | |
96 | ) | |
97 | or print "# ", $vert->error, "\n"; | |
98 | ok($img4, "made with hashref features"); | |
99 | is_image($img4, $img2, "check that all feature mechanisms act the same"); | |
100 | } | |
101 | ||
102 | { | |
103 | # check no state remembered from nograph_outline | |
104 | my $img5 = $vert->draw | |
105 | ( | |
106 | labels => \@labels, | |
107 | font => $font, | |
108 | title => "Test", | |
109 | ) | |
110 | or print "# ", $vert->error, "\n"; | |
111 | ok($img5, "make with border again to check no state held"); | |
112 | is_image($img1, $img5, "check no state held"); | |
113 | } | |
114 | ||
115 | { # styled outline | |
116 | my $img6 = $vert->draw | |
117 | ( | |
118 | labels => \@labels, | |
119 | font => $font, | |
120 | title => "Test styled outline", | |
121 | graph => | |
122 | { | |
123 | outline => | |
124 | { | |
125 | color => "#fff", | |
126 | style => "dashed", | |
127 | }, | |
128 | }, | |
129 | ); | |
130 | ok($img6, "make chart with dashed outline of graph area"); | |
131 | ok($img6->write(file => "testout/x50line_dashout.ppm"), | |
132 | "save it"); | |
133 | cmpimg($img6, "xtestimg/x50line_dashout.png", 80_000); | |
134 | } | |
135 | ||
136 | { # no outline, styled fill | |
137 | my $img7 = $vert->draw | |
138 | ( | |
139 | labels => \@labels, | |
140 | font => $font, | |
141 | title => "Test styled outline", | |
142 | features => "nograph_outline", | |
143 | graph => | |
144 | { | |
145 | fill => { solid => "ffffffC0" }, | |
146 | }, | |
147 | ) | |
148 | or print "# ", $vert->error, "\n"; | |
149 | ok($img7, "made the image"); | |
150 | ok($img7->write(file => "testout/x50line_fill.ppm"), | |
151 | "save it"); | |
152 | cmpimg($img7, "xtestimg/x50line_fill.png", 80_000); | |
153 | } | |
154 | ||
155 | { # gridlines | |
156 | my $img8 = $vert->draw | |
157 | ( | |
158 | labels => \@labels, | |
159 | font => $font, | |
160 | title => "gridlines", | |
161 | features => "horizontal_gridlines", | |
162 | hgrid => { style => "dashed", color => "#A0A0A0" }, | |
163 | ) | |
164 | or print "# ", $vert->error, "\n"; | |
165 | ok($img8, "made the gridline image"); | |
166 | ok($img8->write(file => "testout/x50line_grid.ppm"), | |
167 | "save it"); | |
168 | cmpimg($img8, "xtestimg/x50line_grid.png", 60_000); | |
169 | ||
170 | # default horizontal gridlines | |
171 | my $imgb = $vert->draw | |
172 | ( | |
173 | labels => \@labels, | |
174 | font => $font, | |
175 | title => "gridlines", | |
176 | features => "horizontal_gridlines", | |
177 | ) | |
178 | or print "# ", $vert->error, "\n"; | |
179 | ok($imgb, "made the gridline image"); | |
180 | ok($imgb->write(file => "testout/x50line_griddef.ppm"), | |
181 | "save it"); | |
182 | cmpimg($imgb, "xtestimg/x50line_griddef.png", 60_000); | |
183 | ||
184 | } | |
185 | ||
186 | { # gridlines (set by method) | |
187 | my $vert2 = Imager::Graph::Vertical->new; | |
188 | $vert2->show_horizontal_gridlines(); | |
189 | $vert2->set_horizontal_gridline_style(style => "dashed", color => "#A0A0A0"); | |
190 | $vert2->set_labels(\@labels); | |
191 | $vert2->set_title("gridlines"); | |
192 | $vert2->add_line_data_series(\@data1, "Test Line"); | |
193 | $vert2->set_y_tics(10); | |
194 | $vert2->set_font($font); | |
195 | ||
196 | my $img9 = $vert2->draw | |
197 | ( | |
198 | #labels => \@labels, | |
199 | #font => $font, | |
200 | #title => "gridlines", | |
201 | #features => "horizontal_gridlines", | |
202 | #hgrid => { style => "dashed", color => "#A0A0A0" }, | |
203 | ) | |
204 | or print "# ", $vert2->error, "\n"; | |
205 | ok($img9, "made the gridline image (set by methods)"); | |
206 | ok($img9->write(file => "testout/x50line_gridm.ppm"), | |
207 | "save it"); | |
208 | cmpimg($img9, "xtestimg/x50line_grid.png", 60_000); | |
209 | } | |
210 | } | |
211 | ||
212 | END { | |
213 | unless ($ENV{IMAGER_GRAPH_KEEP_FILES}) { | |
214 | unlink "testout/x50line_def.ppm"; | |
215 | unlink "testout/x50line_noout.ppm"; | |
216 | unlink "testout/x50line_dashout.ppm"; | |
217 | unlink "testout/x50line_fill.ppm"; | |
218 | unlink "testout/x50line_grid.ppm"; | |
219 | unlink "testout/x50line_griddef.ppm"; | |
220 | unlink "testout/x50line_gridm.ppm"; | |
221 | } | |
222 | } | |
223 |