mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
Replace onEvent
by before/afterEvent
This commit is contained in:
parent
1e9224d49c
commit
7205ff5e2a
@ -439,12 +439,9 @@ Plugins should implement the `IPlugin` interface:
|
||||
|
||||
destroy: function(chartInstance) { }
|
||||
|
||||
/**
|
||||
* Called when an event occurs on the chart
|
||||
* @param e {Core.Event} the Chart.js wrapper around the native event. e.native is the original event
|
||||
* @return {Boolean} true if the chart is changed and needs to re-render
|
||||
*/
|
||||
onEvent: function(chartInstance, e) {}
|
||||
// Called when an event occurs on the chart
|
||||
beforeEvent: function(chartInstance, event) {}
|
||||
afterEvent: function(chartInstance, event) {}
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -664,7 +664,10 @@ module.exports = function(Chart) {
|
||||
eventHandler: function(e) {
|
||||
var me = this;
|
||||
var tooltip = me.tooltip;
|
||||
var hoverOptions = me.options.hover;
|
||||
|
||||
if (plugins.notify(me, 'beforeEvent', [e]) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Buffer any update calls so that renders do not occur
|
||||
me._bufferedRender = true;
|
||||
@ -672,7 +675,8 @@ module.exports = function(Chart) {
|
||||
|
||||
var changed = me.handleEvent(e);
|
||||
changed |= tooltip && tooltip.handleEvent(e);
|
||||
changed |= plugins.notify(me, 'onEvent', [e]);
|
||||
|
||||
plugins.notify(me, 'afterEvent', [e]);
|
||||
|
||||
var bufferedRequest = me._bufferedRequest;
|
||||
if (bufferedRequest) {
|
||||
@ -684,7 +688,7 @@ module.exports = function(Chart) {
|
||||
|
||||
// We only need to render at this point. Updating will cause scales to be
|
||||
// recomputed generating flicker & using more memory than necessary.
|
||||
me.render(hoverOptions.animationDuration, true);
|
||||
me.render(me.options.hover.animationDuration, true);
|
||||
}
|
||||
|
||||
me._bufferedRender = false;
|
||||
|
@ -526,7 +526,7 @@ module.exports = function(Chart) {
|
||||
delete chartInstance.legend;
|
||||
}
|
||||
},
|
||||
onEvent: function(chartInstance, e) {
|
||||
afterEvent: function(chartInstance, e) {
|
||||
var legend = chartInstance.legend;
|
||||
if (legend) {
|
||||
legend.handleEvent(e);
|
||||
|
@ -274,6 +274,22 @@ module.exports = function(Chart) {
|
||||
* @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
|
||||
* @param {Object} options - The plugin options.
|
||||
*/
|
||||
/**
|
||||
* @method IPlugin#beforeEvent
|
||||
* @desc Called before processing the specified `event`. If any plugin returns `false`,
|
||||
* the event will be discarded.
|
||||
* @param {Chart.Controller} chart - The chart instance.
|
||||
* @param {IEvent} event - The event object.
|
||||
* @param {Object} options - The plugin options.
|
||||
*/
|
||||
/**
|
||||
* @method IPlugin#afterEvent
|
||||
* @desc Called after the `event` has been consumed. Note that this hook
|
||||
* will not be called if the `event` has been previously discarded.
|
||||
* @param {Chart.Controller} chart - The chart instance.
|
||||
* @param {IEvent} event - The event object.
|
||||
* @param {Object} options - The plugin options.
|
||||
*/
|
||||
/**
|
||||
* @method IPlugin#resize
|
||||
* @desc Called after the chart as been resized.
|
||||
|
@ -320,7 +320,7 @@ describe('Platform.dom', function() {
|
||||
it('should notify plugins about events', function() {
|
||||
var notifiedEvent;
|
||||
var plugin = {
|
||||
onEvent: function(chart, e) {
|
||||
afterEvent: function(chart, e) {
|
||||
notifiedEvent = e;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user