Skip to content
Snippets Groups Projects
Commit ec406805 authored by andileco's avatar andileco
Browse files

Removes unused inc files from the sub-modules.

parent bd1e43b0
No related branches found
No related tags found
No related merge requests found
<?php
/**
* @file
* Callbacks and utility functions for rendering a Google Chart.
*/
/**
* Chart render callback; Convert all chart-level data.
*
* This essentially is an additional #pre_render callback. It operates in the
* same way and is simply called as part of the normal #pre_render process.
*
* @param array $chart
* The chart renderable.
*
* @return
* The modified chart renderable, with necessary #attached, #theme, and
* similar properties prepared for rendering.
*/
function _charts_google_render($chart) {
// Convert the chart renderable to a proper definition.
$chart_definition['visualization'] = _charts_google_visualization_type($chart['#chart_type']);
$chart_definition = _charts_google_populate_chart_options($chart, $chart_definition);
$chart_definition = _charts_google_populate_chart_axes($chart, $chart_definition);
$chart_definition = _charts_google_populate_chart_data($chart, $chart_definition);
if (!isset($chart['#id'])) {
$chart['#id'] = drupal_html_id('google-chart-render');
}
// Trim out empty options.
charts_trim_array($chart_definition['options']);
$chart['#attached']['library'][] = ['charts_google', 'charts_google'];
$chart['#attributes']['class'][] = 'charts-google';
$chart['#chart_definition'] = $chart_definition;
return $chart;
}
/**
* Utility to convert a Drupal renderable type to a Google visualization type.
*/
function _charts_google_visualization_type($renderable_type) {
$types = [
'area' => 'AreaChart',
'bar' => 'BarChart',
'column' => 'ColumnChart',
'line' => 'LineChart',
'pie' => 'PieChart',
'scatter' => 'ScatterChart',
];
drupal_alter('charts_google_visualization_types', $types);
return isset($types[$renderable_type]) ? $types[$renderable_type] : FALSE;
}
/**
* Utility to populate main chart options.
*/
function _charts_google_populate_chart_options($chart, $chart_definition) {
$chart_definition['options']['title'] = $chart['#title'] ? $chart['#title'] : NULL;
$chart_definition['options']['titleTextStyle']['color'] = $chart['#title_color'];
$chart_definition['options']['titleTextStyle']['bold'] = $chart['#title_font_weight'] === 'bold' ? TRUE : FALSE;
$chart_definition['options']['titleTextStyle']['italic'] = $chart['#title_font_style'] === 'italic' ? TRUE : FALSE;
$chart_definition['options']['titleTextStyle']['fontSize'] = $chart['#title_font_size'];
$chart_definition['options']['titlePosition'] = $chart['#title_position'];
$chart_definition['options']['colors'] = $chart['#colors'];
$chart_definition['options']['fontName'] = $chart['#font'];
$chart_definition['options']['fontSize'] = $chart['#font_size'];
$chart_definition['options']['backgroundColor']['fill'] = $chart['#background'];
$chart_definition['options']['isStacked'] = $chart['#stacking'] ? TRUE : FALSE;
$chart_definition['options']['tooltip']['trigger'] = $chart['#tooltips'] ? 'focus' : 'none';
$chart_definition['options']['tooltip']['isHtml'] = $chart['#tooltips_use_html'] ? TRUE : FALSE;
$chart_definition['options']['pieSliceText'] = $chart['#data_labels'] ? NULL : 'none';
$chart_definition['options']['legend']['position'] = $chart['#legend_position'] ? $chart['#legend_position'] : 'none';
$chart_definition['options']['legend']['alignment'] = 'center';
$chart_definition['options']['interpolateNulls'] = TRUE;
// TODO: Legend title (and thus these properties) not supported by Google.
$chart_definition['options']['legend']['title'] = $chart['#legend_title'];
$chart_definition['options']['legend']['titleTextStyle']['bold'] = $chart['#legend_title_font_weight'] === 'bold' ? TRUE : FALSE;
$chart_definition['options']['legend']['titleTextStyle']['italic'] = $chart['#legend_title_font_style'] === 'italic' ? TRUE : FALSE;
$chart_definition['options']['legend']['titleTextStyle']['fontSize'] = $chart['#legend_title_font_size'];
$chart_definition['options']['legend']['textStyle']['bold'] = $chart['#legend_font_weight'] === 'bold' ? TRUE : FALSE;
$chart_definition['options']['legend']['textStyle']['italic'] = $chart['#legend_font_style'] === 'italic' ? TRUE : FALSE;
$chart_definition['options']['legend']['textStyle']['fontSize'] = $chart['#legend_font_size'];
$chart_definition['options']['width'] = $chart['#width'] ? $chart['#width'] : NULL;
$chart_definition['options']['height'] = $chart['#height'] ? $chart['#height'] : NULL;
$chart_definition['options']['animation']['duration'] = 10000;
$chart_definition['options']['animation']['easing'] = 'out';
return $chart_definition;
}
/**
* Utility to populate chart axes.
*/
function _charts_google_populate_chart_axes($chart, $chart_definition) {
foreach (element_children($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] += element_info($chart[$key]['#type']);
}
// Populate the chart data.
$axis = [];
$axis['title'] = $chart[$key]['#title'] ? $chart[$key]['#title'] : '';
$axis['titleTextStyle']['color'] = $chart[$key]['#title_color'];
$axis['titleTextStyle']['bold'] = $chart[$key]['#title_font_weight'] === 'bold' ? TRUE : FALSE;
$axis['titleTextStyle']['italic'] = $chart[$key]['#title_font_style'] === 'italic' ? TRUE : FALSE;
$axis['titleTextStyle']['fontSize'] = $chart[$key]['#title_font_size'];
// In Google, the row column of data is used as labels.
if ($chart[$key]['#labels'] && $chart[$key]['#type'] === 'chart_xaxis') {
foreach ($chart[$key]['#labels'] as $label_key => $label) {
$chart_definition['data'][$label_key + 1][0] = $label;
}
}
$axis['textStyle']['color'] = $chart[$key]['#labels_color'];
$axis['textStyle']['bold'] = $chart[$key]['#labels_font_weight'] === 'bold' ? TRUE : FALSE;
$axis['textStyle']['italic'] = $chart[$key]['#labels_font_style'] === 'italic' ? TRUE : FALSE;
$axis['textStyle']['fontSize'] = $chart[$key]['#labels_font_size'];
$axis['slantedText'] = !empty($chart[$key]['#labels_rotation']) ? TRUE : NULL;
$axis['slantedTextAngle'] = $chart[$key]['#labels_rotation'];
$axis['gridlines']['color'] = $chart[$key]['#grid_line_color'];
$axis['baselineColor'] = $chart[$key]['#base_line_color'];
$axis['minorGridlines']['color'] = $chart[$key]['#minor_grid_line_color'];
$axis['viewWindowMode'] = isset($chart[$key]['#max']) ? 'explicit' : NULL;
$axis['viewWindow']['max'] = strlen($chart[$key]['#max']) ? (int)$chart[$key]['#max'] : NULL;
$axis['viewWindow']['min'] = strlen($chart[$key]['#min']) ? (int)$chart[$key]['#min'] : NULL;
// Multi-axis support only applies to the major axis in Google charts.
$chart_type_info = charts_get_type($chart['#chart_type']);
$axis_index = $chart[$key]['#opposite'] ? 1 : 0;
if ($chart[$key]['#type'] === 'chart_xaxis') {
$axis_keys = !$chart_type_info['axis_inverted'] ? ['hAxis'] : [
'vAxes',
$axis_index,
];
} else {
$axis_keys = !$chart_type_info['axis_inverted'] ? [
'vAxes',
$axis_index,
] : ['hAxis'];
}
$axis_drilldown = &$chart_definition['options'];
foreach ($axis_keys as $key) {
$axis_drilldown = &$axis_drilldown[$key];
}
$axis_drilldown = $axis;
}
}
return $chart_definition;
}
/**
* Utility to populate chart data.
*/
function _charts_google_populate_chart_data(&$chart, $chart_definition) {
$chart_definition['options']['series'] = [];
$chart_type_info = charts_get_type($chart['#chart_type']);
$series_number = 0;
foreach (element_children($chart) as $key) {
if ($chart[$key]['#type'] === 'chart_data') {
$series = [];
// Make sure defaults are loaded.
if (empty($chart[$key]['#defaults_loaded'])) {
$chart[$key] += element_info($chart[$key]['#type']);
}
// Convert target named axis keys to integers.
$axis_index = 0;
if (isset($chart[$key]['#target_axis'])) {
$axis_name = $chart[$key]['#target_axis'];
foreach (element_children($chart) as $axis_key) {
$multi_axis_type = $chart_type_info['axis_inverted'] ? 'chart_xaxis' : 'chart_yaxis';
if ($chart[$axis_key]['#type'] === $multi_axis_type) {
if ($axis_key === $axis_name) {
break;
}
$axis_index++;
}
}
$series['targetAxisIndex'] = $axis_index;
}
// Allow data to provide the labels. This will override the axis settings.
if ($chart[$key]['#labels']) {
foreach ($chart[$key]['#labels'] as $label_index => $label) {
$chart_definition['data'][$label_index + 1][0] = $label;
}
}
if ($chart[$key]['#title']) {
$chart_definition['data'][0][$series_number + 1] = $chart[$key]['#title'];
}
foreach ($chart[$key]['#data'] as $index => $data_value) {
// Nested array values typically used for scatter charts. This weird
// approach leaves columns empty in order to make arbitrary pairings.
// See https://developers.google.com/chart/interactive/docs/gallery/scatterchart#Data_Format
if (is_array($data_value)) {
$chart_definition['data'][] = [
0 => $data_value[0],
$series_number + 1 => $data_value[1],
];
} // Most charts provide a single-dimension array of values.
else {
$chart_definition['data'][$index + 1][$series_number + 1] = $data_value;
}
}
$series['color'] = $chart[$key]['#color'];
$series['pointSize'] = $chart[$key]['#marker_radius'];
$series['visibleInLegend'] = $chart[$key]['#show_in_legend'];
// Labels only supported on pies.
$series['pieSliceText'] = $chart[$key]['#show_labels'] ? 'label' : 'none';
// These properties are not real Google Charts properties. They are
// utilized by the formatter in charts_google.js.
$decimal_count = $chart[$key]['#decimal_count'] ? '.' . str_repeat('0', $chart[$key]['#decimal_count']) : '';
$prefix = _charts_google_escape_icu_characters($chart[$key]['#prefix']);
$suffix = _charts_google_escape_icu_characters($chart[$key]['#suffix']);
$format = $prefix . '#' . $decimal_count . $suffix;
$series['_format']['format'] = $format;
// TODO: Convert this from PHP's date format to ICU format.
// See https://developers.google.com/chart/interactive/docs/reference#dateformatter.
//$series['_format']['dateFormat'] = $chart[$key]['#date_format'];
// Conveniently only the axis that supports multiple axes is the one that
// can receive formatting, so we know that the key will always be plural.
$axis_type = $chart_type_info['axis_inverted'] ? 'hAxes' : 'vAxes';
$chart_definition['options'][$axis_type][$axis_index]['format'] = $format;
// Convert to a ComboChart if mixing types.
// See https://developers.google.com/chart/interactive/docs/gallery/combochart?hl=en.
if ($chart[$key]['#chart_type']) {
// Oddly Google calls a "column" chart a "bars" series. Using actual bar
// charts is not supported in combo charts with Google.
$main_chart_type = $chart['#chart_type'] === 'column' ? 'bars' : $chart['#chart_type'];
$chart_definition['visualization'] = 'ComboChart';
$chart_definition['options']['seriesType'] = $main_chart_type;
$data_chart_type = $chart[$key]['#chart_type'] === 'column' ? 'bars' : $chart[$key]['#chart_type'];
$series['type'] = $data_chart_type;
}
// Add the series to the main chart definition.
charts_trim_array($series);
$chart_definition['options']['series'][$series_number] = $series;
// Merge in any point-specific data points.
foreach (element_children($chart[$key]) as $sub_key) {
if ($chart[$key][$sub_key]['#type'] === 'chart_data_item') {
// Make sure defaults are loaded.
if (empty($chart[$key][$sub_key]['#defaults_loaded'])) {
$chart[$key][$sub_key] += element_info($chart[$key][$sub_key]['#type']);
}
$data_item = $chart[$key][$sub_key];
if ($data_item['#data']) {
$chart_definition['data'][$sub_key + 1][$series_number + 1] = $data_item['#data'];
}
// These data properties are manually applied to cells in JS.
// Color role not yet supported. See https://code.google.com/p/google-visualization-api-issues/issues/detail?id=1267
$chart_definition['_data'][$sub_key + 1][$series_number + 1]['color'] = $data_item['#color'];
$chart_definition['_data'][$sub_key + 1][$series_number + 1]['tooltip'] = $data_item['#title'];
charts_trim_array($chart_definition['_data'][$sub_key + 1][$series_number + 1]);
}
}
$series_number++;
}
}
// Once complete, normalize the chart data to ensure a full 2D structure.
$data = $chart_definition['data'];
// Stub out corner value.
$data[0][0] = isset($data[0][0]) ? $data[0][0] : 'x';
// Ensure consistent column count.
$column_count = count($data[0]);
foreach ($data as $row => $values) {
for ($n = 0; $n < $column_count; $n++) {
$data[$row][$n] = isset($data[$row][$n]) ? $data[$row][$n] : NULL;
}
ksort($data[$row]);
}
ksort($data);
$chart_definition['data'] = $data;
return $chart_definition;
}
/**
* Utility to escape special characters in ICU number formats.
*
* Google will use the ICU format to auto-adjust numbers based on special
* characters that are used in the format. This function escapes these special
* characters so they just show up as the character specified.
*
* The format string is a subset of the ICU pattern set. For instance,
* {pattern:'#,###%'} will result in output values "1,000%", "750%", and "50%"
* for values 10, 7.5, and 0.5.
*/
function _charts_google_escape_icu_characters($string) {
return preg_replace('/([0-9@#\.\-,E\+;%\'\*])/', "'$1'", $string);
}
<?php
/**
* @file
* Callbacks and utility functions for rendering a Highcharts Chart.
*/
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
/**
* Chart render callback; Convert all chart-level data.
*
* This essentially is an additional #pre_render callback. It operates in the
* same way and is simply called as part of the normal #pre_render process.
*
* @param array $chart
* The chart renderable.
* @return array The modified chart renderable, with necessary #attached, #theme, and
* The modified chart renderable, with necessary #attached, #theme, and
* similar properties prepared for rendering.
*/
function _charts_highcharts_render($chart) {
// Populate chart settings.
$chart_definition = [];
$chart_definition = _charts_highcharts_populate_chart_options($chart, $chart_definition);
$chart_definition = _charts_highcharts_populate_chart_axes($chart, $chart_definition);
$chart_definition = _charts_highcharts_populate_chart_data($chart, $chart_definition);
// Remove machine names from series. Highcharts series must be an array.
$series = array_values($chart_definition['series']);
unset($chart_definition['series']);
// Trim out empty options (excluding "series" for efficiency).
charts_trim_array($chart_definition);
// Put back the data.
$chart_definition['series'] = $series;
if (!isset($chart['#id'])) {
$chart['#id'] = Html::getUniqueId('highchart-render');
}
$chart['#attached']['library'][] = [
'charts_highcharts',
'charts_highcharts'
];
$chart['#attributes']['class'][] = 'charts-highchart';
$chart['#chart_definition'] = $chart_definition;
return $chart;
}
/**
* Utility to convert a Drupal renderable type to a Google visualization type.
*
* @param $renderable_type
*
* @return bool|mixed
*/
function _charts_highcharts_type($renderable_type) {
$types = [
'area_chart' => 'AreaChart',
'bar_chart' => 'BarChart',
'column_chart' => 'ColumnChart',
'line_chart' => 'LineChart',
'pie_chart' => 'PieChart',
'scatter_chart' => 'ScatterChart',
];
Drupal::moduleHandler()->alter('charts_highcharts_types', $types);
return isset($types[$renderable_type]) ? $types[$renderable_type] : FALSE;
}
/**
* Utility to populate main chart options.
* @param $chart
* @param $chart_definition
* @return mixed
*/
function _charts_highcharts_populate_chart_options($chart, $chart_definition) {
$chart_definition['chart']['type'] = $chart['#chart_type'];
$chart_definition['title']['text'] = $chart['#title'] ? $chart['#title'] : '';
$chart_definition['title']['style']['color'] = $chart['#title_color'];
$chart_definition['title']['style']['fontWeight'] = $chart['#title_font_weight'];
$chart_definition['title']['style']['fontStyle'] = $chart['#title_font_style'];
$chart_definition['title']['style']['fontSize'] = $chart['#title_font_size'];
$chart_definition['title']['verticalAlign'] = $chart['#title_position'] === 'in' ? 'top' : NULL;
$chart_definition['title']['y'] = $chart['#title_position'] === 'in' ? 24 : NULL;
$chart_definition['colors'] = $chart['#colors'];
$chart_definition['chart']['style']['fontFamily'] = $chart['#font'];
$chart_definition['chart']['style']['fontSize'] = $chart['#font_size'];
$chart_definition['chart']['backgroundColor'] = $chart['#background'];
$chart_definition['plotOptions']['series']['stacking'] = !is_string($chart['#stacking']) && $chart['#stacking'] ? 'normal' : $chart['#stacking'];
$chart_definition['tooltip']['enabled'] = $chart['#tooltips'] ? TRUE : FALSE;
$chart_definition['tooltip']['useHTML'] = $chart['#tooltips_use_html'] ? TRUE : FALSE;
$chart_definition['plotOptions']['series']['dataLabels']['enabled'] = $chart['#data_labels'] ? TRUE : FALSE;
// These changes are for consistency with Google. Perhaps too specific?
if ($chart['#chart_type'] === 'pie') {
$chart_definition['plotOptions']['pie']['dataLabels']['distance'] = -30;
$chart_definition['plotOptions']['pie']['dataLabels']['color'] = 'white';
$chart_definition['plotOptions']['pie']['dataLabels']['format'] = '{percentage:.1f}%';
$chart_definition['tooltip']['pointFormat'] = '<b>{point.y} ({point.percentage:.1f}%)</b><br/>';
}
$chart_definition['legend']['enabled'] = $chart['#legend'];
$chart_definition['legend']['title']['text'] = $chart['#legend_title'];
$chart_definition['legend']['title']['style']['fontWeight'] = $chart['#legend_title_font_weight'];
$chart_definition['legend']['title']['style']['fontStyle'] = $chart['#legend_title_font_style'];
$chart_definition['legend']['title']['style']['fontSize'] = $chart['#legend_title_font_size'];
if ($chart['#legend_position'] === 'bottom') {
$chart_definition['legend']['verticalAlign'] = 'bottom';
$chart_definition['legend']['layout'] = 'horizontal';
} elseif ($chart['#legend_position'] === 'top') {
$chart_definition['legend']['verticalAlign'] = 'top';
$chart_definition['legend']['layout'] = 'horizontal';
} else {
$chart_definition['legend']['align'] = $chart['#legend_position'];
$chart_definition['legend']['verticalAlign'] = 'middle';
$chart_definition['legend']['layout'] = 'vertical';
}
$chart_definition['legend']['itemStyle']['fontWeight'] = $chart['#legend_font_weight'];
$chart_definition['legend']['itemStyle']['fontStyle'] = $chart['#legend_font_style'];
$chart_definition['legend']['itemStyle']['fontSize'] = $chart['#legend_font_size'];
$chart_definition['chart']['width'] = $chart['#width'] ? $chart['#width'] : NULL;
$chart_definition['chart']['height'] = $chart['#height'] ? $chart['#height'] : NULL;
$chart_definition['credits']['enabled'] = FALSE;
// Merge in chart raw options.
if (isset($chart['#raw_options'])) {
$chart_definition = NestedArray::mergeDeep($chart_definition, $chart['#raw_options']);
}
return $chart_definition;
}
/**
* Utility to populate chart axes.
* @param $chart
* @param $chart_definition
* @return mixed
*/
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 = [];
$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;
}
/**
* Utility to populate chart data.
* @param $chart
* @param $chart_definition
* @return mixed
*/
function _charts_highcharts_populate_chart_data(&$chart, $chart_definition) {
$chart_definition['series'] = [];
foreach (\Drupal::state()->getMultiple($chart) as $key) {
if ($chart[$key]['#type'] === 'chart_data') {
$series = [];
$series_data = [];
// Make sure defaults are loaded.
if (empty($chart[$key]['#defaults_loaded'])) {
$chart[$key] += \Drupal::service('element_info')
->getInfo($chart[$key]['#type']);
}
// Convert target named axis keys to integers.
if (isset($chart[$key]['#target_axis'])) {
$axis_name = $chart[$key]['#target_axis'];
$axis_index = 0;
foreach (\Drupal::state()->getMultiple($chart) as $axis_key) {
if ($chart[$axis_key]['#type'] === 'chart_yaxis') {
if ($axis_key === $axis_name) {
break;
}
$axis_index++;
}
}
$series['yAxis'] = $axis_index;
}
// Allow data to provide the labels. This will override the axis settings.
if ($chart[$key]['#labels']) {
foreach ($chart[$key]['#labels'] as $label_index => $label) {
$series_data[$label_index][0] = $label;
}
}
// Populate the data.
foreach ($chart[$key]['#data'] as $data_index => $data) {
if (isset($series_data[$data_index])) {
$series_data[$data_index][] = $data;
} else {
$series_data[$data_index] = $data;
}
}
$series['type'] = $chart[$key]['#chart_type'];
$series['name'] = $chart[$key]['#title'];
$series['color'] = $chart[$key]['#color'];
$series['marker']['radius'] = $chart[$key]['#marker_radius'];
$series['showInLegend'] = $chart[$key]['#show_in_legend'];
$series['connectNulls'] = TRUE;
$series['tooltip']['valueDecimals'] = $chart[$key]['#decimal_count'];
$series['tooltip']['xDateFormat'] = $chart[$key]['#date_format'];
$series['tooltip']['valuePrefix'] = $chart[$key]['#prefix'];
$series['tooltip']['valueSuffix'] = $chart[$key]['#suffix'];
if ($chart[$key]['#prefix'] || $chart[$key]['#suffix']) {
$yaxis_index = isset($series['yAxis']) ? $series['yAxis'] : 0;
// For axis formatting, we need to use a format string.
// See http://docs.highcharts.com/#formatting.
$decimal_formatting = $chart[$key]['#decimal_count'] ? (':.' . $chart[$key]['#decimal_count'] . 'f') : '';
$chart_definition['yAxis'][$yaxis_index]['labels']['format'] = $chart[$key]['#prefix'] . "{value$decimal_formatting}" . $chart[$key]['#suffix'];
}
// Remove unnecessary keys to trim down the resulting JS settings.
charts_trim_array($series);
$series['data'] = $series_data;
// Merge in series raw options.
if (isset($chart[$key]['#raw_options'])) {
$series = NestedArray::mergeDeep($series, $chart[$key]['#raw_options']);
}
// Add the series to the main chart definition.
$chart_definition['series'][$key] = $series;
// Merge in any point-specific data points.
foreach (\Drupal::state()->getMultiple($chart[$key]) as $sub_key) {
if ($chart[$key][$sub_key]['#type'] === 'chart_data_item') {
// Make sure defaults are loaded.
if (empty($chart[$key][$sub_key]['#defaults_loaded'])) {
$chart[$key][$sub_key] += \Drupal::service('element_info')
->getInfo($chart[$key][$sub_key]['#type']);
}
$data_item = $chart[$key][$sub_key];
$series_point = &$chart_definition['series'][$key]['data'][$sub_key];
// Convert the point from a simple data value to a complex point.
if (!isset($series_point['data'])) {
$data = $series_point;
$series_point = [];
if (is_array($data)) {
$series_point['name'] = $data[0];
$series_point['y'] = $data[1];
} else {
$series_point['y'] = $data;
}
}
if (isset($data_item['#data'])) {
if (is_array($data_item['#data'])) {
$series_point['x'] = $data_item['#data'][0];
$series_point['y'] = $data_item['#data'][1];
} else {
$series_point['y'] = $data_item['#data'];
}
}
if ($data_item['#title']) {
$series_point['name'] = $data_item['#title'];
}
// Setting the color requires several properties for consistency.
$series_point['color'] = $data_item['#color'];
$series_point['fillColor'] = $data_item['#color'];
$series_point['states']['hover']['fillColor'] = $data_item['#color'];
$series_point['states']['select']['fillColor'] = $data_item['#color'];
charts_trim_array($series_point);
// Merge in point raw options.
if (isset($data_item['#raw_options'])) {
$series_point = NestedArray::mergeDeep($series_point, $data_item['#raw_options']);
}
}
}
}
}
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