From: <var...@us...> - 2009-02-20 13:51:03
|
Revision: 6519 http://phpwiki.svn.sourceforge.net/phpwiki/?rev=6519&view=rev Author: vargenau Date: 2009-02-20 13:50:58 +0000 (Fri, 20 Feb 2009) Log Message: ----------- Handle correctly negative values in charts Modified Paths: -------------- trunk/lib/plugin/Chart.php Modified: trunk/lib/plugin/Chart.php =================================================================== --- trunk/lib/plugin/Chart.php 2009-02-20 13:10:56 UTC (rev 6518) +++ trunk/lib/plugin/Chart.php 2009-02-20 13:50:58 UTC (rev 6519) @@ -87,17 +87,24 @@ // x_min = 0 // x_max = number of elements in data - // y_min = 0 + // y_min = 0 or smallest element in data if negative // y_max = biggest element in data - $x_max = sizeof($values); + $x_max = sizeof($values) + 1; + $y_min = min($values); + if ($y_min > 0) { + $y_min = 0; + } $y_max = max($values); + // sum is used for the pie only, so we ignore negative values $sum = 0; foreach ($values as $value) { - $sum += $value; + if ($value > 0) { + $sum += $value; + } } - $source = 'initPicture(0,'.$x_max.',0,'.$y_max.'); axes(); stroke = "'.$color.'"; strokewidth = 5;'; + $source = 'initPicture(0,'.$x_max.','.$y_min.','.$y_max.'); axes(); stroke = "'.$color.'"; strokewidth = 5;'; if ($type == "bar") { $abscisse = 1; @@ -126,8 +133,10 @@ . 'point = [1, 0]; line(center, point);'; $angle = 0; foreach ($values as $value) { - $angle += $value/$sum; - $source .= 'point = [cos(2*pi*'.$angle.'), sin(2*pi*'.$angle.')]; line(center, point);'; + if ($value > 0) { + $angle += $value/$sum; + $source .= 'point = [cos(2*pi*'.$angle.'), sin(2*pi*'.$angle.')]; line(center, point);'; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |