Commit | Line | Data |
---|---|---|
f94f373e | 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); | |
119bb3de | 8 | use Imager::Graph::Test qw(cmpimg); |
f94f373e | 9 | |
10 | -d 'testout' | |
11 | or mkdir "testout", 0700 | |
12 | or die "Could not create output directory: $!"; | |
13 | ||
14 | ++$|; | |
15 | ||
16 | use Imager qw(:handy); | |
17 | ||
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(); | |
22 | ||
23 | my @data1 = | |
24 | ( | |
25 | 100, 180, 80, 20, 2, 1, 0.5 , | |
26 | ); | |
27 | my @data2 = | |
28 | ( | |
29 | 10, 20, 40, 200, 150, 10, 50, | |
30 | ); | |
31 | my @labels = qw(alpha beta gamma delta epsilon phi gi); | |
32 | ||
62bf080f | 33 | plan tests => 8; |
56b495c0 TC |
34 | |
35 | { | |
36 | my $area = Imager::Graph::Area->new; | |
37 | ok($area, "creating area chart object"); | |
38 | ||
39 | # this may change output quality too | |
40 | print "# Imager version: $Imager::VERSION\n"; | |
41 | print "# Font type: ",ref $font,"\n"; | |
42 | ||
43 | $area->add_data_series(\@data1, "Test Area"); | |
44 | $area->add_data_series(\@data2, "Test Area 2"); | |
45 | ||
46 | my $img1 = $area->draw | |
47 | ( | |
48 | #data => \@data, | |
49 | labels => \@labels, | |
50 | font => $font, | |
51 | title => "Test", | |
52 | features => { legend => 1 }, | |
53 | legend => | |
54 | { | |
55 | valign => "bottom", | |
56 | halign => "center", | |
57 | orientation => "horizontal", | |
58 | }, | |
59 | area => | |
60 | { | |
61 | opacity => 0.8, | |
62 | }, | |
63 | #outline => { line => '404040' }, | |
64 | ) | |
65 | or print "# ", $area->error, "\n"; | |
66 | ||
67 | ok($img1, "made the image"); | |
68 | ||
69 | ok($img1->write(file => "testout/t40area1.ppm"), | |
70 | "save to testout"); | |
71 | ||
5a50139d | 72 | cmpimg($img1, "testimg/t40area1.png", 100_000); |
56b495c0 | 73 | } |
f94f373e | 74 | |
56b495c0 TC |
75 | { |
76 | my $area = Imager::Graph::Area->new; | |
77 | ok($area, "made area chart object"); | |
78 | $area->add_data_series(\@data1, "Test area"); | |
79 | $area->show_horizontal_gridlines(); | |
f58eaa57 | 80 | $area->set_y_tics(10); |
56b495c0 TC |
81 | my $img2 = $area->draw |
82 | ( | |
62bf080f | 83 | features => [ "horizontal_gridlines", "areamarkers" ], |
56b495c0 TC |
84 | labels => \@labels, |
85 | font => $font, | |
86 | hgrid => { style => "dashed", color => "#888" }, | |
87 | graph => | |
88 | { | |
89 | outline => { color => "#F00", style => "dotted" }, | |
90 | }, | |
91 | ); | |
92 | ok($img2, "made second area chart image"); | |
93 | ok($img2->write(file => "testout/t40area2.ppm"), | |
94 | "save to file"); | |
62bf080f | 95 | |
5a50139d | 96 | cmpimg($img2, "testimg/t40area2.png", 80_000); |
56b495c0 | 97 | } |
f94f373e | 98 | |
99 | END { | |
100 | unless ($ENV{IMAGER_GRAPH_KEEP_FILES}) { | |
101 | unlink "testout/t40area1.ppm"; | |
523a1013 | 102 | unlink "testout/t40area2.ppm"; |
f94f373e | 103 | } |
104 | } | |
105 |