You are here

private function C3::populateOptions in Charts 8.4

Same name and namespace in other branches
  1. 5.0.x modules/charts_c3/src/Plugin/chart/Library/C3.php \Drupal\charts_c3\Plugin\chart\Library\C3::populateOptions()

Populate options.

Parameters

array $element: The element.

array $chart_definition: The chart definition.

Return value

array Return the chart definition.

1 call to C3::populateOptions()
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 143

Class

C3
Define a concrete class for a Chart.

Namespace

Drupal\charts_c3\Plugin\chart\Library

Code

private function populateOptions(array $element, array $chart_definition) {
  $type = $this
    ->getType($element['#chart_type']);
  $chart_definition['title']['text'] = $element['#title'] ? $element['#title'] : '';
  $chart_definition['legend']['show'] = !empty($element['#legend_position']);
  $chart_definition['axis']['x']['type'] = 'category';
  $chart_definition['data']['labels'] = (bool) $element['#data_labels'];
  if ($type === 'pie' || $type === 'donut') {
  }
  elseif ($type === 'line' || $type === 'spline') {
    $chart_definition['point']['show'] = !empty($element['#data_markers']);
  }
  else {

    /*
     * Billboard does not use bar, so column must be used. Since 'column'
     * is changed
     * to 'bar' in getType(), we need to use the value from the element.
     */
    if ($element['#chart_type'] === 'bar') {
      $chart_definition['axis']['rotated'] = TRUE;
    }
    elseif ($element['#chart_type'] === 'column') {
      $type = 'bar';
      $chart_definition['axis']['rotated'] = FALSE;
    }
  }
  $chart_definition['data']['type'] = $type;

  // Merge in chart raw options.
  if (!empty($element['#raw_options'])) {
    $chart_definition = NestedArray::mergeDeepArray([
      $element['#raw_options'],
      $chart_definition,
    ]);
  }
  return $chart_definition;
}