From b10d99401746129c90b7d9289aa28de3f1844ab7 Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Thu, 17 Dec 2020 22:18:02 +0200 Subject: [PATCH] Hover: only update styles of changed elements (#8185) --- src/core/core.controller.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 80632579d..8fa07ec85 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -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); } } -- 2.47.2