You are here

function _charts_highcharts_populate_chart_options in Charts 8

Same name and namespace in other branches
  1. 7.2 modules/charts_highcharts/charts_highcharts.inc \_charts_highcharts_populate_chart_options()

Utility to populate main chart options.

_definition

Parameters

$chart:

Return value

mixed

1 call to _charts_highcharts_populate_chart_options()
_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 81
Callbacks and utility functions for rendering a Highcharts Chart.

Code

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;
}