From: Jukka Kurkela Date: Thu, 17 Dec 2020 20:18:02 +0000 (+0200) Subject: Hover: only update styles of changed elements (#8185) X-Git-Tag: v3.0.0-beta.8~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b10d99401746129c90b7d9289aa28de3f1844ab7;p=thirdparty%2FChart.js.git Hover: only update styles of changed elements (#8185) --- 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); } }