Posted by seutje on October 2, 2009 at 1:52pm
| Project: | Google chart API |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | major |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
concerning function _chart_adjust_resolution($chart_id, &$data, $max_value = NULL)
if $max[$chart_id] is 0, a division by zero error is thrown
attached patch solves this by changing this
<?php
if ($max[$chart_id] > $resoluton){
$divider = round($max[$chart_id] / $resoluton, 1);
}
else {
$multiplier = round($resoluton / $max[$chart_id], 1);
}
?>into this
<?php
if ($max[$chart_id] > $resoluton){
$divider = round($max[$chart_id] / $resoluton, 1);
}
elseif ($max[$chart_id] != 0) {
$multiplier = round($resoluton / $max[$chart_id], 1);
}
?>should apply to HEAD
| Attachment | Size |
|---|---|
| chart-division-by-zero.patch | 554 bytes |
Comments
#1
By the way, I got this error in combination with the google analytics API module, not sure if this is chart API's fault for not catching it, or google analytics API's fault for calling a function with improper values
-> #551146: Division by zero error when viewing a report and bounce rate is zero
#2
from what I can tell, It's a chart problem because it's logically valid to have zero as a max value.
The patch works for me, thanks. However I'll leave it at "needs review" because I'm not entirely sure how this function works, especially with negative ranges, ranges from negative to zero, and other case.
#3
I did:
$max[$chart_id] = max($max[$chart_id], 1);$multiplier = round($resoluton / $max[$chart_id], 1);
#4
It should be:
<?phpif ($max[$chart_id] > $resoluton){
$divider = round($max[$chart_id] / $resoluton, 1);
}
elseif ($max[$chart_id] > 0) {
$multiplier = round($resoluton / $max[$chart_id], 1);
}
?>
Because negative values will also produce errors.
#5
Attaching my patch
#6
Surprised to see 1.3 release not including this
#7
Changes to major as the error message is ugly.
#8
Patch for the new 1.3 release
#9
Patch in #8 applies (with a slight fuzz) and fixes the problem.
#10
Yup. tested, works. plz include in module.
#11
Here's a hotfix patch for 7.x-1.0, in case anyone's in need of that. I did the same as Fleshgrinder in #4.
#12
@ximo: Git reports "fatal: git diff header lacks filename information when removing 1 leading pathname components (line 5)" for your patch. I manually applied the change.
This fix has been committed to 7.x-1.x-dev. May be changed again when #234127: Negative Data values? and #1213796: _chart_adjust_resolution calculation are resolved.
#13
Applied to change in #11 to 6.x-1.x.
#14
Automatically closed -- issue fixed for 2 weeks with no activity.