Skip to content
Snippets Groups Projects
Commit 160184fd authored by Bruno Massa's avatar Bruno Massa
Browse files

Bugs fixed:

* Now data is given in an array with all series.
* $max is calculated inside the function, instead being given as a parameter
parent de0626f6
No related branches found
No related tags found
No related merge requests found
...@@ -16,31 +16,41 @@ ...@@ -16,31 +16,41 @@
* _google_charts_codingextended(), which produces a 4000 levels, * _google_charts_codingextended(), which produces a 4000 levels,
* but also a bigger URL string. * but also a bigger URL string.
* *
* @param $values * @param $data
* Array. A series of numeric data values * Array. A series of numeric data values
* @param $max
* Number. The biggest number to be the reference point
*/ */
function _google_charts_codingsimple($values, $max) { function _google_charts_codingsimple($data) {
// Set the list of characters and the size of the list // Set the list of characters and the size of the list
$simple_encoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $simple = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$strlen = strlen($simple_encoding) - 1; $simple_len = strlen($simple) - 1;
// The final output is going to be build // The final output is going to be build
$chart_data = 's:'; $chart_data = '';
// For each chart value, encode it // For each chart value, encode it
// Note: Underscore represents a missing value // Note: Underscore represents a missing value
foreach ($values as $current_value) { foreach ($data as $series) {
if ($current_value >= 0) { // Include a series separator
$chart_data .= $simple_encoding[(round($strlen * $current_value / $max))]; if (!empty($chart_data)) {
$chart_data .= '|';
} }
else {
$chart_data .= '_'; // Get the highest value on the series, to be a reference point
$max = max($series);
// For each series of data, scan it
foreach ($series as $value) {
if ($value >= 0) {
$chart_data .= $simple[round($simple_len * $value / $max)];
}
else {
$chart_data .= '_';
}
} }
} }
return $chart_data; // Return the series of data
return 's:'. $chart_data;
} }
function _google_charts_codingextended() { function _google_charts_codingextended() {
......
...@@ -78,7 +78,7 @@ function google_charts_chartsapi(&$data) { ...@@ -78,7 +78,7 @@ function google_charts_chartsapi(&$data) {
if (empty($data['data'])) { if (empty($data['data'])) {
return ''; return '';
} }
$options = _google_charts_codingsimple($data['data'], max($data['data'])); $options = _google_charts_codingsimple($data['data']);
$chart[] = 'chd='. $options; $chart[] = 'chd='. $options;
// If its all ok, build the HTML img tag // If its all ok, build the HTML img tag
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment