You are here

protected function Highcharts::buildPlotOptions in Charts 8.3

Build the plotOptions.

Parameters

array $options: Options.

Return value

\Drupal\charts_highcharts\Settings\Highcharts\PlotOptions PlotOptions.

1 call to Highcharts::buildPlotOptions()
Highcharts::buildVariables in modules/charts_highcharts/src/Plugin/chart/Highcharts.php
Creates a JSON Object formatted for Highcharts JavaScript to use.

File

modules/charts_highcharts/src/Plugin/chart/Highcharts.php, line 117

Class

Highcharts
Defines a concrete class for a Highcharts.

Namespace

Drupal\charts_highcharts\Plugin\chart

Code

protected function buildPlotOptions(array $options) {
  $plotOptions = new PlotOptions();
  $plotOptionsStacking = new PlotOptionsStacking();
  $plotOptionsSeries = new PlotOptionsSeries();
  $plotOptionsSeriesDataLabels = new PlotOptionsSeriesDataLabels();
  $plotOptionsSeriesDataLabels
    ->setEnabled($options['data_labels']);

  // Set plot options if stacked chart.
  if (!empty($options['grouping'])) {
    $plotOptions
      ->setPlotOptions($options['type'], $plotOptionsStacking);
    $plotOptionsStacking
      ->setDataLabels($plotOptionsSeriesDataLabels);

    // Set markers if grouped.
    if (in_array($options['type'], [
      'area',
      'line',
      'scatter',
      'spline',
    ])) {
      $marker = new Marker();
      if ($options['data_markers'] == 'FALSE') {
        $marker
          ->setEnabled(FALSE);
      }
      else {
        $marker
          ->setEnabled(TRUE);
      }
      $plotOptionsStacking
        ->setMarker($marker);
    }
    if ($options['type'] == 'gauge') {
      $plotOptionsStacking
        ->setStacking('');
    }
  }
  else {
    $plotOptions
      ->setPlotOptions($options['type'], $plotOptionsSeries);
    $plotOptionsSeries
      ->setDataLabels($plotOptionsSeriesDataLabels);

    // Set markers if not grouped.
    if (in_array($options['type'], [
      'area',
      'line',
      'scatter',
      'spline',
    ])) {
      $marker = new Marker();
      if ($options['data_markers'] == 'FALSE') {
        $marker
          ->setEnabled(FALSE);
      }
      else {
        $marker
          ->setEnabled(TRUE);
      }
      $plotOptionsSeries
        ->setMarker($marker);
    }
  }
  if (isset($options['data_labels'])) {
    $plotOptionsSeriesDataLabels
      ->setEnabled($options['data_labels']);
  }

  // Determines if chart is three-dimensional.
  if (!empty($options['three_dimensional'])) {
    $plotOptionsSeries
      ->setDepth(45);
  }
  return $plotOptions;
}