ignore more build detritus
[imager-graph.git] / t / t32series_labels.t
CommitLineData
1509eee7 1#!perl -w
2use strict;
3use Imager::Graph::Line;
4use lib 't/lib';
5use Imager::Font::Test;
6use Test::More;
7
8-d 'testout'
9 or mkdir "testout", 0700
10 or die "Could not create output directory: $!";
11
12++$|;
13
14my @warned;
15local $SIG{__WARN__} =
16 sub {
17 print STDERR $_[0];
18 push @warned, $_[0]
19 };
20
21
22use Imager qw(:handy);
23
24plan 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";
29my $font = Imager::Font::Test->new();
30
31my @data = (1 .. 1000);
32my @labels = qw(alpha beta gamma delta epsilon phi gi);
33
34my $line = Imager::Graph::Line->new();
35ok($line, "creating line chart object");
36$line->set_font($font);
37
38$line->add_data_series(\@data, "Data series 1");
39$line->set_labels(\@labels);
40$line->show_legend();
41
42my $img1 = $line->draw();
43ok($img1, "drawing line chart");
44
45$img1->write(file=>'testout/t32_series.ppm') or die "Can't save img1: ".$img1->errstr."\n";
5a50139d 46cmpimg($img1, 'testimg/t32_series.ppm', 80_000);
1509eee7 47
48unless (is(@warned, 0, "should be no warnings")) {
49 diag($_) for @warned;
50}
51
52
53sub cmpimg {
54 my ($img, $file, $limit) = @_;
55
56 $limit ||= 10000;
57
267997be 58 my $cmpimg = Imager->new;
59 $cmpimg->read(file=>$file)
60 or return ok(0, "Cannot read $file: ".$cmpimg->errstr);
61 my $diff = Imager::i_img_diff($img->{IMG}, $cmpimg->{IMG});
62 cmp_ok($diff, '<', $limit, "Comparison to $file ($diff)");
63
1509eee7 64}
65