function _charts_highcharts_populate_chart_axes in Charts 8
Same name and namespace in other branches
- 7.2 modules/charts_highcharts/charts_highcharts.inc \_charts_highcharts_populate_chart_axes()
Utility to populate chart axes.
_definition
Parameters
$chart:
Return value
mixed
1 call to _charts_highcharts_populate_chart_axes()
- _charts_highcharts_render in modules/
charts_highcharts/ charts_highcharts.inc - Chart render callback; Convert all chart-level data.
File
- modules/
charts_highcharts/ charts_highcharts.inc, line 146 - Callbacks and utility functions for rendering a Highcharts Chart.
Code
function _charts_highcharts_populate_chart_axes($chart, $chart_definition) {
foreach (\Drupal::state()
->getMultiple($chart) as $key) {
if ($chart[$key]['#type'] === 'chart_xaxis' || $chart[$key]['#type'] === 'chart_yaxis') {
// Make sure defaults are loaded.
if (empty($chart[$key]['#defaults_loaded'])) {
$chart[$key] += \Drupal::service('element_info')
->getInfo($chart[$key]['#type']);
}
// Populate the chart data.
$axisType = $chart[$key]['#type'] === 'chart_xaxis' ? 'xAxis' : 'yAxis';
$axis = array();
$axis['type'] = $chart[$key]['#axis_type'];
$axis['title']['text'] = $chart[$key]['#title'];
$axis['title']['style']['color'] = $chart[$key]['#title_color'];
$axis['title']['style']['fontWeight'] = $chart[$key]['#title_font_weight'];
$axis['title']['style']['fontStyle'] = $chart[$key]['#title_font_style'];
$axis['title']['style']['fontSize'] = $chart[$key]['#title_font_size'];
$axis['categories'] = $chart[$key]['#labels'];
$axis['labels']['style']['color'] = $chart[$key]['#labels_color'];
$axis['labels']['style']['fontWeight'] = $chart[$key]['#labels_font_weight'];
$axis['labels']['style']['fontStyle'] = $chart[$key]['#labels_font_style'];
$axis['labels']['style']['fontSize'] = $chart[$key]['#labels_font_size'];
$axis['labels']['rotation'] = $chart[$key]['#labels_rotation'];
$axis['gridLineColor'] = $chart[$key]['#grid_line_color'];
$axis['lineColor'] = $chart[$key]['#base_line_color'];
$axis['minorGridLineColor'] = $chart[$key]['#minor_grid_line_color'];
$axis['endOnTick'] = isset($chart[$key]['#max']) ? FALSE : NULL;
$axis['max'] = $chart[$key]['#max'];
$axis['min'] = $chart[$key]['#min'];
$axis['opposite'] = $chart[$key]['#opposite'];
// Dealing with axis rotation in a reasonable manner is complicated in
// Highcharts. We want the label to be reasonably positioned on the
// outside of the chart when labels are rotated.
if ($axis['labels']['rotation']) {
$chart_type = charts_get_type($chart['#chart_type']);
if ($axisType === 'xAxis' && !$chart_type['axis_inverted']) {
$axis['labels']['align'] = 'left';
}
elseif ($axisType === 'yAxis' && $chart_type['axis_inverted']) {
$axis['labels']['align'] = 'left';
}
else {
// Rotation not allowed on left/right axis.
unset($axis['labels']['rotation']);
}
}
// Merge in axis raw options.
if (isset($chart[$key]['#raw_options'])) {
$axis = NestedArray::mergeDeep($axis, $chart[$key]['#raw_options']);
}
$chart_definition[$axisType][] = $axis;
}
}
return $chart_definition;
}