From: Evert Timberg Date: Sun, 17 Apr 2016 16:25:47 +0000 (-0400) Subject: Use apply instead of call so that the animation easing can be passed to the draw... X-Git-Tag: 2.1.0~68^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d131e7d07a3969d644fe3f2f36eac28e14a3aa7a;p=thirdparty%2FChart.js.git Use apply instead of call so that the animation easing can be passed to the draw callbacks --- diff --git a/src/core/core.controller.js b/src/core/core.controller.js index b6dad13b9..dfb62a331 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -44,7 +44,7 @@ module.exports = function(Chart) { initialize: function initialize() { // Before init plugin notification - Chart.pluginService.notifyPlugins('beforeInit', this); + Chart.pluginService.notifyPlugins('beforeInit', [this]); this.bindEvents(); @@ -60,7 +60,7 @@ module.exports = function(Chart) { this.update(); // After init plugin notification - Chart.pluginService.notifyPlugins('afterInit', this); + Chart.pluginService.notifyPlugins('afterInit', [this]); return this; }, @@ -242,7 +242,7 @@ module.exports = function(Chart) { }, update: function update(animationDuration, lazy) { - Chart.pluginService.notifyPlugins('beforeUpdate', this); + Chart.pluginService.notifyPlugins('beforeUpdate', [this]); // In case the entire data object changed this.tooltip._data = this.data; @@ -268,7 +268,7 @@ module.exports = function(Chart) { }); this.render(animationDuration, lazy); - Chart.pluginService.notifyPlugins('afterUpdate', this); + Chart.pluginService.notifyPlugins('afterUpdate', [this]); }, render: function render(duration, lazy) { @@ -305,7 +305,7 @@ module.exports = function(Chart) { var easingDecimal = ease || 1; this.clear(); - Chart.pluginService.notifyPlugins('beforeDraw', this); + Chart.pluginService.notifyPlugins('beforeDraw', [this, easingDecimal]); // Draw all the scales helpers.each(this.boxes, function(box) { @@ -334,7 +334,7 @@ module.exports = function(Chart) { // Finally draw the tooltip this.tooltip.transition(easingDecimal).draw(); - Chart.pluginService.notifyPlugins('afterDraw', this); + Chart.pluginService.notifyPlugins('afterDraw', [this, easingDecimal]); }, // Get the single element that was clicked on diff --git a/src/core/core.plugin.js b/src/core/core.plugin.js index c98cef15a..78f5fe988 100644 --- a/src/core/core.plugin.js +++ b/src/core/core.plugin.js @@ -22,10 +22,10 @@ module.exports = function(Chart) { }, // Iterate over all plugins - notifyPlugins: function(method, chartInstance, scope) { + notifyPlugins: function(method, args, scope) { helpers.each(Chart.plugins, function(plugin) { if (plugin[method] && typeof plugin[method] === 'function') { - plugin[method].call(scope, chartInstance); + plugin[method].apply(scope, args); } }, scope); } diff --git a/test/core.plugin.tests.js b/test/core.plugin.tests.js index 4f59c63cd..5a6891071 100644 --- a/test/core.plugin.tests.js +++ b/test/core.plugin.tests.js @@ -36,7 +36,7 @@ describe('Test the plugin system', function() { }; Chart.pluginService.register(myplugin); - Chart.pluginService.notifyPlugins('trigger', { count: 10 }); + Chart.pluginService.notifyPlugins('trigger', [{ count: 10 }]); expect(myplugin.count).toBe(10); });