From 265e113117de55546695907252cfc724441afad9 Mon Sep 17 00:00:00 2001 From: enkimatt Date: Thu, 28 May 2015 13:22:57 -0700 Subject: [PATCH 1/2] updated 'update' function. added the ability to pass a new set of chart options in the update method, useful for changing colors while updating, ect.. --- src/easypiechart.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/easypiechart.js b/src/easypiechart.js index 0dc3822..61524c6 100644 --- a/src/easypiechart.js +++ b/src/easypiechart.js @@ -99,10 +99,24 @@ var EasyPieChart = function(el, opts) { /** * Update the value of the chart * @param {number} newValue Number between 0 and 100 + * @param {newOptions} newOptions chart options * @return {object} Instance of the plugin for method chaining */ - this.update = function(newValue) { - newValue = parseFloat(newValue); + this.update = function(newValue, newOptions) { + newValue = parseFloat(newValue); + console.log(newOptions); + if (newOptions != null) { + // merge user options into default options + for (var i in defaultOptions) { + if (defaultOptions.hasOwnProperty(i)) { + options[i] = newOptions && typeof (newOptions[i]) !== 'undefined' ? newOptions[i] : defaultOptions[i]; + if (typeof (options[i]) === 'function') { + options[i] = options[i].bind(this); + } + } + } + } + if (options.animate.enabled) { this.renderer.animate(currentValue, newValue); } else { From 8d864c1b8a236de8d44a7d08f36e7ae302822149 Mon Sep 17 00:00:00 2001 From: enkimatt Date: Thu, 28 May 2015 13:41:50 -0700 Subject: [PATCH 2/2] Update easypiechart.js --- src/easypiechart.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/easypiechart.js b/src/easypiechart.js index 61524c6..f7983f8 100644 --- a/src/easypiechart.js +++ b/src/easypiechart.js @@ -97,25 +97,15 @@ var EasyPieChart = function(el, opts) { }.bind(this); /** - * Update the value of the chart + * Update the chart value and options * @param {number} newValue Number between 0 and 100 * @param {newOptions} newOptions chart options * @return {object} Instance of the plugin for method chaining */ this.update = function(newValue, newOptions) { newValue = parseFloat(newValue); - console.log(newOptions); - if (newOptions != null) { - // merge user options into default options - for (var i in defaultOptions) { - if (defaultOptions.hasOwnProperty(i)) { - options[i] = newOptions && typeof (newOptions[i]) !== 'undefined' ? newOptions[i] : defaultOptions[i]; - if (typeof (options[i]) === 'function') { - options[i] = options[i].bind(this); - } - } - } - } + + this.setOptions(newOptions); if (options.animate.enabled) { this.renderer.animate(currentValue, newValue); @@ -126,7 +116,16 @@ var EasyPieChart = function(el, opts) { return this; }.bind(this); - /** + /** + * Update options + * @param newOptions + * @returns {EasyPieChart} + */ + this.setOptions = function (newOptions) { + $.extend(true, options, newOptions); + return this; + }; + /** * Disable animation * @return {object} Instance of the plugin for method chaining */