diff --git a/docs/docs/getting-started/v3-migration.md b/docs/docs/getting-started/v3-migration.md index 4e792434f..1877fd60f 100644 --- a/docs/docs/getting-started/v3-migration.md +++ b/docs/docs/getting-started/v3-migration.md @@ -504,3 +504,4 @@ All helpers are now exposed in a flat hierarchy, e.g., `Chart.helpers.canvas.cli * `afterEvent` and `beforeEvent` now receive a wrapped `event` as the `event` property of the second argument. The native event is available via `args.event.native`. * Initial `resize` is no longer silent. Meaning that `resize` event can fire between `beforeInit` and `afterInit` * New hooks: `install`, `start`, `stop`, and `uninstall` +* `afterEvent` should notify about changes that need a render by setting `args.changed` to true. Because the `args` are shared with all plugins, it should only be set to true and not false. diff --git a/src/core/core.controller.js b/src/core/core.controller.js index d8328313d..8fdcda2b4 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -1035,7 +1035,7 @@ class Chart { args.cancellable = false; me.notifyPlugins('afterEvent', args); - if (changed) { + if (changed || args.changed) { me.render(); } diff --git a/src/plugins/plugin.tooltip.js b/src/plugins/plugin.tooltip.js index 15f40fb52..422069d01 100644 --- a/src/plugins/plugin.tooltip.js +++ b/src/plugins/plugin.tooltip.js @@ -1089,7 +1089,10 @@ export default { if (chart.tooltip) { // If the event is replayed from `update`, we should evaluate with the final positions. const useFinalPosition = args.replay; - chart.tooltip.handleEvent(args.event, useFinalPosition); + if (chart.tooltip.handleEvent(args.event, useFinalPosition)) { + // notify chart about the change, so it will render + args.changed = true; + } } }, diff --git a/types/index.esm.d.ts b/types/index.esm.d.ts index 784c09de9..081040395 100644 --- a/types/index.esm.d.ts +++ b/types/index.esm.d.ts @@ -975,10 +975,11 @@ export interface Plugin extends ExtendedPlugin { * @param {Chart} chart - The chart instance. * @param {object} args - The call arguments. * @param {ChartEvent} args.event - The event object. - * @param {boolean} replay - True if this event is replayed from `Chart.update` + * @param {boolean} args.replay - True if this event is replayed from `Chart.update` + * @param {boolean} [args.changed] - Set to true if the plugin needs a render. Should only be changed to true, because this args object is passed through all plugins. * @param {object} options - The plugin options. */ - afterEvent?(chart: Chart, args: { event: ChartEvent, replay: boolean }, options: O): void; + afterEvent?(chart: Chart, args: { event: ChartEvent, replay: boolean, changed?: boolean }, options: O): void; /** * @desc Called after the chart as been resized. * @param {Chart} chart - The chart instance.