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) {}
}
```
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;
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) {
// 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;
delete chartInstance.legend;
}
},
- onEvent: function(chartInstance, e) {
+ afterEvent: function(chartInstance, e) {
var legend = chartInstance.legend;
if (legend) {
legend.handleEvent(e);
* @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.
it('should notify plugins about events', function() {
var notifiedEvent;
var plugin = {
- onEvent: function(chart, e) {
+ afterEvent: function(chart, e) {
notifiedEvent = e;
}
};