private function C3::populateAxes in Charts 8.4
Same name and namespace in other branches
- 5.0.x modules/charts_c3/src/Plugin/chart/Library/C3.php \Drupal\charts_c3\Plugin\chart\Library\C3::populateAxes()
Populate axes.
Parameters
array $element: The element.
array $chart_definition: The chart definition.
Return value
array Return chart definition.
1 call to C3::populateAxes()
- C3::preRender in modules/
charts_c3/ src/ Plugin/ chart/ Library/ C3.php - Pre render.
File
- modules/
charts_c3/ src/ Plugin/ chart/ Library/ C3.php, line 190
Class
- C3
- Define a concrete class for a Chart.
Namespace
Drupal\charts_c3\Plugin\chart\LibraryCode
private function populateAxes(array $element, array $chart_definition) {
/** @var \Drupal\Core\Render\ElementInfoManagerInterface $element_info */
$element_info = \Drupal::service('element_info');
$children = Element::children($element);
$axes = array_filter($children, function ($child) use ($element) {
$type = $element[$child]['#type'];
return $type === 'chart_xaxis' || $type === 'chart_yaxis';
});
// $series_data = array_filter($children, function ($child) use ($element) {
// return $element[$child]['#type'] === 'chart_data';
// });
if ($axes) {
foreach ($axes as $key) {
// Make sure defaults are loaded.
if (empty($element[$key]['#defaults_loaded'])) {
$element[$key] += $element_info
->getInfo($element[$key]['#type']);
}
$axis_type = $element[$key]['#type'] === 'chart_xaxis' ? 'x' : 'y';
if ($axis_type === 'x') {
$categories = $categories = array_map('strip_tags', $element[$key]['#labels']);
$chart_definition['data']['columns'][] = [
'x',
];
$chart_definition['data']['x'] = 'x';
$categories_keys = array_keys($chart_definition['data']['columns']);
$categories_key = end($categories_keys);
foreach ($categories as $category) {
$chart_definition['data']['columns'][$categories_key][] = $category;
}
}
}
}
return $chart_definition;
}