Using the following program shows a bug in the cumulative numbers shown
on the axis when showing cumulative areas:
use GD::Graph::area;
my @data = (
[ 'a', 'b', 'c' ],
[ 7, 9, 17 ],
[ 10, 14, 8 ],
[ 13, 9, 19 ],
);
my $graph = new GD::Graph::area(580, 300);
$graph->set(
title => "Example chart",
cumulate => 1,
show_values => \@data,
) or die $graph->error;
my $gd = $graph->plot(\@data) or die $graph->error;
open(IMG, '>', "graph$$.gif") or die $!;
binmode IMG;
print IMG $gd->gif;
print "Written graph$$.gif\n";
close IMG;
The two attached graphs show the generated graph before (10371) and
after (10512) the following patch, applied against 1.44:
diff -r -u /tmp/GDGraph-1.44/Graph/axestype.pm
GDGraph-1.44/Graph/axestype.pm
--- /tmp/GDGraph-1.44/Graph/axestype.pm 2007-04-26 04:16:09.000000000 +0100
+++ GDGraph-1.44/Graph/axestype.pm 2007-06-20 14:06:55.942938829 +0100
@@ -1414,6 +1414,8 @@
@others = 1 .. $self->{_data}->num_sets;
}
+ my @cumulated;
+
foreach my $dsn ( @others )
{
my @values = $self->{_data}->y_values($dsn) or
@@ -1425,14 +1427,24 @@
{
next unless defined $display[$i];
my ($xp, $yp);
+
+ my $value = $values[$i];
+ if ($self->{cumulate})
+ {
+ if (defined $cumulated[$i]) {
+ $value += $cumulated[$i];
+ }
+ $cumulated[$i] = $value;
+ }
+
if (defined($self->{x_min_value}) &&
defined($self->{x_max_value}))
{
($xp, $yp) = $self->val_to_pixel(
- $self->{_data}->get_x($i), $values[$i], $dsn);
+ $self->{_data}->get_x($i), $value, $dsn);
}
else
{
- ($xp, $yp) = $self->val_to_pixel($i+1, $values[$i], $dsn);
+ ($xp, $yp) = $self->val_to_pixel($i+1, $value, $dsn);
}
$yp -= $self->{values_space};