From 8185d8671663465717f3dbd38f4918c3e0d71d84 Mon Sep 17 00:00:00 2001
From: Daniel Cothran <daniel@andile.co>
Date: Fri, 16 Feb 2018 22:47:22 -0500
Subject: [PATCH] Issue #2945416 by John Cook, andileco: Y-Axis title not
 working for HighCharts

---
 .../src/Charts/HighchartsChartsRender.php     |  5 ++--
 .../src/Plugin/chart/Highchart.php            | 28 +++++++++++--------
 .../src/Settings/Highcharts/Highcharts.php    | 27 ++++++++++++------
 3 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php
index cd3b572..2e8008f 100644
--- a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php
+++ b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php
@@ -121,10 +121,10 @@ class HighchartsChartsRender implements ChartsRenderInterface {
     $yAxes = [];
     $yAxisTitle = new YaxisTitle();
     $yAxisTitle->setText($options['yaxis_title']);
-    if (!empty($options['yaxis_min'])) {
+    if (is_numeric($options['yaxis_min'])) {
       $chartYaxis->min = $options['yaxis_min'];
     }
-    if (!empty($options['yaxis_max'])) {
+    if (is_numeric($options['yaxis_max'])) {
       $chartYaxis->max = $options['yaxis_max'];
     }
 
@@ -197,6 +197,7 @@ class HighchartsChartsRender implements ChartsRenderInterface {
     $highchart->setChart($chart);
     $highchart->setTitle($chartTitle);
     $highchart->setAxisX($chartXaxis);
+    $highchart->setAxisY($chartYaxis);
     $highchart->setTooltip($chartTooltip);
     $highchart->setPlotOptions($plotOptions);
     $highchart->setCredits($chartCredits);
diff --git a/modules/charts_highcharts/src/Plugin/chart/Highchart.php b/modules/charts_highcharts/src/Plugin/chart/Highchart.php
index 718a689..37b70b7 100644
--- a/modules/charts_highcharts/src/Plugin/chart/Highchart.php
+++ b/modules/charts_highcharts/src/Plugin/chart/Highchart.php
@@ -82,7 +82,7 @@ class Highchart extends AbstractChart {
 
     // Set chart title.
     $chartTitle = new ChartTitle();
-    if ((isset($options['title'])) && (!empty($options['title_position']))) {
+    if (isset($options['title'])) {
       $chartTitle->setText($options['title']);
     }
 
@@ -97,11 +97,13 @@ class Highchart extends AbstractChart {
     }
 
     // Set title position.
-    if ($options['title_position'] == 'in') {
-      $chartTitle->setVerticalAlign('middle');
-    }
-    else {
-      $chartTitle->setVerticalAlign('top');
+    if (isset($options['title_position'])) {
+      if ($options['title_position'] == 'in') {
+        $chartTitle->setVerticalAlign('middle');
+      }
+      else {
+        $chartTitle->setVerticalAlign('top');
+      }
     }
 
     $chartXaxis = new Xaxis();
@@ -126,10 +128,10 @@ class Highchart extends AbstractChart {
     $yAxes = [];
     $yAxisTitle = new YaxisTitle();
     $yAxisTitle->setText($options['yaxis_title']);
-    if (!empty($options['yaxis_min'])) {
+    if (is_numeric($options['yaxis_min'])) {
       $chartYaxis->min = $options['yaxis_min'];
     }
-    if (!empty($options['yaxis_max'])) {
+    if (is_numeric($options['yaxis_max'])) {
       $chartYaxis->max = $options['yaxis_max'];
     }
 
@@ -160,20 +162,23 @@ class Highchart extends AbstractChart {
     $plotOptionsSeries = new PlotOptionsSeries();
     $plotOptionsSeriesDataLabels = new PlotOptionsSeriesDataLabels();
     // Set plot options if stacked chart.
-    if(!empty($options['grouping'])) {
+    if (!empty($options['grouping'])) {
       $plotOptions->setPlotSeries($plotOptionsStacking);
       $plotOptionsStacking->setDataLabels($plotOptionsSeriesDataLabels);
-      $plotOptionsSeriesDataLabels->setEnabled($options['data_labels']);
     }
     else {
       $plotOptions->setPlotSeries($plotOptionsSeries);
       $plotOptionsSeries->setDataLabels($plotOptionsSeriesDataLabels);
+    }
+    if (isset($options['data_labels'])) {
       $plotOptionsSeriesDataLabels->setEnabled($options['data_labels']);
     }
 
     // Set Tooltip.
     $chartTooltip = new Tooltip();
-    $chartTooltip->setEnabled($options['tooltips']);
+    if (isset($options['tooltips'])) {
+      $chartTooltip->setEnabled($options['tooltips']);
+    }
     $chartCredits = new ChartCredits();
 
     // Set charts legend.
@@ -199,6 +204,7 @@ class Highchart extends AbstractChart {
     $highchart->setChart($chart);
     $highchart->setTitle($chartTitle);
     $highchart->setAxisX($chartXaxis);
+    $highchart->setAxisY($chartYaxis);
     $highchart->setTooltip($chartTooltip);
     $highchart->setPlotOptions($plotOptions);
     $highchart->setCredits($chartCredits);
diff --git a/modules/charts_highcharts/src/Settings/Highcharts/Highcharts.php b/modules/charts_highcharts/src/Settings/Highcharts/Highcharts.php
index 7095ac3..9deb147 100644
--- a/modules/charts_highcharts/src/Settings/Highcharts/Highcharts.php
+++ b/modules/charts_highcharts/src/Settings/Highcharts/Highcharts.php
@@ -10,13 +10,13 @@ class Highcharts implements \JsonSerializable {
   private $chart;
   private $title;
   private $xAxis;
+  private $yAxis;
   private $tooltip;
   private $plotOptions;
   private $legend;
   private $credits;
   private $innerSize = '%20';
   private $series;
-  /* private $yAxis; */
 
   /**
    * Get Chart.
@@ -78,16 +78,25 @@ class Highcharts implements \JsonSerializable {
     $this->xAxis = $xAxis;
   }
 
-  /*
-  @return mixed
-  public function getYAxis() {
-  return $this->yAxis;
-  }
-  @param mixed $yAxis
-  public function setYAxis($yAxis) {
-  $this->yAxis = $yAxis;
+  /**
+   * Get Y Axis.
+   *
+   * @return \Drupal\charts_highcharts\Settings\Highcharts\Yaxis|null
+   *   Y Axis.
+   */
+  public function getAxisY() {
+    return $this->yAxis;
   }
+
+  /**
+   * Set Y Axis.
+   *
+   * @param \Drupal\charts_highcharts\Settings\Highcharts\Yaxis $yAxis
+   *   Y Axis.
    */
+  public function setAxisY(Yaxis $yAxis) {
+    $this->yAxis = $yAxis;
+  }
 
   /**
    * Get Tooltip.
-- 
GitLab