]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Hover: only update styles of changed elements (#8185)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Thu, 17 Dec 2020 20:18:02 +0000 (22:18 +0200)
committerGitHub <noreply@github.com>
Thu, 17 Dec 2020 20:18:02 +0000 (15:18 -0500)
src/core/core.controller.js

index 80632579d8054915eea249056aebd97a08b50912..8fa07ec85c45818ad916a9e83db40540c54d9110 100644 (file)
@@ -994,15 +994,16 @@ class Chart {
                const me = this;
                const options = me.options || {};
                const hoverOptions = options.hover;
+               const diff = (a, b) => a.filter(x => !b.some(y => x.datasetIndex === y.datasetIndex && x.index === y.index));
+               const deactivated = diff(lastActive, active);
+               const activated = diff(active, lastActive);
 
-               // Remove styling for last active (even if it may still be active)
-               if (lastActive.length) {
-                       me.updateHoverStyle(lastActive, hoverOptions.mode, false);
+               if (deactivated.length) {
+                       me.updateHoverStyle(deactivated, hoverOptions.mode, false);
                }
 
-               // Built-in hover styling
-               if (active.length && hoverOptions.mode) {
-                       me.updateHoverStyle(active, hoverOptions.mode, true);
+               if (activated.length && hoverOptions.mode) {
+                       me.updateHoverStyle(activated, hoverOptions.mode, true);
                }
        }