diff --git a/charts.module b/charts.module index a6d11c10213d4e83ddf1857442292aa1bca1160a..0a01040b248f762d1a7447ab6b5aa576102e78a0 100644 --- a/charts.module +++ b/charts.module @@ -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); } } diff --git a/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php b/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php index b7222693223c0fee47bd4648b0b13eb62e878340..63dd860d4b8a4a78a9a12abc5ce2e7b612440c25 100644 --- a/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php +++ b/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php @@ -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']; diff --git a/modules/charts_blocks/templates/charts-block.html.twig b/modules/charts_blocks/templates/charts-block.html.twig index b2a89501e1b292c9d5eed8e0ed88e237a27eadea..734319d20cbcd3ff4f8ae2edcf09f8284e8f91e6 100644 --- a/modules/charts_blocks/templates/charts-block.html.twig +++ b/modules/charts_blocks/templates/charts-block.html.twig @@ -1,3 +1,3 @@ {% 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> diff --git a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php index 93db286df7c6909e3803df6728dd4d2b47fa57ad..1f8560121fc24d4c979ece2c89160f99ad9be79d 100644 --- a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php +++ b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php @@ -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(); diff --git a/modules/charts_highcharts/src/Plugin/chart/Highchart.php b/modules/charts_highcharts/src/Plugin/chart/Highchart.php index e05dee7edb5a7450985d6476922ee5f6d7b5aee9..e2000ea049c367820e30624e784c79f2b57c7b60 100644 --- a/modules/charts_highcharts/src/Plugin/chart/Highchart.php +++ b/modules/charts_highcharts/src/Plugin/chart/Highchart.php @@ -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); diff --git a/modules/charts_highcharts/src/Settings/Highcharts/PlotOptionsStacking.php b/modules/charts_highcharts/src/Settings/Highcharts/PlotOptionsStacking.php new file mode 100644 index 0000000000000000000000000000000000000000..58252e97c57a3499a9b017c19b8c9a267fcff4a5 --- /dev/null +++ b/modules/charts_highcharts/src/Settings/Highcharts/PlotOptionsStacking.php @@ -0,0 +1,65 @@ +<?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; + } + +} diff --git a/src/Plugin/views/style/ChartsPluginStyleChart.php b/src/Plugin/views/style/ChartsPluginStyleChart.php index e7e2b9fc49516c0f544016a80635075f4753ba4f..b10c54664958105fe7e84f36516cbc6b6d4cae7e 100644 --- a/src/Plugin/views/style/ChartsPluginStyleChart.php +++ b/src/Plugin/views/style/ChartsPluginStyleChart.php @@ -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; diff --git a/templates/views-view-charts.html.twig b/templates/views-view-charts.html.twig index f46df05abfd7a0903af23385ecbc2fd085a67532..4d1a1135a0c5b2a5bb997c7befd73b6d80791fdb 100644 --- a/templates/views-view-charts.html.twig +++ b/templates/views-view-charts.html.twig @@ -1,3 +1,3 @@ -{% 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>