Skip to content
Snippets Groups Projects
Commit 85f87421 authored by Daniel Cothran's avatar Daniel Cothran
Browse files

Issue #3449184 by andileco: Fix bubble chart for Google Charts

parent c2672c5b
No related branches found
No related tags found
1 merge request!92Update Google.php
Pipeline #201449 passed with warnings
...@@ -426,9 +426,10 @@ class Google extends ChartBase implements ContainerFactoryPluginInterface { ...@@ -426,9 +426,10 @@ class Google extends ChartBase implements ContainerFactoryPluginInterface {
} }
elseif ($chart_type['id'] === 'bubble') { elseif ($chart_type['id'] === 'bubble') {
$chart_definition['data'][] = [ $chart_definition['data'][] = [
0 => $data_value[0], 0 => $element[$key]['#title'],
$series_number + 1 => $data_value[1], 1 => $data_value[0],
$series_number + 2 => $data_value[2], $series_number + 2 => $data_value[1],
$series_number + 3 => $data_value[2],
]; ];
} }
else { else {
...@@ -485,7 +486,7 @@ class Google extends ChartBase implements ContainerFactoryPluginInterface { ...@@ -485,7 +486,7 @@ class Google extends ChartBase implements ContainerFactoryPluginInterface {
// Convert to a ComboChart if mixing types. // Convert to a ComboChart if mixing types.
// See https://developers.google.com/chart/interactive/docs/gallery/combochart?hl=en. // See https://developers.google.com/chart/interactive/docs/gallery/combochart?hl=en.
if ($element[$key]['#chart_type']) { if ($element[$key]['#chart_type'] && !in_array($element[$key]['#chart_type'], ['bubble', 'scatter'])) {
// Oddly Google calls a "column" chart a "bars" series. // Oddly Google calls a "column" chart a "bars" series.
// Using actual bar. // Using actual bar.
// charts is not supported in combo charts with Google. // charts is not supported in combo charts with Google.
...@@ -547,29 +548,36 @@ class Google extends ChartBase implements ContainerFactoryPluginInterface { ...@@ -547,29 +548,36 @@ class Google extends ChartBase implements ContainerFactoryPluginInterface {
// Once complete, normalize the chart data to ensure a full 2D structure. // Once complete, normalize the chart data to ensure a full 2D structure.
$data = $chart_definition['data']; $data = $chart_definition['data'];
// Stub out corner value. if (in_array($element['#chart_type'], ['pie', 'donut', 'scatter'])) {
if (in_array($element['#chart_type'], ['pie', 'donut'])) {
// Populate the 0th row with the same number of values as the 1st row. // Populate the 0th row with the same number of values as the 1st row.
$data[0] = array_fill(0, count($data[1]), ''); $data[0] = array_fill(0, count($data[1]), $element[$key]['#title'] ?? '');
} }
$data[0][0] = $data[0][0] ?? 'x'; elseif ($element['#chart_type'] === 'bubble') {
if ($element['#chart_type'] === 'bubble') { $data[0] = [
$data[0][2] = 'bubble'; $element[$key]['#title'] ?? '',
$chart_definition['options']['hAxis']['title'] ?? '',
$chart_definition['options']['vAxes'][0]['title'] ?? '',
$chart_definition['options']['zAxis']['title'] ?? '',
];
}
else {
array_unshift($data[0], '');
} }
// Ensure consistent column count. // Ensure consistent column count.
$column_count = count($data[0]); $column_count = count($data[0]);
$new_data = [];
foreach ($data as $row => $values) { foreach ($data as $row => $values) {
for ($n = 0; $n < $column_count; $n++) { for ($n = 0; $n < $column_count; $n++) {
$data[$row][$n] = $data[$row][$n] ?? NULL; if (!empty(array_values($values))) {
$temp = array_values($values);
$new_data[$row][$n] = $temp[$n] ?? NULL;
}
} }
ksort($data[$row]); ksort($new_data[$row]);
} }
ksort($data); ksort($new_data);
$chart_definition['data'] = $data; $chart_definition['data'] = $new_data;
return $chart_definition; return $chart_definition;
} }
......
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