]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix small bugs when animations are disabled (#8253)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Wed, 30 Dec 2020 13:31:30 +0000 (15:31 +0200)
committerGitHub <noreply@github.com>
Wed, 30 Dec 2020 13:31:30 +0000 (08:31 -0500)
* Fix small bugs when animations are disabled
* Update test

src/core/core.controller.js
src/core/core.element.js
src/helpers/helpers.extras.js
test/specs/core.element.tests.js

index 54ddd2f8d018520290cb8e5eb9de561e37666aa7..d8328313de4648381c124b99f0b788e2bd47ec97 100644 (file)
@@ -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;
index b0927ce994b923c380eaa0995c433c773d6fc8bb..aefa1d918d4150cd10494bbade3364edf030091e 100644 (file)
@@ -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;
        }
index 5bc7748c9d7bbf6b082e8f83e629621a150a5c79..b140cdd7f69e1221ae6418a1cd467d995737c3f2 100644 (file)
@@ -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()));
 }
index f312f3df6cf63233e7bd86a5fbcf113b1e568a2f..e3f0f1aba55e61e9698469985a8d7d66053d5a1f 100644 (file)
@@ -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}));
                });