Skip Menu |

This queue is for tickets about the GDGraph CPAN distribution.

Maintainer(s)' notes

There are plenty of good ideas of what people can do published here on the queue. Turning a patch from the tracker into a pull request is not one of them. In order to get maintainers' attention way more quickier, PR should have at least a sample included. We know it's hard to test images generating software, but it doesn't mean we can not test numbers produced by intermediate algorithms used to generate these images, so either a test or a sample.

Report information
The Basics
Id: 2852
Status: resolved
Priority: 0/
Queue: GDGraph

People
Owner: Nobody in particular
Requestors: drew [...] marold.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 1.40
  • 1.41
  • 1.42
Fixed in: (no value)



Subject: Divide by zero error on two axis graph when all data points are zero
This bug is similar to, but different from bug 512. Using GD::Graph 1.40 and also checked against 1.42, perl 5.8.0 under linux. When creating a 2 axis graph, if there is no data, or it's all zeros, you get a divide by zero error in axestype.pm. Line 1705 of axestype.pm rev1.42 has a comment asking if $scale_2 should be checked for zero, which is exactly what causes the problem. I modified the test case code from bug 512 to demonstrate this error: #!/usr/bin/perl use strict; use warnings; use GD::Graph::lines; my($graph, $image, $margin, @data, $filename); $filename = "/tmp/gd_graph_axis_bug.png"; $margin = 5; $graph = GD::Graph::lines::->new(700 ,450); $graph->set( two_axes => 1, y1_label => 'y label', y2_label => 'other y label', y1_min_value => 0, y2_min_value => 0, y2_ticks => 1, y2_plot_values => 1, y_tick_number => 6, x_label => 'x_label', title => 'title', x_label_position => 0, y_label_skip => 2, x_labels_vertical => 1, y_long_ticks => 1, y_number_format => "%i", bar_width => 5, ); @data = ([ 'label1', 'label2' ], [ 0,0 ], [ 0,0 ], ); $image = eval { $graph->plot(\@data); }; if($@ or !defined $image) { die("PLOT FAILED: $@\n"); } print "READY TO WRITE IMAGE: $filename\n"; open(IMG, ">", $filename) or die("Unable to open $filename : $!"); binmode IMG; print IMG $image->png; close IMG;
From: Pug
I am facing the same problem/bug. The file is the same (axestype.pm) but the line number is 1768. It is a division by zero error Regards [guest - Wed Jun 25 13:47:33 2003]: Show quoted text
> This bug is similar to, but different from bug 512. > Using GD::Graph 1.40 and also checked against 1.42, perl 5.8.0 under > linux. > > When creating a 2 axis graph, if there is no data, or it's all zeros, > you get a divide by zero error in axestype.pm. Line 1705 of > axestype.pm rev1.42 has a comment asking if $scale_2 should be > checked for zero, which is exactly what causes the problem. > > I modified the test case code from bug 512 to demonstrate this error: > #!/usr/bin/perl > use strict; > use warnings; > use GD::Graph::lines; > > my($graph, $image, $margin, @data, $filename); > > $filename = "/tmp/gd_graph_axis_bug.png"; > $margin = 5; > $graph = GD::Graph::lines::->new(700 ,450); > > $graph->set( two_axes => 1, > y1_label => 'y label', > y2_label => 'other y label', > y1_min_value => 0, > y2_min_value => 0, > y2_ticks => 1, > y2_plot_values => 1, > y_tick_number => 6, > x_label => 'x_label', > title => 'title', > x_label_position => 0, > y_label_skip => 2, > x_labels_vertical => 1, > y_long_ticks => 1, > y_number_format => "%i", > bar_width => 5, > ); > > > @data = ([ 'label1', 'label2' ], > [ 0,0 ], > [ 0,0 ], > ); > > $image = eval { > $graph->plot(\@data); > }; > if($@ or !defined $image) { > die("PLOT FAILED: $@\n"); > } > > print "READY TO WRITE IMAGE: $filename\n"; > > open(IMG, ">", $filename) or die("Unable to open $filename : $!"); > binmode IMG; > print IMG $image->png; > close IMG;
From: simon [...] tachyon.net
...same problem here. The fix (if you don't want to wait for the next revision of GD::Graph) is to add return ($min, $max, 0) if ($step_size == 0); in the _fit_interval subroutine just before the divide-by-zero error occurs. See diff output below: $ diff -C 8 axestype.pm axestype.pm.orig *** axestype.pm Mon Jun 30 20:51:28 2003 --- axestype.pm.orig Sun Jun 29 06:57:10 2003 *************** *** 1760,1777 **** # Takes $min, $max, $step_count, $step_size. Assumes $min <= $max and both # $step_count and $step_size are positive. Returns the fitted $min, $max, # and a $fit statistic (where smaller is better). Failure to fit the # interval results in a poor fit statistic. :-) sub _fit_interval { my ($min, $max, $step_count, $step_size) = @_; - return ($min, $max, 0) if ($step_size == 0); - my $nice_min = $step_size * int($min/$step_size); $nice_min -= $step_size if ($nice_min > $min); my $nice_max = ($step_count == 1) ? $step_size * int($max/$step_size + 1) : $nice_min + $step_count * $step_size; my $fit = _measure_interval_fit($nice_min, $min, $max, $nice_max); --- 1760,1775 ---- - Simon [guest - Wed Jun 25 13:47:33 2003]: Show quoted text
> This bug is similar to, but different from bug 512. > Using GD::Graph 1.40 and also checked against 1.42, perl 5.8.0 under > linux. > > When creating a 2 axis graph, if there is no data, or it's all zeros, > you get a divide by zero error in axestype.pm. Line 1705 of > axestype.pm rev1.42 has a comment asking if $scale_2 should be > checked for zero, which is exactly what causes the problem. > > I modified the test case code from bug 512 to demonstrate this error: > #!/usr/bin/perl > use strict; > use warnings; > use GD::Graph::lines; > > my($graph, $image, $margin, @data, $filename); > > $filename = "/tmp/gd_graph_axis_bug.png"; > $margin = 5; > $graph = GD::Graph::lines::->new(700 ,450); > > $graph->set( two_axes => 1, > y1_label => 'y label', > y2_label => 'other y label', > y1_min_value => 0, > y2_min_value => 0, > y2_ticks => 1, > y2_plot_values => 1, > y_tick_number => 6, > x_label => 'x_label', > title => 'title', > x_label_position => 0, > y_label_skip => 2, > x_labels_vertical => 1, > y_long_ticks => 1, > y_number_format => "%i", > bar_width => 5, > ); > > > @data = ([ 'label1', 'label2' ], > [ 0,0 ], > [ 0,0 ], > ); > > $image = eval { > $graph->plot(\@data); > }; > if($@ or !defined $image) { > die("PLOT FAILED: $@\n"); > } > > print "READY TO WRITE IMAGE: $filename\n"; > > open(IMG, ">", $filename) or die("Unable to open $filename : $!"); > binmode IMG; > print IMG $image->png; > close IMG;