Use apply instead of call so that the animation easing can be passed to the draw callbacks

This commit is contained in:
Evert Timberg 2016-04-17 12:25:47 -04:00
parent 7fa4c4c1b8
commit d131e7d07a
3 changed files with 9 additions and 9 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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);
});