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

Issue #2930340 by mpoloskey: Some highcharts settings are not working

parent 5a0e5075
No related branches found
No related tags found
No related merge requests found
Showing with 207 additions and 54 deletions
...@@ -12,9 +12,9 @@ use Drupal\charts_highcharts\Settings\Highcharts\ChartLabel; ...@@ -12,9 +12,9 @@ use Drupal\charts_highcharts\Settings\Highcharts\ChartLabel;
use Drupal\charts_highcharts\Settings\Highcharts\YaxisLabel; use Drupal\charts_highcharts\Settings\Highcharts\YaxisLabel;
use Drupal\charts_highcharts\Settings\Highcharts\Yaxis; use Drupal\charts_highcharts\Settings\Highcharts\Yaxis;
use Drupal\charts_highcharts\Settings\Highcharts\YaxisTitle; use Drupal\charts_highcharts\Settings\Highcharts\YaxisTitle;
use Drupal\charts_highcharts\Settings\Highcharts\DataLabelStatus;
use Drupal\charts_highcharts\Settings\Highcharts\DataLabels;
use Drupal\charts_highcharts\Settings\Highcharts\PlotOptions; use Drupal\charts_highcharts\Settings\Highcharts\PlotOptions;
use Drupal\charts_highcharts\Settings\Highcharts\PlotOptionsSeries;
use Drupal\charts_highcharts\Settings\Highcharts\PlotOptionsSeriesDataLabels;
use Drupal\charts_highcharts\Settings\Highcharts\Tooltip; use Drupal\charts_highcharts\Settings\Highcharts\Tooltip;
use Drupal\charts_highcharts\Settings\Highcharts\ChartCredits; use Drupal\charts_highcharts\Settings\Highcharts\ChartCredits;
use Drupal\charts_highcharts\Settings\Highcharts\ChartLegend; use Drupal\charts_highcharts\Settings\Highcharts\ChartLegend;
...@@ -67,14 +67,27 @@ class HighchartsChartsRender implements ChartsRenderInterface { ...@@ -67,14 +67,27 @@ class HighchartsChartsRender implements ChartsRenderInterface {
// Set chart height. // Set chart height.
if (isset($options['height'])) { if (isset($options['height'])) {
$chart->setHeight($options['height']); $chart->setHeight($options['height']);
} }
// Set chart title. // Set chart title.
$chartTitle = new ChartTitle(); $chartTitle = new ChartTitle();
if (isset($options['title'])) { if ((isset($options['title'])) && (!empty($options['title_position']))) {
$chartTitle->setText($options['title']); $chartTitle->setText($options['title']);
} }
// Set background color
if (isset($options['background'])) {
$chart->setBackgroundColor($options['background']);
}
// Set title position.
if ($options['title_position'] =='in' ) {
$chartTitle->setVerticalAlign('middle');
}
else {
$chartTitle->setVerticalAlign('top');
}
$chartXaxis = new Xaxis(); $chartXaxis = new Xaxis();
$chartLabels = new ChartLabel(); $chartLabels = new ChartLabel();
...@@ -124,14 +137,38 @@ class HighchartsChartsRender implements ChartsRenderInterface { ...@@ -124,14 +137,38 @@ class HighchartsChartsRender implements ChartsRenderInterface {
} }
array_push($yAxes, $chartYaxisSecondary); array_push($yAxes, $chartYaxisSecondary);
} }
$dataLabelStatus = new DataLabelStatus();
$dataLabels = new DataLabels(); // Set Plotoptions
$dataLabels->setDataLabels($dataLabelStatus);
$plotOptions = new PlotOptions(); $plotOptions = new PlotOptions();
$plotOptions->setPlotType($dataLabels); $plotOptionsSeries = new PlotOptionsSeries();
$plotOptionsSeriesDataLabels = new PlotOptionsSeriesDataLabels();
$plotOptions->setPlotSeries($plotOptionsSeries);
$plotOptionsSeries->setDataLabels($plotOptionsSeriesDataLabels);
$plotOptionsSeriesDataLabels->setEnabled($options['data_labels']);
// Set Tooltip
$chartTooltip = new Tooltip(); $chartTooltip = new Tooltip();
$chartTooltip->setEnabled($options['tooltips']);
$chartCredits = new ChartCredits(); $chartCredits = new ChartCredits();
// Set charts legend
$chartLegend = new ChartLegend(); $chartLegend = new ChartLegend();
if (empty($options['legend_position'])) {
$chartLegend->setEnabled(false);
}
elseif (in_array($options['legend_position'], array('left','right'))) {
$chartLegend->setAlign($options['legend_position']);
$chartLegend->setVerticalAlign('top');
if ($options['legend_position'] == 'left') {
$chartLegend->setX('0');
}
}
else {
$chartLegend->setVerticalAlign($options['legend_position']);
$chartLegend->setAlign('center');
$chartLegend->setX('0');
$chartLegend->setY('0');
}
$highchart = new Highcharts(); $highchart = new Highcharts();
$highchart->setChart($chart); $highchart->setChart($chart);
...@@ -143,7 +180,6 @@ class HighchartsChartsRender implements ChartsRenderInterface { ...@@ -143,7 +180,6 @@ class HighchartsChartsRender implements ChartsRenderInterface {
$highchart->setCredits($chartCredits); $highchart->setCredits($chartCredits);
$highchart->setLegend($chartLegend); $highchart->setLegend($chartLegend);
$highchart->setSeries($seriesData); $highchart->setSeries($seriesData);
$variables['chart_type'] = 'highcharts'; $variables['chart_type'] = 'highcharts';
$variables['content_attributes']['data-chart'][] = json_encode($highchart); $variables['content_attributes']['data-chart'][] = json_encode($highchart);
$variables['attributes']['id'][0] = $chartId; $variables['attributes']['id'][0] = $chartId;
......
...@@ -13,9 +13,9 @@ use Drupal\charts_highcharts\Settings\Highcharts\ChartLabel; ...@@ -13,9 +13,9 @@ use Drupal\charts_highcharts\Settings\Highcharts\ChartLabel;
use Drupal\charts_highcharts\Settings\Highcharts\YaxisLabel; use Drupal\charts_highcharts\Settings\Highcharts\YaxisLabel;
use Drupal\charts_highcharts\Settings\Highcharts\Yaxis; use Drupal\charts_highcharts\Settings\Highcharts\Yaxis;
use Drupal\charts_highcharts\Settings\Highcharts\YaxisTitle; use Drupal\charts_highcharts\Settings\Highcharts\YaxisTitle;
use Drupal\charts_highcharts\Settings\Highcharts\DataLabelStatus;
use Drupal\charts_highcharts\Settings\Highcharts\DataLabels;
use Drupal\charts_highcharts\Settings\Highcharts\PlotOptions; use Drupal\charts_highcharts\Settings\Highcharts\PlotOptions;
use Drupal\charts_highcharts\Settings\Highcharts\PlotOptionsSeries;
use Drupal\charts_highcharts\Settings\Highcharts\PlotOptionsSeriesDataLabels;
use Drupal\charts_highcharts\Settings\Highcharts\Tooltip; use Drupal\charts_highcharts\Settings\Highcharts\Tooltip;
use Drupal\charts_highcharts\Settings\Highcharts\ChartCredits; use Drupal\charts_highcharts\Settings\Highcharts\ChartCredits;
use Drupal\charts_highcharts\Settings\Highcharts\ChartLegend; use Drupal\charts_highcharts\Settings\Highcharts\ChartLegend;
...@@ -46,6 +46,8 @@ class Highchart extends AbstractChart { ...@@ -46,6 +46,8 @@ class Highchart extends AbstractChart {
* Variables. * Variables.
* @param mixed $chartId * @param mixed $chartId
* Chart Id. * Chart Id.
*
* @return array|void
*/ */
public function buildVariables($options, $categories = [], $seriesData = [], $attachmentDisplayOptions = [], &$variables, $chartId) { public function buildVariables($options, $categories = [], $seriesData = [], $attachmentDisplayOptions = [], &$variables, $chartId) {
$noAttachmentDisplays = count($attachmentDisplayOptions) === 0; $noAttachmentDisplays = count($attachmentDisplayOptions) === 0;
...@@ -61,10 +63,12 @@ class Highchart extends AbstractChart { ...@@ -61,10 +63,12 @@ class Highchart extends AbstractChart {
} }
// Add innerSize to differentiate between donut and pie. // Add innerSize to differentiate between donut and pie.
foreach ($seriesData as $key => &$value) { foreach ($seriesData as $key => &$value) {
$innerSize['showInLegend'] = 'true'; if ($typeOptions == 'pie') {
$innerSize['innerSize'] = '40%'; $innerSize['showInLegend'] = 'true';
$chartPlacement = array_search($value, $seriesData); $innerSize['innerSize'] = '40%';
$seriesData[$chartPlacement] = array_merge($innerSize, $seriesData[$chartPlacement]); $chartPlacement = array_search($value, $seriesData);
$seriesData[$chartPlacement] = array_merge($innerSize, $seriesData[$chartPlacement]);
}
} }
} }
$chart->setType($typeOptions); $chart->setType($typeOptions);
...@@ -81,10 +85,23 @@ class Highchart extends AbstractChart { ...@@ -81,10 +85,23 @@ class Highchart extends AbstractChart {
// Set chart title. // Set chart title.
$chartTitle = new ChartTitle(); $chartTitle = new ChartTitle();
if (isset($options['title'])) { if ((isset($options['title'])) && (!empty($options['title_position']))) {
$chartTitle->setText($options['title']); $chartTitle->setText($options['title']);
} }
// Set background color
if (isset($options['background'])) {
$chart->setBackgroundColor($options['background']);
}
// Set title position.
if ($options['title_position'] =='in' ) {
$chartTitle->setVerticalAlign('middle');
}
else {
$chartTitle->setVerticalAlign('top');
}
$chartXaxis = new Xaxis(); $chartXaxis = new Xaxis();
$chartLabels = new ChartLabel(); $chartLabels = new ChartLabel();
...@@ -134,14 +151,38 @@ class Highchart extends AbstractChart { ...@@ -134,14 +151,38 @@ class Highchart extends AbstractChart {
} }
array_push($yAxes, $chartYaxisSecondary); array_push($yAxes, $chartYaxisSecondary);
} }
$dataLabelStatus = new DataLabelStatus();
$dataLabels = new DataLabels(); // Set Plotoptions
$dataLabels->setDataLabels($dataLabelStatus);
$plotOptions = new PlotOptions(); $plotOptions = new PlotOptions();
$plotOptions->setPlotType($dataLabels); $plotOptionsSeries = new PlotOptionsSeries();
$plotOptionsSeriesDataLabels = new PlotOptionsSeriesDataLabels();
$plotOptions->setPlotSeries($plotOptionsSeries);
$plotOptionsSeries->setDataLabels($plotOptionsSeriesDataLabels);
$plotOptionsSeriesDataLabels->setEnabled($options['data_labels']);
// Set Tooltip
$chartTooltip = new Tooltip(); $chartTooltip = new Tooltip();
$chartTooltip->setEnabled($options['tooltips']);
$chartCredits = new ChartCredits(); $chartCredits = new ChartCredits();
// Set charts legend
$chartLegend = new ChartLegend(); $chartLegend = new ChartLegend();
if (empty($options['legend_position'])) {
$chartLegend->setEnabled(false);
}
elseif (in_array($options['legend_position'], array('left','right'))) {
$chartLegend->setAlign($options['legend_position']);
$chartLegend->setVerticalAlign('top');
if ($options['legend_position'] == 'left') {
$chartLegend->setX('0');
}
}
else {
$chartLegend->setVerticalAlign($options['legend_position']);
$chartLegend->setAlign('center');
$chartLegend->setX('0');
$chartLegend->setY('0');
}
$highchart = new Highcharts(); $highchart = new Highcharts();
$highchart->setChart($chart); $highchart->setChart($chart);
...@@ -153,7 +194,6 @@ class Highchart extends AbstractChart { ...@@ -153,7 +194,6 @@ class Highchart extends AbstractChart {
$highchart->setCredits($chartCredits); $highchart->setCredits($chartCredits);
$highchart->setLegend($chartLegend); $highchart->setLegend($chartLegend);
$highchart->setSeries($seriesData); $highchart->setSeries($seriesData);
$variables['chart_type'] = 'highcharts'; $variables['chart_type'] = 'highcharts';
$variables['content_attributes']['data-chart'][] = json_encode($highchart); $variables['content_attributes']['data-chart'][] = json_encode($highchart);
$variables['attributes']['id'][0] = $chartId; $variables['attributes']['id'][0] = $chartId;
......
...@@ -10,6 +10,7 @@ class Chart implements \JsonSerializable { ...@@ -10,6 +10,7 @@ class Chart implements \JsonSerializable {
private $type; private $type;
private $width = NULL; private $width = NULL;
private $height = NULL; private $height = NULL;
private $backgroundColor;
/** /**
* Get Type. * Get Type.
...@@ -81,6 +82,26 @@ class Chart implements \JsonSerializable { ...@@ -81,6 +82,26 @@ class Chart implements \JsonSerializable {
} }
} }
/**
* Get BackgroundColor
*
* @return string
* BackgroundColor
*/
public function getBackgroundColor() {
return $this->backgroundColor;
}
/**
* Set BackgroundColor
*
* @param string $BackgroundColor
* BackgroundColor
*/
public function setBackgroundColor($backgroundColor) {
$this->backgroundColor = $backgroundColor;
}
/** /**
* Json Serialize. * Json Serialize.
* *
......
...@@ -10,7 +10,7 @@ class ChartLegend implements \JsonSerializable { ...@@ -10,7 +10,7 @@ class ChartLegend implements \JsonSerializable {
private $layout = 'vertical'; private $layout = 'vertical';
private $align = 'right'; private $align = 'right';
private $verticalAlign = 'top'; private $verticalAlign = 'top';
private $x = -40; private $x = 0;
private $y = 80; private $y = 80;
private $floating = TRUE; private $floating = TRUE;
private $borderWidth = 1; private $borderWidth = 1;
...@@ -196,6 +196,27 @@ class ChartLegend implements \JsonSerializable { ...@@ -196,6 +196,27 @@ class ChartLegend implements \JsonSerializable {
public function setShadow($shadow) { public function setShadow($shadow) {
$this->shadow = $shadow; $this->shadow = $shadow;
} }
/**
* Set Legende.
*
* @return boolean
* Enabled
*/
public function isEnabled() {
return $this->enabled;
}
/**
* Set enabled
*
* @param boolean $enabled
* Enabled
*/
public function setEnabled($enabled) {
$this->enabled = $enabled;
}
/** /**
* Json Serialize. * Json Serialize.
......
...@@ -28,6 +28,21 @@ class ChartTitle implements \JsonSerializable { ...@@ -28,6 +28,21 @@ class ChartTitle implements \JsonSerializable {
public function setText($text) { public function setText($text) {
$this->text = $text; $this->text = $text;
} }
/**
* @return string
*/
public function getVerticalAlign() {
return $this->verticalAlign;
}
/**
* @param string $verticalAlign
*/
public function setVerticalAlign($verticalAlign) {
$this->verticalAlign = $verticalAlign;
}
/** /**
* Json Serialize. * Json Serialize.
......
...@@ -2,38 +2,25 @@ ...@@ -2,38 +2,25 @@
namespace Drupal\charts_highcharts\Settings\Highcharts; namespace Drupal\charts_highcharts\Settings\Highcharts;
/**
* Plot Options.
*/
class PlotOptions implements \JsonSerializable { class PlotOptions implements \JsonSerializable {
private $series;
private $plotType;
/** /**
* Get Plot Type.
*
* @return mixed * @return mixed
* Plot Type.
*/ */
public function getPlotType() { public function getPlotSeries() {
return $this->plotType; return $this->series;
} }
/** /**
* Set Plot Type.
*
* @param mixed $plotType * @param mixed $plotType
* Plot Type.
*/ */
public function setPlotType($plotType) { public function setPlotSeries($series) {
$this->plotType = $plotType; $this->series = $series;
} }
/** /**
* Json Serialize.
*
* @return array * @return array
* Json Serialize.
*/ */
public function jsonSerialize() { public function jsonSerialize() {
$vars = get_object_vars($this); $vars = get_object_vars($this);
......
...@@ -2,38 +2,25 @@ ...@@ -2,38 +2,25 @@
namespace Drupal\charts_highcharts\Settings\Highcharts; namespace Drupal\charts_highcharts\Settings\Highcharts;
/** class PlotOptionsSeries implements \JsonSerializable {
* Data Labels.
*/
class DataLabels implements \JsonSerializable {
private $dataLabels; private $dataLabels;
/** /**
* Get Data Labels.
*
* @return mixed * @return mixed
* Data Labels.
*/ */
public function getDataLabels() { public function getDataLabels() {
return $this->dataLabels; return $this->dataLabels;
} }
/** /**
* Set Data Labels.
*
* @param mixed $dataLabels * @param mixed $dataLabels
* Data Labels.
*/ */
public function setDataLabels($dataLabels) { public function setDataLabels($dataLabels) {
$this->dataLabels = $dataLabels; $this->dataLabels = $dataLabels;
} }
/** /**
* Json Serialize.
*
* @return array * @return array
* Json Serialize.
*/ */
public function jsonSerialize() { public function jsonSerialize() {
$vars = get_object_vars($this); $vars = get_object_vars($this);
......
<?php
namespace Drupal\charts_highcharts\Settings\Highcharts;
class PlotOptionsSeriesDataLabels implements \JsonSerializable {
private $enabled = FALSE;
/**
* @return boolean
*/
public function getEnabled() {
return $this->enabled;
}
/**
* @param boolean $enabled
*/
public function setEnabled($enabled) {
$this->enabled = $enabled;
}
/**
* @return array
*/
public function jsonSerialize() {
$vars = get_object_vars($this);
return $vars;
}
}
...@@ -8,6 +8,7 @@ namespace Drupal\charts_highcharts\Settings\Highcharts; ...@@ -8,6 +8,7 @@ namespace Drupal\charts_highcharts\Settings\Highcharts;
class Tooltip implements \JsonSerializable { class Tooltip implements \JsonSerializable {
private $valueSuffix = ''; private $valueSuffix = '';
private $enabled = FALSE;
/** /**
* Get Value Suffix. * Get Value Suffix.
...@@ -28,7 +29,21 @@ class Tooltip implements \JsonSerializable { ...@@ -28,7 +29,21 @@ class Tooltip implements \JsonSerializable {
public function setValueSuffix($valueSuffix) { public function setValueSuffix($valueSuffix) {
$this->valueSuffix = $valueSuffix; $this->valueSuffix = $valueSuffix;
} }
/**
* @return boolean
*/
public function getEnabled() {
return $this->enabled;
}
/**
* @param boolean $enabled
*/
public function setEnabled($enabled) {
$this->enabled = $enabled;
}
/** /**
* Json Serialize. * Json Serialize.
* *
......
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