Skip to content
Snippets Groups Projects
Commit 7a5be6c6 authored by Daniel Cothran's avatar Daniel Cothran
Browse files

Issue #2943952 by andileco: Enable stacking

parent 016a57b6
No related branches found
No related tags found
No related merge requests found
......@@ -97,13 +97,15 @@ function template_preprocess_views_view_charts(&$variables) {
if (!isset($plugin_definitions)) {
// To be removed in drupal 9.
$moduleSelector = new ModuleSelector($library, $categories, $seriesData, $options, $attachmentDisplayOptions, $chartId);
$moduleSelector = new ModuleSelector($library, $categories, $seriesData, $attachmentDisplayOptions, $options, $chartId);
if ($moduleSelector->moduleExists()) {
$moduleSelector->buildVariables($variables);
}
}
else {
$plugin = $plugin_manager->createInstance($library);
$variables['height'] = $options['height'];
$variables['width'] = $options['width'];
$plugin->buildVariables($options, $categories, $seriesData, $attachmentDisplayOptions, $variables, $chartId);
}
}
......@@ -134,7 +134,7 @@ class ChartsBlock extends BlockBase {
unset($form['display']['background']['#parents']);
$form['display']['background']['#default_value'] = $this->configuration['background'];
unset($form['display']['three_dimensional']['#parents']);
$form['display']['three_dimensional']['#default_value'] = $this->configuration['three_dimensional'];
......
{% set library, height, width = 'charts_' ~ library ~ '/' ~ library, options.height, options.width %}
{{ attach_library("#{ library }") }}
<div {{ attributes }} {{ content_attributes }} style="width:{{ width }};height:{{ height }};"></div>
<div {{ attributes }} {{ content_attributes }} style="{% if width is not empty %}width:{{ width }}px;{% endif %}{% if height is not empty %}height:{{ height }}px;{% endif %}"></div>
......@@ -6,6 +6,7 @@ use Drupal\charts\Charts\ChartsRenderInterface;
use Drupal\charts\Util\Util;
use Drupal\charts_highcharts\Settings\Highcharts\Chart;
use Drupal\charts_highcharts\Settings\Highcharts\ChartTitle;
use Drupal\charts_highcharts\Settings\Highcharts\PlotOptionsStacking;
use Drupal\charts_highcharts\Settings\Highcharts\Xaxis;
use Drupal\charts_highcharts\Settings\Highcharts\XaxisTitle;
use Drupal\charts_highcharts\Settings\Highcharts\ChartLabel;
......@@ -143,13 +144,22 @@ class HighchartsChartsRender implements ChartsRenderInterface {
array_push($yAxes, $chartYaxisSecondary);
}
// Set Plotoptions.
// Set plot options.
$plotOptions = new PlotOptions();
$plotOptionsStacking = new PlotOptionsStacking();
$plotOptionsSeries = new PlotOptionsSeries();
$plotOptionsSeriesDataLabels = new PlotOptionsSeriesDataLabels();
$plotOptions->setPlotSeries($plotOptionsSeries);
$plotOptionsSeries->setDataLabels($plotOptionsSeriesDataLabels);
$plotOptionsSeriesDataLabels->setEnabled($options['data_labels']);
// Set plot options if stacked chart.
if(!empty($options['grouping'])) {
$plotOptions->setPlotSeries($plotOptionsStacking);
$plotOptionsStacking->setDataLabels($plotOptionsSeriesDataLabels);
$plotOptionsSeriesDataLabels->setEnabled($options['data_labels']);
}
else {
$plotOptions->setPlotSeries($plotOptionsSeries);
$plotOptionsSeries->setDataLabels($plotOptionsSeriesDataLabels);
$plotOptionsSeriesDataLabels->setEnabled($options['data_labels']);
}
// Set Tooltip.
$chartTooltip = new Tooltip();
......
......@@ -3,10 +3,9 @@
namespace Drupal\charts_highcharts\Plugin\chart;
use Drupal\charts\Plugin\chart\AbstractChart;
/* use Drupal\Charts\Annotation\Chart; */
use Drupal\charts_highcharts\Settings\Highcharts\Chart;
/* use Drupal\charts_highcharts\Settings\Highcharts\ChartType; */
use Drupal\charts_highcharts\Settings\Highcharts\ChartTitle;
use Drupal\charts_highcharts\Settings\Highcharts\PlotOptionsStacking;
use Drupal\charts_highcharts\Settings\Highcharts\Xaxis;
use Drupal\charts_highcharts\Settings\Highcharts\XaxisTitle;
use Drupal\charts_highcharts\Settings\Highcharts\ChartLabel;
......@@ -150,13 +149,22 @@ class Highchart extends AbstractChart {
array_push($yAxes, $chartYaxisSecondary);
}
// Set Plotoptions.
// Set plot options.
$plotOptions = new PlotOptions();
$plotOptionsStacking = new PlotOptionsStacking();
$plotOptionsSeries = new PlotOptionsSeries();
$plotOptionsSeriesDataLabels = new PlotOptionsSeriesDataLabels();
$plotOptions->setPlotSeries($plotOptionsSeries);
$plotOptionsSeries->setDataLabels($plotOptionsSeriesDataLabels);
$plotOptionsSeriesDataLabels->setEnabled($options['data_labels']);
// Set plot options if stacked chart.
if(!empty($options['grouping'])) {
$plotOptions->setPlotSeries($plotOptionsStacking);
$plotOptionsStacking->setDataLabels($plotOptionsSeriesDataLabels);
$plotOptionsSeriesDataLabels->setEnabled($options['data_labels']);
}
else {
$plotOptions->setPlotSeries($plotOptionsSeries);
$plotOptionsSeries->setDataLabels($plotOptionsSeriesDataLabels);
$plotOptionsSeriesDataLabels->setEnabled($options['data_labels']);
}
// Set Tooltip.
$chartTooltip = new Tooltip();
......@@ -186,7 +194,6 @@ class Highchart extends AbstractChart {
$highchart->setChart($chart);
$highchart->setTitle($chartTitle);
$highchart->setAxisX($chartXaxis);
/* $highchart->yAxis = $yAxes; */
$highchart->setTooltip($chartTooltip);
$highchart->setPlotOptions($plotOptions);
$highchart->setCredits($chartCredits);
......
<?php
namespace Drupal\charts_highcharts\Settings\Highcharts;
/**
* Plot Options Series.
*/
class PlotOptionsStacking implements \JsonSerializable {
private $dataLabels;
private $stacking = 'normal';
/**
* Get Data Labels.
*
* @return mixed
* Data Labels.
*/
public function getDataLabels() {
return $this->dataLabels;
}
/**
* Set Data Labels.
*
* @param mixed $dataLabels
* Data Labels.
*/
public function setDataLabels($dataLabels) {
$this->dataLabels = $dataLabels;
}
/**
* Get Stacking.
*
* @return mixed
* Stacking.
*/
public function getStacking() {
return $this->stacking;
}
/**
* Set Stacking.
*
* @param mixed $stacking
* Stacking.
*/
public function setStacking($stacking) {
$this->stacking = $stacking;
}
/**
* Json Serialize.
*
* @return array
* Json Serialize.
*/
public function jsonSerialize() {
$vars = get_object_vars($this);
return $vars;
}
}
......@@ -24,7 +24,7 @@ use Drupal\views\Plugin\views\style\StylePluginBase;
*/
class ChartsPluginStyleChart extends StylePluginBase {
protected $usesGrouping = FALSE;
// protected $usesGrouping = FALSE;
protected $usesFields = TRUE;
protected $usesRowPlugin = TRUE;
......
{% set library, height, width = 'charts_' ~ chart_type ~ '/' ~ chart_type, options.height, options.width %}
{% set library, height, width = 'charts_' ~ chart_type ~ '/' ~ chart_type, height, width %}
{{ attach_library("#{ library }") }}
<div {{ attributes }} {{ content_attributes }} style="width:{{ width }};height:{{ height }};"></div>
<div {{ attributes }} {{ content_attributes }} style="{% if width is not empty %}width:{{ width }}px;{% endif %}{% if height is not empty %}height:{{ height }}px;{% endif %}"></div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment