3 use Imager::Graph::Line;
5 use Imager::Font::Test;
7 use Imager::Test qw(is_image_similar is_image);
10 or mkdir "testout", 0700
11 or die "Could not create output directory: $!";
15 use Imager qw(:handy);
17 #my $fontfile = 'ImUgly.ttf';
18 #my $font = Imager::Font->new(file=>$fontfile, type => 'ft2', aa=>1)
19 # or plan skip_all => "Cannot create font object: ",Imager->errstr,"\n";
20 my $font = Imager::Font::Test->new();
24 100, 180, 80, 20, 2, 1, 0.5 ,
26 my @labels = qw(alpha beta gamma delta epsilon phi gi);
30 # this may change output quality too
31 print "# Imager version: $Imager::VERSION\n";
32 print "# Font type: ",ref $font,"\n";
35 my $vert = Imager::Graph::Vertical->new;
36 ok($vert, "creating chart object");
37 $vert->set_y_tics(10);
39 $vert->add_line_data_series(\@data1, "Test Line");
42 { # default outline of chart area
49 or print "# ", $vert->error, "\n";
51 ok($img1, "made the image");
53 ok($img1->write(file => "testout/x50line_def.ppm"),
56 cmpimg($img1, "xtestimg/x50line_def.png");
60 my $img2 = $vert->draw
65 features => [ qw/nograph_outline/ ],
67 or print "# ", $vert->error, "\n";
69 isnt($img1, $img2, "make sure they're different images");
71 ok($img2, "made the image");
73 ok($img2->write(file => "testout/x50line_noout.ppm"),
76 cmpimg($img2, "xtestimg/x50line_noout.png");
78 my $img3 = $vert->draw
83 features => "nograph_outline",
85 or print "# ", $vert->error, "\n";
86 ok($img3, "made with scalar features");
87 is_image($img3, $img2, "check that both feature mechanisms act the same");
89 my $img4 = $vert->draw
94 features => { "graph_outline" => 0 },
96 or print "# ", $vert->error, "\n";
97 ok($img4, "made with hashref features");
98 is_image($img4, $img2, "check that all feature mechanisms act the same");
102 # check no state remembered from nograph_outline
103 my $img5 = $vert->draw
109 or print "# ", $vert->error, "\n";
110 ok($img5, "make with border again to check no state held");
111 is_image($img1, $img5, "check no state held");
115 my $img6 = $vert->draw
119 title => "Test styled outline",
129 ok($img6, "make chart with dashed outline of graph area");
130 ok($img6->write(file => "testout/x50line_dashout.ppm"),
132 cmpimg($img6, "xtestimg/x50line_dashout.png");
135 { # no outline, styled fill
136 my $img7 = $vert->draw
140 title => "Test styled outline",
141 features => "nograph_outline",
144 fill => { solid => "ffffffC0" },
147 or print "# ", $vert->error, "\n";
148 ok($img7, "made the image");
149 ok($img7->write(file => "testout/x50line_fill.ppm"),
151 cmpimg($img7, "xtestimg/x50line_fill.png");
155 my $img8 = $vert->draw
159 title => "gridlines",
160 features => "horizontal_gridlines",
161 hgrid => { style => "dashed", color => "#A0A0A0" },
163 or print "# ", $vert->error, "\n";
164 ok($img8, "made the gridline image");
165 ok($img8->write(file => "testout/x50line_grid.ppm"),
167 cmpimg($img8, "xtestimg/x50line_grid.png");
169 # default horizontal gridlines
170 my $imgb = $vert->draw
174 title => "gridlines",
175 features => "horizontal_gridlines",
177 or print "# ", $vert->error, "\n";
178 ok($imgb, "made the gridline image");
179 ok($imgb->write(file => "testout/x50line_griddef.ppm"),
181 cmpimg($imgb, "xtestimg/x50line_griddef.png");
185 { # gridlines (set by method)
186 my $vert2 = Imager::Graph::Vertical->new;
187 $vert2->show_horizontal_gridlines();
188 $vert2->set_horizontal_gridline_style(style => "dashed", color => "#A0A0A0");
189 $vert2->set_labels(\@labels);
190 $vert2->set_title("gridlines");
191 $vert2->add_line_data_series(\@data1, "Test Line");
192 $vert2->set_y_tics(10);
193 $vert2->set_font($font);
195 my $img9 = $vert2->draw
199 #title => "gridlines",
200 #features => "horizontal_gridlines",
201 #hgrid => { style => "dashed", color => "#A0A0A0" },
203 or print "# ", $vert2->error, "\n";
204 ok($img9, "made the gridline image (set by methods)");
205 ok($img9->write(file => "testout/x50line_gridm.ppm"),
207 cmpimg($img9, "xtestimg/x50line_grid.png");
212 unless ($ENV{IMAGER_GRAPH_KEEP_FILES}) {
213 unlink "testout/x50line_def.ppm";
214 unlink "testout/x50line_noout.ppm";
215 unlink "testout/x50line_dashout.ppm";
216 unlink "testout/x50line_fill.ppm";
217 unlink "testout/x50line_grid.ppm";
218 unlink "testout/x50line_griddef.ppm";
219 unlink "testout/x50line_gridm.ppm";
224 my ($img, $file, $limit) = @_;
230 $Imager::formats{png}
231 or skip("No PNG support", 1);
233 my $cmpimg = Imager->new;
234 $cmpimg->read(file=>$file)
235 or return ok(0, "Cannot read $file: ".$cmpimg->errstr);
236 my $diff = Imager::i_img_diff($img->{IMG}, $cmpimg->{IMG});
237 is_image_similar($img, $cmpimg, $limit, "Comparison to $file ($diff)");