File: mountain.t

package info (click to toggle)
libchart-perl 1.0.1-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 320 kB
  • ctags: 86
  • sloc: perl: 2,796; makefile: 33
file content (54 lines) | stat: -rw-r--r-- 1,392 bytes parent folder | download | duplicates (2)
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
use Chart::Mountain;
use File::Spec;

print "1..2\n";

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

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, '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 },
	},
	{
		'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,
	},
);

foreach my $i (1..@opts-1)
{
	my $newpath = File::Spec->catfile(File::Spec->curdir, 'samples', "mountain-$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);