changes from Patrick Michaud, line, bar, stacked column graphs
[imager-graph.git] / t / t20api.t
1 #!perl -w
2 use strict;
3 use Imager::Graph::Pie;
4 use lib 't/lib';
5 use Imager::Font::Test;
6 use Test::More;
7
8 ++$|;
9
10 use Imager qw(:handy);
11
12 plan tests => 3;
13
14 #my $fontfile = 'ImUgly.ttf';
15 #my $font = Imager::Font->new(file=>$fontfile, type => 'ft2', aa=>1)
16 #  or plan skip_all => "Cannot create font object: ",Imager->errstr,"\n";
17 my $font = Imager::Font::Test->new();
18
19 my @data = ( 100, 180, 80, 20, 2, 1, 0.5 );
20 my @labels = qw(alpha beta gamma delta epsilon phi gi);
21
22 my $api_pie = Imager::Graph::Pie->new();
23
24 $api_pie->addDataSeries(\@data, 'Demo series');
25 $api_pie->setFont($font);
26 $api_pie->setLabels(\@labels);
27 $api_pie->setGraphSize(50);
28 $api_pie->setImageWidth(200);
29 $api_pie->setImageHeight(200);
30 $api_pie->setTitle('Test 20');
31 $api_pie->setStyle('fount_rad');
32
33 my $api_img = $api_pie->draw();
34 ok($api_img);
35
36 my $data_pie = Imager::Graph::Pie->new();
37
38 my $data_img = $data_pie->draw(
39                                 data    => \@data,
40                                 labels  => \@labels,
41                                 font    => $font,
42                                 title   => { text => 'Test 20' },
43                                 style   => 'fount_rad',
44                                 size    => 50,
45                                 width   => 200,
46                                 height  => 200,
47                               );
48
49
50 ok($data_img);
51
52 my ($api_content, $data_content);
53
54 $data_img->write(data => \$data_content, type=>'tiff', tiff_compression => 'none') or die "Err: ".$data_img->errstr;
55 $api_img->write(data  => \$api_content,  type=>'tiff', tiff_compression => 'none') or die "Err: ".$api_img->errstr;
56
57 ok($data_content eq $api_content);
58
59