remove more test generated files
[imager-graph.git] / t / t40area.t
1 #!perl -w
2 use strict;
3 use Imager::Graph::Area;
4 use lib 't/lib';
5 use Imager::Font::Test;
6 use Test::More;
7 use Imager::Test qw(is_image_similar);
8
9 -d 'testout' 
10   or mkdir "testout", 0700 
11   or die "Could not create output directory: $!";
12
13 ++$|;
14
15 use Imager qw(:handy);
16
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();
21
22 my @data1 =
23   (
24     100, 180, 80, 20, 2, 1, 0.5 ,
25   );
26 my @data2 =
27   (
28    10, 20, 40, 200, 150, 10, 50,
29   );
30 my @labels = qw(alpha beta gamma delta epsilon phi gi);
31
32 plan tests => 7;
33
34 {
35   my $area = Imager::Graph::Area->new;
36   ok($area, "creating area chart object");
37
38   # this may change output quality too
39   print "# Imager version: $Imager::VERSION\n";
40   print "# Font type: ",ref $font,"\n";
41
42   $area->add_data_series(\@data1, "Test Area");
43   $area->add_data_series(\@data2, "Test Area 2");
44
45   my $img1 = $area->draw
46     (
47      #data => \@data,
48      labels => \@labels,
49      font => $font, 
50      title => "Test",
51      features => { legend => 1 },
52      legend =>
53      { 
54       valign => "bottom",
55       halign => "center",
56       orientation => "horizontal",
57      },
58      area =>
59      {
60       opacity => 0.8,
61      },
62      #outline => { line => '404040' },
63     )
64       or print "# ", $area->error, "\n";
65
66   ok($img1, "made the image");
67
68   ok($img1->write(file => "testout/t40area1.ppm"),
69      "save to testout");
70
71   cmpimg($img1, "testimg/t40area1.png");
72 }
73
74 {
75   my $area = Imager::Graph::Area->new;
76   ok($area, "made area chart object");
77   $area->add_data_series(\@data1, "Test area");
78   $area->show_horizontal_gridlines();
79   $area->use_automatic_axis();
80   my $img2 = $area->draw
81     (
82      features => [ "horizontal_gridlines" ],
83      labels => \@labels,
84      font => $font,
85      hgrid => { style => "dashed", color => "#888" },
86      graph =>
87      {
88       outline => { color => "#F00", style => "dotted" },
89      },
90     );
91   ok($img2, "made second area chart image");
92   ok($img2->write(file => "testout/t40area2.ppm"),
93      "save to file");
94 }
95
96 END {
97   unless ($ENV{IMAGER_GRAPH_KEEP_FILES}) {
98     unlink "testout/t40area1.ppm";
99     unlink "testout/t40area2.ppm";
100   }
101 }
102
103 sub cmpimg {
104   my ($img, $file, $limit) = @_;
105
106   $limit ||= 10000;
107
108  SKIP:
109   {
110     $Imager::formats{png}
111       or skip("No PNG support", 1);
112
113     my $cmpimg = Imager->new;
114     $cmpimg->read(file=>$file)
115       or return ok(0, "Cannot read $file: ".$cmpimg->errstr);
116     my $diff = Imager::i_img_diff($img->{IMG}, $cmpimg->{IMG});
117     is_image_similar($img, $cmpimg, $limit, "Comparison to $file ($diff)");
118   }
119 }