3 use Imager::Graph::Bar;
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 $colm = Imager::Graph::Bar->new;
36 ok($colm, "creating chart object");
37 $colm->set_x_tics(10);
39 $colm->add_data_series(\@data1, "Test Bar");
42 { # default outline of chart area
49 or print "# ", $colm->error, "\n";
51 ok($img1, "made the image");
53 ok($img1->write(file => "testout/x51col_def.ppm"),
56 cmpimg($img1, "xtestimg/x51col_def.png");
60 my $img2 = $colm->draw
65 features => [ qw/nograph_outline/ ],
67 or print "# ", $colm->error, "\n";
69 isnt($img1, $img2, "make sure they're different images");
71 ok($img2, "made the image");
73 ok($img2->write(file => "testout/x51col_noout.ppm"),
76 cmpimg($img2, "xtestimg/x51col_noout.png");
80 # check no state remembered from nograph_outline
81 my $img5 = $colm->draw
87 or print "# ", $colm->error, "\n";
88 ok($img5, "make with border again to check no state held");
89 is_image($img1, $img5, "check no state held");
93 my $img6 = $colm->draw
97 title => "Test styled outline",
107 ok($img6, "make chart with dashed outline of graph area");
108 ok($img6->write(file => "testout/x51col_dashout.ppm"),
110 cmpimg($img6, "xtestimg/x51col_dashout.png");
113 { # no outline, styled fill
114 my $img7 = $colm->draw
118 title => "Test styled outline",
119 features => "nograph_outline",
122 fill => { solid => "ffffff80" },
125 or print "# ", $colm->error, "\n";
126 ok($img7, "made the image");
127 ok($img7->write(file => "testout/x51col_fill.ppm"),
129 cmpimg($img7, "xtestimg/x51col_fill.png");
133 my $img8 = $colm->draw
137 title => "gridlines",
138 features => "vertical_gridlines",
139 vgrid => { style => "dashed", color => "#A0A0A0" },
141 or print "# ", $colm->error, "\n";
142 ok($img8, "made the gridline image");
143 ok($img8->write(file => "testout/x51col_grid.ppm"),
145 cmpimg($img8, "xtestimg/x51col_grid.png");
148 { # gridlines (set by method)
149 my $colm2 = Imager::Graph::Bar->new;
150 $colm2->show_vertical_gridlines();
151 $colm2->set_vertical_gridline_style(style => "dashed", color => "#A0A0A0");
152 $colm2->set_labels(\@labels);
153 $colm2->set_title("gridlines");
154 $colm2->add_data_series(\@data1, "Test Bar");
155 $colm2->set_x_tics(10);
156 $colm2->set_font($font);
158 my $img9 = $colm2->draw
162 #title => "gridlines",
163 #features => "vertical_gridlines",
164 #vgrid => { style => "dashed", color => "#A0A0A0" },
166 or print "# ", $colm2->error, "\n";
167 ok($img9, "made the gridline image (set by methods)");
168 ok($img9->write(file => "testout/x51col_gridm.ppm"),
170 cmpimg($img9, "xtestimg/x51col_grid.png");
175 unless ($ENV{IMAGER_GRAPH_KEEP_FILES}) {
176 unlink "testout/x51col_def.ppm";
177 unlink "testout/x51col_noout.ppm";
178 unlink "testout/x51col_dashout.ppm";
179 unlink "testout/x51col_fill.ppm";
180 unlink "testout/x51col_grid.ppm";
181 unlink "testout/x51col_gridm.ppm";
186 my ($img, $file, $limit) = @_;
192 $Imager::formats{png}
193 or skip("No PNG support", 1);
195 my $cmpimg = Imager->new;
196 $cmpimg->read(file=>$file)
197 or return ok(0, "Cannot read $file: ".$cmpimg->errstr);
198 my $diff = Imager::i_img_diff($img->{IMG}, $cmpimg->{IMG});
199 is_image_similar($img, $cmpimg, $limit, "Comparison to $file ($diff)");