1#!/usr/bin/perl -w
2
3use Chart::Mountain;
4use File::Spec;
5
6print "1..2\n";
7
8my @data = (
9    [ "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th" ],
10    [ 3,     7,     8,     2,     4,     8.5,   2,     5,     9 ],
11    [ 4,     2,     5,     6,     3,     2.5,   3,     3,     4 ],
12    [ 7,     3,     2,     8,     8.5,   2,     9,     4,     5 ],
13);
14
15my @hex_colors = qw(0099FF 00CC00 FFCC33 FF0099 3333FF);
16my @colors     = map {
17    [ map { hex($_) } unpack( "a2 a2 a2", $_ ) ]
18} @hex_colors;
19
20my @patterns = ();
21foreach ( 1 .. @data - 1 )
22{
23    open( PNG, '<' . File::Spec->catfile( File::Spec->curdir, 'patterns', "PATTERN$_.PNG" ) ) || die "Can't load pattern $_";
24    push( @patterns, GD::Image->newFromPng( \*PNG ) );
25    close(PNG);
26}
27
28my @opts = (
29    {},
30    {
31        'x_label'    => 'X Label',
32        'y_label'    => 'Y label',
33        'title'      => 'Mountain Chart',
34        'grid_lines' => 'true',
35        'colors'     => { map { ( "dataset$_" => $colors[$_] ) } 0 .. @colors - 1 },
36    },
37    {
38        'x_label'    => 'X Label',
39        'y_label'    => 'Y label',
40        'title'      => 'Mountain Chart with Patterns',
41        'grid_lines' => 'true',
42        'colors'     => { map { ( "dataset$_" => $colors[$_] ) } 0 .. @colors - 1 },
43        'patterns'   => \@patterns,
44    },
45);
46
47foreach my $i ( 1 .. @opts - 1 )
48{
49    my $newpath = File::Spec->catfile( File::Spec->curdir, 'samples', "mountain-$i.png" );
50    my $opts    = $opts[$i];
51    my $g       = new Chart::Mountain();
52    $g->set(%$opts);
53    my $Image = $g->png( $newpath, \@data );
54    print "ok $i\n";
55}
56
57exit(0);
58
59