]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Tooltip: Render when animations are disabled (#8252)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Wed, 30 Dec 2020 13:33:30 +0000 (15:33 +0200)
committerGitHub <noreply@github.com>
Wed, 30 Dec 2020 13:33:30 +0000 (08:33 -0500)
docs/docs/getting-started/v3-migration.md
src/core/core.controller.js
src/plugins/plugin.tooltip.js
types/index.esm.d.ts

index 4e792434f14389565e7145a679e17295d69ae2ad..1877fd60faa349e221ad8b5e3c5944f0e557024a 100644 (file)
@@ -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.
index d8328313de4648381c124b99f0b788e2bd47ec97..8fdcda2b4770dcf73b33a09a7f6f093e593d857b 100644 (file)
@@ -1035,7 +1035,7 @@ class Chart {
                args.cancellable = false;
                me.notifyPlugins('afterEvent', args);
 
-               if (changed) {
+               if (changed || args.changed) {
                        me.render();
                }
 
index 15f40fb52601b75941fec33bff85dc8a9565d26a..422069d0109e087d067da4d203e6022edf8cb405 100644 (file)
@@ -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;
+                       }
                }
        },
 
index 784c09de97c0378b99536af5b041d3b1e25d4ddb..081040395ff22e7c9b8987c523879bcd2c046a9d 100644 (file)
@@ -975,10 +975,11 @@ export interface Plugin<O = {}> 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.