summaryrefslogtreecommitdiff
path: root/t/mountain_2.t
blob: f4a45ac7f96b015418d9553bd2219e18e2ff3bca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl -w

BEGIN { unshift @INC, 'lib', '../lib'}
use Chart::Mountain;
use File::Spec;
use File::Temp 0.19;
my $samples = File::Temp->newdir();

print "1..2\n";

my $a = ( 10**(-6) );

my @data = (
    [ "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th" ],
    [ ( 3 * $a ), ( 7 * $a ), ( 8 * $a ), ( 2 * $a ), ( 4 * $a ),   ( 8.5 * $a ), ( 2 * $a ), ( 5 * $a ), ( 9 * $a ) ],
    [ ( 4 * $a ), ( 2 * $a ), ( 5 * $a ), ( 6 * $a ), ( 3 * $a ),   ( 2.5 * $a ), ( 3 * $a ), ( 3 * $a ), ( 4 * $a ) ],
    [ ( 7 * $a ), ( 3 * $a ), ( 2 * $a ), ( 8 * $a ), ( 8.5 * $a ), ( 2 * $a ),   ( 9 * $a ), ( 4 * $a ), ( 5 * $a ) ],
);

my @hex_colors = qw(0099FF 00CC00 FFCC33 FF0099 3333FF);
my @colors     = map {
    [ map { hex($_) } unpack( "a2 a2 a2", $_ ) ]
} @hex_colors;

my @patterns = ();
foreach ( 1 .. @data - 1 )
{
    open( PNG, '<' . File::Spec->catfile( File::Spec->curdir, 't', 'patterns',  "PATTERN$_.PNG" ) ) || die "Can't load pattern $_";
    push( @patterns, GD::Image->newFromPng( \*PNG ) );
    close(PNG);
}

my @opts = (
    {},
    {
        'x_label'    => 'X Label',
        'y_label'    => 'Y label',
        'title'      => 'Mountain Chart',
        'grid_lines' => 'true',
        'colors'     => { map { ( "dataset$_" => $colors[$_] ) } 0 .. @colors - 1 },
        'precision'  => 6,

        #'integer_ticks_only'      => 'true',
    },
    {
        'x_label'    => 'X Label',
        'y_label'    => 'Y label',
        'title'      => 'Mountain Chart with Patterns',
        'grid_lines' => 'true',
        'colors'     => { map { ( "dataset$_" => $colors[$_] ) } 0 .. @colors - 1 },
        'patterns'   => \@patterns,
        'precision'  => 5,
    },
);

foreach my $i ( 1 .. @opts - 1 )
{
    my $newpath = File::Spec->catfile( $samples, "mountain_2-$i.png" );
    my $opts    = $opts[$i];
    my $g       = new Chart::Mountain();
    $g->set(%$opts);
    my $Image = $g->png( $newpath, \@data );
    print "ok $i\n";
}

exit(0);