]> git.imager.perl.org - imager-graph.git/blame - t/t12column.t
[rt #59532] allow negative_bg to be a fill for vertical charts
[imager-graph.git] / t / t12column.t
CommitLineData
2eac77fc 1#!perl -w
2use strict;
3use Imager::Graph::Column;
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
14use Imager qw(:handy);
15
90f723b5 16plan tests => 7;
28acfd43 17
18my @warned;
19local $SIG{__WARN__} =
20 sub {
21 print STDERR $_[0];
22 push @warned, $_[0]
23 };
24
2eac77fc 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 = ( 100, 180, 80, 20, 2, 1, 0.5 );
32my @labels = qw(alpha beta gamma delta epsilon phi gi);
33
0c2d2199
TC
34{
35 my $column = Imager::Graph::Column->new();
36 ok($column, "creating column chart object");
2eac77fc 37
0c2d2199
TC
38 $column->add_data_series(\@data);
39 $column->set_labels(\@labels);
2eac77fc 40
0c2d2199
TC
41 my $img1 = $column->draw();
42 ok($img1, "drawing column chart");
2eac77fc 43
0c2d2199
TC
44 $img1->write(file=>'testout/t12_column.ppm') or die "Can't save img1: ".$img1->errstr."\n";
45}
46
47{
48 my $column = Imager::Graph::Column->new();
49 ok($column, "creating column chart object");
50
51 $column->add_data_series(\@data);
52 $column->add_data_series([ -50, -30, 20, 10, -10, 25, 10 ]);
53 $column->set_labels(\@labels);
54
55 my $img1 = $column->draw(features => "outline");
56 ok($img1, "drawing column chart");
57
58 $img1->write(file=>'testout/t12_column2.ppm') or die "Can't save img1: ".$img1->errstr."\n";
59}
2eac77fc 60
90f723b5
TC
61{
62 my $column = Imager::Graph::Column->new();
63 ok($column, "creating column chart object");
64
65 $column->add_data_series(\@data);
66 $column->add_data_series([ -50, -30, 20, 10, -10, 25, 10 ]);
67 $column->set_labels(\@labels);
68
69 my $fountain = Imager::Fountain->simple(colors => [ "#C0C0FF", "#E0E0FF" ],
70 positions => [ 0, 1 ]);
71
72 my %fill =
73 (
74 fountain => "linear",
75 segments => $fountain,
76 xa_ratio => -0.1,
77 ya_ratio => 0.5,
78 xb_ratio => 1.1,
79 yb_ratio => 0.55,
80 );
81
82 my $img1 = $column->draw
83 (
84 features => "outline",
85 negative_bg => \%fill,
86 );
87 ok($img1, "drawing column chart - negative_bg is a fill");
88
89 $img1->write(file=>'testout/t12_column3.ppm') or die "Can't save img1: ".$img1->errstr."\n";
90}
91
28acfd43 92unless (is(@warned, 0, "should be no warnings")) {
93 diag($_) for @warned;
94}