Fix small bugs when animations are disabled (#8253)

* Fix small bugs when animations are disabled
* Update test
This commit is contained in:
Jukka Kurkela 2020-12-30 15:31:30 +02:00 committed by GitHub
parent c2091fc77d
commit 2e43f787de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 6 deletions

View 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;

View 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;
}

View 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()));
}

View 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}));
});