private function Billboard::populateAxes in Charts 5.0.x
Same name and namespace in other branches
- 8.4 modules/charts_billboard/src/Plugin/chart/Library/Billboard.php \Drupal\charts_billboard\Plugin\chart\Library\Billboard::populateAxes()
Populate axes.
Parameters
array $element: The element.
array $chart_definition: The chart definition.
Return value
array Return the chart definition.
1 call to Billboard::populateAxes()
- Billboard::preRender in modules/
charts_billboard/ src/ Plugin/ chart/ Library/ Billboard.php - Pre render.
File
- modules/
charts_billboard/ src/ Plugin/ chart/ Library/ Billboard.php, line 206
Class
- Billboard
- Define a concrete class for a Chart.
Namespace
Drupal\charts_billboard\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';
});
$chart_type = $this
->getType($element['#chart_type'], $element['#polar']);
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 = $element[$key]['#labels'] ? array_map('strip_tags', $element[$key]['#labels']) : [];
if (!in_array($chart_type, [
'pie',
'donut',
])) {
if ($chart_type === 'scatter') {
//
}
else {
$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;
}
}
}
else {
$chart_definition['data']['columns'] = array_map(NULL, $categories, $chart_definition['data']['columns']);
}
}
}
}
return $chart_definition;
}