You are here

private function Billboard::populateAxes in Charts 8.4

Same name and namespace in other branches
  1. 5.0.x 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 190

Class

Billboard
Define a concrete class for a Chart.

Namespace

Drupal\charts_billboard\Plugin\chart\Library

Code

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

  // $series_data = array_filter($children, function ($child) use ($element) {
  // return $element[$child]['#type'] === 'chart_data';
  // });
  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 = $categories = array_map('strip_tags', $element[$key]['#labels']);
        $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;
        }
      }
    }
  }
  return $chart_definition;
}