1509eee7 |
1 | #!perl -w |
2 | use strict; |
3 | use Imager::Graph::Line; |
4 | use lib 't/lib'; |
5 | use Imager::Font::Test; |
6 | use Test::More; |
7 | |
8 | -d 'testout' |
9 | or mkdir "testout", 0700 |
10 | or die "Could not create output directory: $!"; |
11 | |
12 | ++$|; |
13 | |
14 | my @warned; |
15 | local $SIG{__WARN__} = |
16 | sub { |
17 | print STDERR $_[0]; |
18 | push @warned, $_[0] |
19 | }; |
20 | |
21 | |
22 | use Imager qw(:handy); |
23 | |
24 | plan tests => 4; |
25 | |
26 | #my $fontfile = 'ImUgly.ttf'; |
27 | #my $font = Imager::Font->new(file=>$fontfile, type => 'ft2', aa=>1) |
28 | # or plan skip_all => "Cannot create font object: ",Imager->errstr,"\n"; |
29 | my $font = Imager::Font::Test->new(); |
30 | |
267997be |
31 | my @data = (1 .. 7); |
1509eee7 |
32 | my @labels = qw(alpha beta gamma delta epsilon phi gi); |
33 | |
34 | my $line = Imager::Graph::Line->new(); |
35 | ok($line, "creating line chart object"); |
36 | |
37 | $line->set_font($font); |
38 | $line->add_data_series(\@data); |
39 | $line->set_labels(\@labels); |
40 | $line->use_automatic_axis(); |
41 | $line->set_y_tics(5); |
42 | |
43 | |
44 | my $img1 = $line->draw(outline => {line => '#FF0000'}); |
45 | ok($img1, "drawing line chart"); |
46 | |
47 | $img1->write(file=>'testout/t31tic_color.ppm') or die "Can't save img1: ".$img1->errstr."\n"; |
267997be |
48 | |
49 | eval { require Chart::Math::Axis; }; |
50 | if ($@) { |
5a50139d |
51 | cmpimg($img1, 'testimg/t31tic_color.ppm', 100_000); |
267997be |
52 | } |
53 | else { |
5a50139d |
54 | cmpimg($img1, 'testimg/t31tic_color_CMA.ppm', 100_000); |
267997be |
55 | } |
1509eee7 |
56 | |
57 | unless (is(@warned, 0, "should be no warnings")) { |
58 | diag($_) for @warned; |
59 | } |
60 | |
61 | |
62 | sub cmpimg { |
63 | my ($img, $file, $limit) = @_; |
64 | |
65 | $limit ||= 10000; |
66 | |
267997be |
67 | my $cmpimg = Imager->new; |
68 | $cmpimg->read(file=>$file) |
69 | or return ok(0, "Cannot read $file: ".$cmpimg->errstr); |
70 | my $diff = Imager::i_img_diff($img->{IMG}, $cmpimg->{IMG}); |
71 | cmp_ok($diff, '<', $limit, "Comparison to $file ($diff)"); |
1509eee7 |
72 | } |
73 | |