From aa06968588cd885c44c643747bac0e73454ff8b1 Mon Sep 17 00:00:00 2001
From: Daniel Cothran <daniel@andile.co>
Date: Sat, 29 Jul 2017 10:34:45 -0400
Subject: [PATCH] Update Highcharts based on issue 2898236

---
 .../charts_highcharts/js/charts_highcharts.js | 31 ++++++++++++++++++-
 src/Form/ChartsConfigForm.php                 |  8 ++---
 .../display/ChartsPluginDisplayChart.php      |  8 ++---
 3 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/modules/charts_highcharts/js/charts_highcharts.js b/modules/charts_highcharts/js/charts_highcharts.js
index 36629f8..1b18ea9 100644
--- a/modules/charts_highcharts/js/charts_highcharts.js
+++ b/modules/charts_highcharts/js/charts_highcharts.js
@@ -11,7 +11,36 @@
       $('.charts-highchart').once().each(function () {
         if ($(this).attr('data-chart')) {
           var highcharts = $(this).attr('data-chart');
-          $(this).highcharts(JSON.parse(highcharts));
+          var hc = JSON.parse(highcharts);
+          if (hc.chart.type === 'pie') {
+            delete hc.plotOptions.bar;
+            hc.plotOptions.pie = {
+              allowPointSelect: true,
+              cursor: 'pointer',
+              showInLegend: true,
+              dataLabels: {
+                enabled: true,
+                format: '{point.y:,.0f}'
+              }
+            };
+
+            hc.legend.enabled = true;
+            hc.legend.labelFormatter = function () {
+              var legendIndex = this.index;
+              return this.series.chart.axes[0].categories[legendIndex];
+            };
+
+            hc.tooltip.formatter = function () {
+              var sliceIndex = this.point.index;
+              var sliceName = this.series.chart.axes[0].categories[sliceIndex];
+              return '' + sliceName +
+                  ' : ' + this.y + '';
+            };
+
+            console.log(hc);
+          }
+
+          $(this).highcharts(hc);
         }
       });
     }
diff --git a/src/Form/ChartsConfigForm.php b/src/Form/ChartsConfigForm.php
index 9e37207..3a9c0a9 100644
--- a/src/Form/ChartsConfigForm.php
+++ b/src/Form/ChartsConfigForm.php
@@ -131,6 +131,8 @@ class ChartsConfigForm extends ConfigFormBase {
     // Ensure all defaults are set.
     $options = array_merge($this->charts_default_settings(), $defaults);
 
+    $form['#attached']['library'][] = ['charts', 'charts.admin'];
+
     // Get a list of available chart libraries.
     $charts_info = $this->charts_info();
     $library_options = [];
@@ -179,7 +181,7 @@ class ChartsConfigForm extends ConfigFormBase {
 
     // Set data attributes to identify special properties of different types.
     foreach ($chart_types as $chart_type => $chart_type_info) {
-      if (isset($chart_type_info['axis_inverted']) && $chart_type_info['axis_inverted']) {
+      if ($chart_type_info['axis_inverted']) {
         $form['type'][$chart_type]['#attributes']['data-axis-inverted'] = TRUE;
       }
       if ($chart_type_info['axis'] === ChartsInterface::CHARTS_SINGLE_AXIS) {
@@ -483,10 +485,6 @@ class ChartsConfigForm extends ConfigFormBase {
       'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
       'stacking' => TRUE,
     ];
-    $chart_types['donut'] = [
-      'label' => $this->t('Donut'),
-      'axis' => ChartsInterface::CHARTS_SINGLE_AXIS,
-    ];
     $chart_types['line'] = [
       'label' => $this->t('Line'),
       'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
diff --git a/src/Plugin/views/display/ChartsPluginDisplayChart.php b/src/Plugin/views/display/ChartsPluginDisplayChart.php
index 1eb65b3..db18691 100644
--- a/src/Plugin/views/display/ChartsPluginDisplayChart.php
+++ b/src/Plugin/views/display/ChartsPluginDisplayChart.php
@@ -117,11 +117,7 @@ class ChartsPluginDisplayChart extends Attachment {
   }
 
   /**
-   * Perform any necessary changes to the form values prior to storage.
-   * There is no need for this function to actually store the data.
-   *
-   * @param $form
-   * @param FormStateInterface $form_state
+   * {@inheritdoc}
    */
   public function submitOptionsForm(&$form, FormStateInterface $form_state) {
     // It is very important to call the parent function here:
@@ -131,7 +127,7 @@ class ChartsPluginDisplayChart extends Attachment {
       case 'displays':
         $form_state->setValue($section, array_filter($form_state->getValue($section)));
         break;
-
+      // @todo set isDefaulted to false by default.
       case 'inherit_arguments':
       case 'inherit_exposed_filters':
       case 'inherit_yaxis':
-- 
GitLab