From 57cee77895ff57ddfcb35a63645dc3636b248d55 Mon Sep 17 00:00:00 2001
From: Russell England <russellengland@gmail.com>
Date: Thu, 13 Oct 2016 11:17:53 +0100
Subject: [PATCH] charts: Add support for cutoutpercentage in doughnut charts

---
 lib/amd/src/chart_output_chartjs.js |  5 +++++
 lib/amd/src/chart_pie.js            | 27 +++++++++++++++++++++++++++
 lib/classes/chart_pie.php           | 23 +++++++++++++++++++++++
 3 files changed, 55 insertions(+)

diff --git a/lib/amd/src/chart_output_chartjs.js b/lib/amd/src/chart_output_chartjs.js
index 9665a37..669bbf7 100644
--- a/lib/amd/src/chart_output_chartjs.js
+++ b/lib/amd/src/chart_output_chartjs.js
@@ -187,6 +187,11 @@ define([
             }
         };
 
+        if (this._chart.getType() === Pie.prototype.TYPE && this._chart.getDoughnut() === true
+                && this._chart.getCutoutPercentage() !== null) {
+            config.options.cutoutPercentage = this._chart.getCutoutPercentage();
+        }
+
         this._chart.getXAxes().forEach(function(axis, i) {
             var axisLabels = axis.getLabels();
 
diff --git a/lib/amd/src/chart_pie.js b/lib/amd/src/chart_pie.js
index bce2ef2..59c0431 100644
--- a/lib/amd/src/chart_pie.js
+++ b/lib/amd/src/chart_pie.js
@@ -46,10 +46,19 @@ define(['core/chart_base'], function(Base) {
      */
     Pie.prototype._doughnut = null;
 
+    /**
+     * The cut out percentage of the hole in the doughnut.
+     *
+     * @protected
+     * @type {String}
+     */
+    Pie.prototype._cutoutPercentage = null;
+
     /** @override */
     Pie.prototype.create = function(Klass, data) {
         var chart = Base.prototype.create.apply(this, arguments);
         chart.setDoughnut(data.doughnut);
+        chart.setCutoutPercentage(data.cutoutPercentage);
         return chart;
     };
 
@@ -90,6 +99,24 @@ define(['core/chart_base'], function(Base) {
     };
 
     /**
+     * Get the size of the hole in the doughnut.
+     *
+     * @return {Number}
+     */
+    Pie.prototype.getCutoutPercentage = function() {
+        return this._cutoutPercentage;
+    };
+
+    /**
+     * Set the size of the hole in the doughnut.
+     *
+     * @param {Number}
+     */
+    Pie.prototype.setCutoutPercentage = function(cutoutPercentage) {
+        this._cutoutPercentage = cutoutPercentage;
+    };
+
+    /**
      * Validate a series.
      *
      * Overrides parent implementation to validate that there is only
diff --git a/lib/classes/chart_pie.php b/lib/classes/chart_pie.php
index b4c2041..2ddc7ac 100644
--- a/lib/classes/chart_pie.php
+++ b/lib/classes/chart_pie.php
@@ -37,6 +37,9 @@ class chart_pie extends chart_base {
     /** @var bool $doughnut Whether the chart should be displayed as doughnut. */
     protected $doughnut = null;
 
+    /** @var int $cutoutpercentage size of the hole in the doughnut */
+    protected $cutoutpercentage = null;
+
     /**
      * Get parent JSON and add specific pie related attributes and values.
      *
@@ -45,6 +48,7 @@ class chart_pie extends chart_base {
     public function jsonSerialize() { // @codingStandardsIgnoreLine (CONTRIB-6469).
         $data = parent::jsonSerialize();
         $data['doughnut'] = $this->get_doughnut();
+        $data['cutoutPercentage'] = $this->get_cutoutpercentage();
         return $data;
     }
 
@@ -65,4 +69,23 @@ class chart_pie extends chart_base {
     public function set_doughnut($doughnut) {
         $this->doughnut = $doughnut;
     }
+
+    /**
+     * Get the size of the hole in the doughnut.
+     *
+     * @return bool
+     */
+    public function get_cutoutpercentage() {
+        return $this->cutoutpercentage;
+    }
+
+    /**
+     * Set the size of the hole in the doughnut.
+     *
+     * @param int $cutoutpercentage
+     */
+    public function set_cutoutpercentage($cutoutpercentage) {
+        $this->cutoutpercentage = $cutoutpercentage;
+    }
+
 }
-- 
1.9.1

