You are here

protected function Chartjs::buildLegend 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::buildLegend()

Builds legend based on element properties.

Parameters

array $element: The element.

Return value

array The legend array.

1 call to Chartjs::buildLegend()
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 374

Class

Chartjs
Define a concrete class for a Chart.

Namespace

Drupal\charts_chartjs\Plugin\chart\Library

Code

protected function buildLegend(array $element) {
  $legend = [];

  // Configure the legend display.
  $legend['display'] = (bool) $element['#legend'];

  // Configure legend position.
  if (!empty($element['#legend_position'])) {
    $legend['position'] = $element['#legend_position'];
    if (!empty($element['#legend_font_weight'])) {
      $legend['labels']['font']['weight'] = $element['#legend_font_weight'];
    }
    if (!empty($element['#legend_font_style'])) {
      $legend['labels']['font']['style'] = $element['#legend_font_style'];
    }
    if (!empty($element['#legend_font_size'])) {
      $legend['labels']['font']['size'] = $element['#legend_font_size'];
    }
  }
  return $legend;
}