mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Update running animations (#7196)
This commit is contained in:
parent
da6056c8d1
commit
b73b8f9863
@ -42,6 +42,19 @@ export default class Animation {
|
|||||||
return this._active;
|
return this._active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update(cfg, to, date) {
|
||||||
|
const me = this;
|
||||||
|
if (me._active) {
|
||||||
|
const currentValue = me._target[me._prop];
|
||||||
|
const elapsed = date - me._start;
|
||||||
|
const remain = me._duration - elapsed;
|
||||||
|
me._start = date;
|
||||||
|
me._duration = Math.floor(Math.max(remain, cfg.duration));
|
||||||
|
me._to = resolve([cfg.to, to, currentValue, cfg.from]);
|
||||||
|
me._from = resolve([cfg.from, currentValue, to]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cancel() {
|
cancel() {
|
||||||
const me = this;
|
const me = this;
|
||||||
if (me._active) {
|
if (me._active) {
|
||||||
|
|||||||
@ -147,6 +147,7 @@ export default class Animations {
|
|||||||
const animations = [];
|
const animations = [];
|
||||||
const running = target.$animations || (target.$animations = {});
|
const running = target.$animations || (target.$animations = {});
|
||||||
const props = Object.keys(values);
|
const props = Object.keys(values);
|
||||||
|
const date = Date.now();
|
||||||
let i;
|
let i;
|
||||||
|
|
||||||
for (i = props.length - 1; i >= 0; --i) {
|
for (i = props.length - 1; i >= 0; --i) {
|
||||||
@ -161,11 +162,17 @@ export default class Animations {
|
|||||||
}
|
}
|
||||||
const value = values[prop];
|
const value = values[prop];
|
||||||
let animation = running[prop];
|
let animation = running[prop];
|
||||||
if (animation) {
|
|
||||||
animation.cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
const cfg = animatedProps.get(prop);
|
const cfg = animatedProps.get(prop);
|
||||||
|
|
||||||
|
if (animation) {
|
||||||
|
if (cfg && animation.active()) {
|
||||||
|
// There is an existing active animation, let's update that
|
||||||
|
animation.update(cfg, value, date);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
animation.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!cfg || !cfg.duration) {
|
if (!cfg || !cfg.duration) {
|
||||||
// not animated, set directly to new value
|
// not animated, set directly to new value
|
||||||
target[prop] = value;
|
target[prop] = value;
|
||||||
|
|||||||
@ -343,7 +343,6 @@ export default class Chart {
|
|||||||
options.onResize(me, newSize);
|
options.onResize(me, newSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
me.stop();
|
|
||||||
me.update('resize');
|
me.update('resize');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user