3 use Imager::Graph::Bar;
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 $colm = Imager::Graph::Bar->new;
37 ok($colm, "creating chart object");
38 $colm->set_x_tics(10);
40 $colm->add_data_series(\@data1, "Test Bar");
43 { # default outline of chart area
50 or print "# ", $colm->error, "\n";
52 ok($img1, "made the image");
54 ok($img1->write(file => "testout/x51col_def.ppm"),
57 cmpimg($img1, "xtestimg/x51col_def.png", 80_000);
61 my $img2 = $colm->draw
66 features => [ qw/nograph_outline/ ],
68 or print "# ", $colm->error, "\n";
70 isnt($img1, $img2, "make sure they're different images");
72 ok($img2, "made the image");
74 ok($img2->write(file => "testout/x51col_noout.ppm"),
77 cmpimg($img2, "xtestimg/x51col_noout.png", 80_000);
81 # check no state remembered from nograph_outline
82 my $img5 = $colm->draw
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");
94 my $img6 = $colm->draw
98 title => "Test styled outline",
108 ok($img6, "make chart with dashed outline of graph area");
109 ok($img6->write(file => "testout/x51col_dashout.ppm"),
111 cmpimg($img6, "xtestimg/x51col_dashout.png", 80_000);
114 { # no outline, styled fill
115 my $img7 = $colm->draw
119 title => "Test styled outline",
120 features => "nograph_outline",
123 fill => { solid => "ffffff80" },
126 or print "# ", $colm->error, "\n";
127 ok($img7, "made the image");
128 ok($img7->write(file => "testout/x51col_fill.ppm"),
130 cmpimg($img7, "xtestimg/x51col_fill.png", 120_000);
134 my $img8 = $colm->draw
138 title => "gridlines",
139 features => "vertical_gridlines",
140 vgrid => { style => "dashed", color => "#A0A0A0" },
142 or print "# ", $colm->error, "\n";
143 ok($img8, "made the gridline image");
144 ok($img8->write(file => "testout/x51col_grid.ppm"),
146 cmpimg($img8, "xtestimg/x51col_grid.png", 80_000);
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);
159 my $img9 = $colm2->draw
163 #title => "gridlines",
164 #features => "vertical_gridlines",
165 #vgrid => { style => "dashed", color => "#A0A0A0" },
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"),
171 cmpimg($img9, "xtestimg/x51col_grid.png", 80_000);
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";