From: Jukka Kurkela Date: Wed, 30 Dec 2020 13:31:30 +0000 (+0200) Subject: Fix small bugs when animations are disabled (#8253) X-Git-Tag: v3.0.0-beta.8~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e43f787de354427a0ec96c505e8934072702ad9;p=thirdparty%2FChart.js.git Fix small bugs when animations are disabled (#8253) * Fix small bugs when animations are disabled * Update test --- diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 54ddd2f8d..d8328313d 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -1002,13 +1002,13 @@ class Chart { /** * @private */ - _updateHoverStyles(active, lastActive) { + _updateHoverStyles(active, lastActive, replay) { 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); + const activated = replay ? active : diff(active, lastActive); if (deactivated.length) { me.updateHoverStyle(deactivated, hoverOptions.mode, false); @@ -1093,7 +1093,7 @@ class Chart { changed = !_elementsEqual(active, lastActive); if (changed || replay) { me._active = active; - me._updateHoverStyles(active, lastActive); + me._updateHoverStyles(active, lastActive, replay); } return changed; diff --git a/src/core/core.element.js b/src/core/core.element.js index b0927ce99..aefa1d918 100644 --- a/src/core/core.element.js +++ b/src/core/core.element.js @@ -37,7 +37,7 @@ export default class Element { } const ret = {}; props.forEach(prop => { - ret[prop] = anims[prop] && anims[prop].active ? anims[prop]._to : me[prop]; + ret[prop] = anims[prop] && anims[prop].active() ? anims[prop]._to : me[prop]; }); return ret; } diff --git a/src/helpers/helpers.extras.js b/src/helpers/helpers.extras.js index 5bc7748c9..b140cdd7f 100644 --- a/src/helpers/helpers.extras.js +++ b/src/helpers/helpers.extras.js @@ -65,5 +65,5 @@ export const _alignStartEnd = (align, start, end) => align === 'start' ? start : */ export function _coordsAnimated(element) { const anims = element && element.$animations; - return anims && ((anims.x && anims.x.active) || (anims.y && anims.y.active)); + return anims && ((anims.x && anims.x.active()) || (anims.y && anims.y.active())); } diff --git a/test/specs/core.element.tests.js b/test/specs/core.element.tests.js index f312f3df6..e3f0f1aba 100644 --- a/test/specs/core.element.tests.js +++ b/test/specs/core.element.tests.js @@ -8,7 +8,7 @@ describe('Chart.element', function() { expect(elem.getProps(['x', 'y'])).toEqual(jasmine.objectContaining({x: 10, y: 1.5})); expect(elem.getProps(['x', 'y'], true)).toEqual(jasmine.objectContaining({x: 10, y: 1.5})); - elem.$animations = {x: {active: true, _to: 20}}; + elem.$animations = {x: {active: () => true, _to: 20}}; expect(elem.getProps(['x', 'y'])).toEqual(jasmine.objectContaining({x: 10, y: 1.5})); expect(elem.getProps(['x', 'y'], true)).toEqual(jasmine.objectContaining({x: 20, y: 1.5})); });