You are here

protected function Chartjs::buildTitle in Charts 5.0.x

Same name and namespace in other branches
  1. 8.4 modules/charts_chartjs/src/Plugin/chart/Library/Chartjs.php \Drupal\charts_chartjs\Plugin\chart\Library\Chartjs::buildTitle()

Builds title based on element properties.

Parameters

array $element: The element.

Return value

array The title array.

1 call to Chartjs::buildTitle()
Chartjs::populateOptions in modules/charts_chartjs/src/Plugin/chart/Library/Chartjs.php
Populate options.

File

modules/charts_chartjs/src/Plugin/chart/Library/Chartjs.php, line 405

Class

Chartjs
Define a concrete class for a Chart.

Namespace

Drupal\charts_chartjs\Plugin\chart\Library

Code

protected function buildTitle(array $element) {
  $title = [];
  if (!empty($element['#title'])) {
    $title = [
      'display' => TRUE,
      'text' => $element['#title'],
    ];
    if (!empty($element['#title_position'])) {
      if (in_array($element['#title_position'], [
        'in',
        'out',
      ])) {
        $title['position'] = 'top';
      }
      else {
        $title['position'] = $element['#title_position'];
      }
    }
    if (!empty($element['#title_color'])) {
      $title['color'] = $element['#title_color'];
    }
    if (!empty($element['#title_font_weight'])) {
      $title['font']['weight'] = $element['#title_font_weight'];
    }
    if (!empty($element['#title_font_style'])) {
      $title['font']['style'] = $element['#title_font_style'];
    }
    if (!empty($element['#title_font_size'])) {
      $title['font']['size'] = $element['#title_font_size'];
    }
  }
  return $title;
}