From 016a57b60951eb790cc7dd2e044904972f58caa6 Mon Sep 17 00:00:00 2001
From: Daniel Cothran <daniel@andile.co>
Date: Sun, 11 Feb 2018 10:40:30 -0500
Subject: [PATCH] Issue #2942129 by pinchy: Adding "is3D" option for 3D Google
 Charts integration

---
 includes/charts.pages.inc                     | 14 ++++++++++
 .../src/Controller/ChartsApiExample.php       |  1 +
 .../src/Plugin/Block/ChartsBlock.php          |  5 ++++
 .../src/Charts/GoogleChartsRender.php         |  5 ++++
 .../src/Plugin/chart/GoogleCharts.php         |  5 ++++
 .../src/Settings/Google/GoogleOptions.php     | 27 +++++++++++++++++++
 src/Form/ChartsConfigForm.php                 | 14 ++++++++++
 7 files changed, 71 insertions(+)

diff --git a/includes/charts.pages.inc b/includes/charts.pages.inc
index 4fa38d0..947d6a0 100644
--- a/includes/charts.pages.inc
+++ b/includes/charts.pages.inc
@@ -422,6 +422,19 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren
     '#parents'       => array_merge($parents, ['background']),
   ];
 
+  $form['display']['three_dimensional'] = [
+    '#title'         => t('Make chart three-dimensional (3D)'),
+    '#type'          => 'checkbox',
+    '#default_value' => $options['three_dimensional'],
+    '#parents'       => array_merge($parents, ['three_dimensional']),
+    '#attributes'    => [
+      'class'      => [
+          'chart-type-checkbox',
+          'container-inline',
+        ],
+      ],
+    ];
+
   $form['display']['dimensions'] = [
     '#title'          => t('Dimensions'),
     '#theme_wrappers' => ['form_element'],
@@ -668,6 +681,7 @@ function charts_default_settings() {
     'legend_position'       => 'right',
     'colors'                => charts_default_colors(),
     'background'            => '',
+    'three_dimensional'     => FALSE,
     'tooltips'              => TRUE,
     'tooltips_use_html'     => FALSE,
     'width'                 => NULL,
diff --git a/modules/charts_api_example/src/Controller/ChartsApiExample.php b/modules/charts_api_example/src/Controller/ChartsApiExample.php
index 18e3d6b..6f80e9f 100644
--- a/modules/charts_api_example/src/Controller/ChartsApiExample.php
+++ b/modules/charts_api_example/src/Controller/ChartsApiExample.php
@@ -44,6 +44,7 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter
       'yaxis_title' => $this->t('Y-Axis'),
       'yaxis_min'   => '',
       'yaxis_max'   => '',
+      'three_dimensional' => FALSE,
     ];
 
     // Sample data format.
diff --git a/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php b/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php
index 7703275..b722269 100644
--- a/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php
+++ b/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php
@@ -134,6 +134,9 @@ 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'];
 
     unset($form['display']['legend_position']['#parents']);
     $form['display']['legend_position']['#default_value'] = $this->configuration['legend_position'];
@@ -174,6 +177,7 @@ class ChartsBlock extends BlockBase {
     $this->configuration['legend_position'] = $form_state->getValue(['display','legend_position']);
     $this->configuration['colors'] = $form_state->getValue('colors');
     $this->configuration['background'] = $form_state->getValue(['display','background']);
+    $this->configuration['three_dimensional'] = $form_state->getValue(['display','three_dimensional']);
     $this->configuration['tooltips'] = $form_state->getValue(['display','tooltips']);
     $this->configuration['tooltips_use_html'] = $form_state->getValue('tooltips_use_html');
     $this->configuration['width'] = $form_state->getValue(['display','dimensions','width']);
@@ -206,6 +210,7 @@ class ChartsBlock extends BlockBase {
       'legend_position'=>$this->configuration['legend_position'],
       'colors'=>$this->configuration['colors'],
       'background'=>$this->configuration['background'],
+      'three_dimensional'=>$this->configuration['three_dimensional'],
       'tooltips'=>$this->configuration['tooltips'],
       'tooltips_use_html'=>$this->configuration['tooltips_use_html'],
       'width'=>$this->configuration['width'],
diff --git a/modules/charts_google/src/Charts/GoogleChartsRender.php b/modules/charts_google/src/Charts/GoogleChartsRender.php
index 9bdb634..b4df824 100644
--- a/modules/charts_google/src/Charts/GoogleChartsRender.php
+++ b/modules/charts_google/src/Charts/GoogleChartsRender.php
@@ -325,6 +325,11 @@ class GoogleChartsRender implements ChartsRenderInterface {
       $googleOptions->setHeight($options['height']);
     }
 
+    // Determines if chart is three-dimensional.
+    if (isset($options['three_dimensional'])) {
+      $googleOptions->setThreeDimensional($options['three_dimensional']);
+    }
+
     // 'legend' can be a string (for position) or an array with legend
     // properties: [position: 'top', textStyle: [color: 'blue', fontSize: 16]].
     if (isset($options['legend'])) {
diff --git a/modules/charts_google/src/Plugin/chart/GoogleCharts.php b/modules/charts_google/src/Plugin/chart/GoogleCharts.php
index 67d42cb..15751ba 100644
--- a/modules/charts_google/src/Plugin/chart/GoogleCharts.php
+++ b/modules/charts_google/src/Plugin/chart/GoogleCharts.php
@@ -334,6 +334,11 @@ class GoogleCharts extends AbstractChart {
       $googleOptions->setHeight($options['height']);
     }
 
+    // Determines if chart is three-dimensional.
+    if (isset($options['three_dimensional'])) {
+      $googleOptions->setThreeDimensional($options['three_dimensional']);
+    }
+
     // 'legend' can be a string (for position) or an array with legend
     // properties: [position: 'top', textStyle: [color: 'blue', fontSize: 16]].
     if (isset($options['legend'])) {
diff --git a/modules/charts_google/src/Settings/Google/GoogleOptions.php b/modules/charts_google/src/Settings/Google/GoogleOptions.php
index fee23fe..885affa 100644
--- a/modules/charts_google/src/Settings/Google/GoogleOptions.php
+++ b/modules/charts_google/src/Settings/Google/GoogleOptions.php
@@ -100,6 +100,13 @@ class GoogleOptions implements \JsonSerializable {
    */
   private $height;
 
+  /**
+  * 3D chart option.
+  *
+  * @var mixed
+  */
+  private $is3D;
+
   /**
    * Gets the title of the Material Chart. Only Material Charts support titles.
    *
@@ -367,6 +374,26 @@ class GoogleOptions implements \JsonSerializable {
     $this->height = $height;
   }
 
+  /**
+  * Gets three-dimensional chart option.
+  *
+  * @return mixed
+  *   3D option.
+  */
+  public function getThreeDimensional() {
+    return $this->is3D;
+  }
+
+  /**
+  * Sets three-dimensional chart option.
+  *
+  * @param mixed $threeDimensional
+  *   3D option.
+  */
+  public function setThreeDimensional($is3D) {
+    $this->is3D = $is3D;
+  }
+
   /**
    * Json Serialize.
    *
diff --git a/src/Form/ChartsConfigForm.php b/src/Form/ChartsConfigForm.php
index 5609507..220be73 100644
--- a/src/Form/ChartsConfigForm.php
+++ b/src/Form/ChartsConfigForm.php
@@ -115,6 +115,7 @@ class ChartsConfigForm extends ConfigFormBase {
       'legend_position'       => 'right',
       'colors'                => $this->chartsDefaultColors(),
       'background'            => '',
+      'three_dimensional'     => FALSE,
       'tooltips'              => TRUE,
       'tooltips_use_html'     => FALSE,
       'width'                 => NULL,
@@ -339,6 +340,19 @@ class ChartsConfigForm extends ConfigFormBase {
       '#parents'       => array_merge($parents, ['background']),
     ];
 
+    $form['display']['three_dimensional'] = [
+      '#title'         => t('Make chart three-dimensional (3D)'),
+      '#type'          => 'checkbox',
+      '#default_value' => $options['three_dimensional'],
+      '#parents'       => array_merge($parents, ['three_dimensional']),
+      '#attributes'    => [
+        'class'      => [
+          'chart-type-checkbox',
+          'container-inline',
+        ],
+      ],
+    ];
+
     $form['display']['dimensions'] = [
       '#title'          => $this->t('Dimensions'),
       '#theme_wrappers' => ['form_element'],
-- 
GitLab