3 use Imager::Graph::Line;
5 use Imager::Font::Test;
7 use Imager::Test qw(is_image);
8 use Imager::Graph::Test 'cmpimg';
11 or mkdir "testout", 0700
12 or die "Could not create output directory: $!";
16 use Imager qw(:handy);
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();
25 100, 180, 80, 20, 2, 1, 0.5 ,
27 my @labels = qw(alpha beta gamma delta epsilon phi gi);
31 # this may change output quality too
32 print "# Imager version: $Imager::VERSION\n";
33 print "# Font type: ",ref $font,"\n";
36 my $vert = Imager::Graph::Vertical->new;
37 ok($vert, "creating chart object");
38 $vert->set_y_tics(10);
40 $vert->add_line_data_series(\@data1, "Test Line");
43 { # default outline of chart area
50 or print "# ", $vert->error, "\n";
52 ok($img1, "made the image");
54 ok($img1->write(file => "testout/x50line_def.ppm"),
57 cmpimg($img1, "xtestimg/x50line_def.png", 60_000);
61 my $img2 = $vert->draw
66 features => [ qw/nograph_outline/ ],
68 or print "# ", $vert->error, "\n";
70 isnt($img1, $img2, "make sure they're different images");
72 ok($img2, "made the image");
74 ok($img2->write(file => "testout/x50line_noout.ppm"),
77 cmpimg($img2, "xtestimg/x50line_noout.png", 60_000);
79 my $img3 = $vert->draw
84 features => "nograph_outline",
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");
90 my $img4 = $vert->draw
95 features => { "graph_outline" => 0 },
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");
103 # check no state remembered from nograph_outline
104 my $img5 = $vert->draw
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");
116 my $img6 = $vert->draw
120 title => "Test styled outline",
130 ok($img6, "make chart with dashed outline of graph area");
131 ok($img6->write(file => "testout/x50line_dashout.ppm"),
133 cmpimg($img6, "xtestimg/x50line_dashout.png", 80_000);
136 { # no outline, styled fill
137 my $img7 = $vert->draw
141 title => "Test styled outline",
142 features => "nograph_outline",
145 fill => { solid => "ffffffC0" },
148 or print "# ", $vert->error, "\n";
149 ok($img7, "made the image");
150 ok($img7->write(file => "testout/x50line_fill.ppm"),
152 cmpimg($img7, "xtestimg/x50line_fill.png", 80_000);
156 my $img8 = $vert->draw
160 title => "gridlines",
161 features => "horizontal_gridlines",
162 hgrid => { style => "dashed", color => "#A0A0A0" },
164 or print "# ", $vert->error, "\n";
165 ok($img8, "made the gridline image");
166 ok($img8->write(file => "testout/x50line_grid.ppm"),
168 cmpimg($img8, "xtestimg/x50line_grid.png", 60_000);
170 # default horizontal gridlines
171 my $imgb = $vert->draw
175 title => "gridlines",
176 features => "horizontal_gridlines",
178 or print "# ", $vert->error, "\n";
179 ok($imgb, "made the gridline image");
180 ok($imgb->write(file => "testout/x50line_griddef.ppm"),
182 cmpimg($imgb, "xtestimg/x50line_griddef.png", 60_000);
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);
196 my $img9 = $vert2->draw
200 #title => "gridlines",
201 #features => "horizontal_gridlines",
202 #hgrid => { style => "dashed", color => "#A0A0A0" },
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"),
208 cmpimg($img9, "xtestimg/x50line_grid.png", 60_000);
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";