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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
#============================================================= -*-perl-*-
#
# t/gdgraph.t
#
# Test the GD::Graph::* plugins. The GD::Graph::* modules don't
# come with any tests, so we simply verify that each graph type
# produces a PNG output file, but we don't verify the contents.
#
# Written by Craig Barratt <craig@arraycomm.com>
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# $Id: gdgraph.t,v 2.4 2002/08/12 11:07:15 abw Exp $
#
#========================================================================
use strict;
use lib qw( ../lib );
use Template;
use Template::Test;
$^W = 1;
eval "use GD; use GD::Graph;";
if ( $@ || $GD::VERSION < 1.20 ) {
skip_all('GD module(s) not installed');
}
test_expect(\*DATA, { FILTERS => {
head2hex => [\&head2hex_filter_factory, 1],
}
});
#
# Grab just the first $len bytes of the input, and optionally convert
# to a hex string if $hex is set
#
sub head2hex_filter_factory
{
my($context, $len, $hex) = @_;
return sub {
my $text = shift;
return $text if length $text < $len;
$text = substr($text, 0, $len);
$text =~ s/(.)/sprintf("%02x", ord($1))/eg if ( $hex );
return $text;
}
}
__END__
-- test --
[%
USE g = GD.Graph.lines(300,200);
x = [1, 2, 3, 4];
y = [5, 4, 2, 3];
r = g.set(x_label => 'X Label', y_label => 'Y label', title => 'Title');
g.plot([x, y]).png | head2hex(4, 1);
%]
-- expect --
89504e47
-- test --
[%
data = [
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 1, 2, 5, 6, 3, 1.5, 1, 3, 4],
];
USE my_graph = GD.Graph.bars();
r = my_graph.set(
x_label => 'X Label',
y_label => 'Y label',
title => 'A Simple Bar Chart',
y_max_value => 8,
y_tick_number => 8,
y_label_skip => 2,
# shadows
bar_spacing => 8,
shadow_depth => 4,
shadowclr => 'dred',
transparent => 0,
);
my_graph.plot(data).png | head2hex(4, 1);
%]
-- expect --
89504e47
-- test --
[%
data = [
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 5, 12, 24, 33, 19, 8, 6, 15, 21],
[ 1, 2, 5, 6, 3, 1.5, 1, 3, 4],
];
USE my_graph = GD.Graph.bars();
r = my_graph.set(
x_label => 'X Label',
y_label => 'Y label',
title => 'Two data sets',
# shadows
bar_spacing => 8,
shadow_depth => 4,
shadowclr => 'dred',
long_ticks => 1,
y_max_value => 40,
y_tick_number => 8,
y_label_skip => 2,
bar_spacing => 3,
accent_treshold => 200,
transparent => 0,
);
r = my_graph.set_legend( 'Data set 1', 'Data set 2' );
my_graph.plot(data).png | head2hex(4, 1);
%]
-- expect --
89504e47
-- test --
[%
data = [
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[50, 52, 53, 54, 55, 56, 57, 58, 59],
[60, 61, 61, 63, 68, 66, 65, 61, 58],
[70, 72, 71, 74, 78, 73, 75, 71, 68],
];
USE my_graph = GD.Graph.linespoints;
r = my_graph.set(
x_label => 'X Label',
y_label => 'Y label',
title => 'A Lines and Points Graph',
y_max_value => 80,
y_tick_number => 6,
y_label_skip => 2,
y_long_ticks => 1,
x_tick_length => 2,
markers => [ 1, 5 ],
skip_undef => 1,
transparent => 0,
);
r = my_graph.set_legend('data set 1', 'data set 2', 'data set 3');
my_graph.plot(data).png | head2hex(4, 1);
%]
-- expect --
89504e47
-- test --
[%
data = [
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 1, 2, 5, 6, 3, 1.5, -1, -3, -4],
[ -4, -3, 1, 1, -3, -1.5, -2, -1, 0],
[ 9, 8, 9, 8.4, 7.1, 7.5, 8, 3, -3],
[ 0.1, 0.2, 0.5, 0.4, 0.3, 0.5, 0.1, 0, 0.4],
[ -0.1, 2, 5, 4, -3, 2.5, 3.2, 4, -4],
];
USE my_graph = GD.Graph.mixed();
r = my_graph.set(
types => ['lines', 'lines', 'points', 'area', 'linespoints'],
default_type => 'points',
);
r = my_graph.set(
x_label => 'X Label',
y_label => 'Y label',
title => 'A Mixed Type Graph',
y_max_value => 10,
y_min_value => -5,
y_tick_number => 3,
y_label_skip => 0,
x_plot_values => 0,
y_plot_values => 0,
long_ticks => 1,
x_ticks => 0,
legend_marker_width => 24,
line_width => 3,
marker_size => 5,
bar_spacing => 8,
transparent => 0,
);
r = my_graph.set_legend('one', 'two', 'three', 'four', 'five', 'six');
my_graph.plot(data).png | head2hex(4, 1);
%]
-- expect --
89504e47
-- test --
[%
data = [
["1st","2nd","3rd","4th","5th","6th"],
[ 4, 2, 3, 4, 3, 3.5]
];
USE my_graph = GD.Graph.pie( 250, 200 );
r = my_graph.set(
title => 'A Pie Chart',
label => 'Label',
axislabelclr => 'black',
pie_height => 36,
transparent => 0,
);
my_graph.plot(data).png | head2hex(4, 1);
%]
-- expect --
89504e47
-- test --
[%
data = [
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 5, 12, 24, 33, 19, 8, 6, 15, 21],
[ -1, -2, -5, -6, -3, 1.5, 1, 1.3, 2]
];
USE my_graph = GD.Graph.area();
r = my_graph.set(
two_axes => 1,
zero_axis => 1,
transparent => 0,
);
r = my_graph.set_legend('left axis', 'right axis' );
my_graph.plot(data).png | head2hex(4, 1);
%]
-- expect --
89504e47
-- test --
[%
data = [
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 5, 12, 24, 33, 19, 8, 6, 15, 21],
[ 1, 2, 5, 6, 3, 1.5, 2, 3, 4],
];
USE my_graph = GD.Graph.points();
r = my_graph.set(
x_label => 'X Label',
y_label => 'Y label',
title => 'A Points Graph',
y_max_value => 40,
y_tick_number => 8,
y_label_skip => 2,
legend_placement => 'RC',
long_ticks => 1,
marker_size => 6,
markers => [ 1, 7, 5 ],
transparent => 0,
);
r = my_graph.set_legend('one', 'two');
my_graph.plot(data).png | head2hex(4, 1);
%]
-- expect --
89504e47
-- test --
[%
data = [
["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec", ],
[-5, -4, -3, -3, -1, 0, 2, 1, 3, 4, 6, 7],
[4, 3, 5, 6, 3,1.5, -1, -3, -4, -6, -7, -8],
[1, 2, 2, 3, 4, 3, 1, -1, 0, 2, 3, 2],
];
USE my_graph = GD.Graph.lines();
r = my_graph.set(
x_label => 'Month',
y_label => 'Measure of success',
title => 'A Simple Line Graph',
y_max_value => 8,
y_min_value => -8,
y_tick_number => 16,
y_label_skip => 2,
box_axis => 0,
line_width => 3,
zero_axis_only => 1,
x_label_position => 1,
y_label_position => 1,
x_label_skip => 3,
x_tick_offset => 2,
transparent => 0,
);
r = my_graph.set_legend("Us", "Them", "Others");
my_graph.plot(data).png | head2hex(4, 1);
%]
-- expect --
89504e47
|