function _google_chart_tools_apply_grouping_conversion in Google Chart Tools 7
SUM datasets based on grouping value.
1 call to _google_chart_tools_apply_grouping_conversion()
- google_chart_tools_views_plugin_style::render in google_chart_tools_views/
views/ google_chart_tools_views_plugin_style.inc - Render the display in this style.
File
- google_chart_tools_views/
views/ google_chart_tools_views_plugin_style.inc, line 224 - Contains the Google Chart Tools display plugin.
Code
function _google_chart_tools_apply_grouping_conversion(&$header, &$item) {
// establish overlap by header name
$tmp_header = array_flip($header);
foreach ($header as $value) {
$tmp_header[$value] = array();
}
// populate tmp_header with the array key matches of headerr
foreach ($header as $key => $value) {
$tmp_header[$value][] = $key;
}
$tmp_item = array();
// SUM the items into their respective totals
foreach ($item as $item_key => $datapoints) {
$tmp_item[$item_key] = array();
foreach ($tmp_header as $header_key => $header_array) {
$tmp_item[$item_key][$header_key] = NULL;
foreach ($header_array as $datapointkey) {
$tmp_item[$item_key][$header_key] += $item[$item_key][$datapointkey];
}
}
}
// reset the header so we can merge it
$header = array();
foreach ($tmp_header as $header_key => $header_array) {
// quotes ensure that header_key will be a string
$header[] = "{$header_key}";
}
// convert the name aggregates back to generic keys
foreach ($tmp_item as $item_key => $datapoints) {
$tmp_item[$item_key] = array_values($datapoints);
}
// set item to the new datapoints array
$item = $tmp_item;
}