MCPcopy Create free account
hub / github.com/chartjs/Chart.js / Animation

Class Animation

src/core/core.animation.js:27–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25};
26
27export default class Animation {
28 constructor(cfg, target, prop, to) {
29 const currentValue = target[prop];
30
31 to = resolve([cfg.to, to, currentValue, cfg.from]);
32 const from = resolve([cfg.from, currentValue, to]);
33
34 this._active = true;
35 this._fn = cfg.fn || interpolators[cfg.type || typeof from];
36 this._easing = effects[cfg.easing] || effects.linear;
37 this._start = Math.floor(Date.now() + (cfg.delay || 0));
38 this._duration = this._total = Math.floor(cfg.duration);
39 this._loop = !!cfg.loop;
40 this._target = target;
41 this._prop = prop;
42 this._from = from;
43 this._to = to;
44 this._promises = undefined;
45 }
46
47 active() {
48 return this._active;
49 }
50
51 update(cfg, to, date) {
52 if (this._active) {
53 this._notify(false);
54
55 const currentValue = this._target[this._prop];
56 const elapsed = date - this._start;
57 const remain = this._duration - elapsed;
58 this._start = date;
59 this._duration = Math.floor(Math.max(remain, cfg.duration));
60 this._total += elapsed;
61 this._loop = !!cfg.loop;
62 this._to = resolve([cfg.to, to, currentValue, cfg.from]);
63 this._from = resolve([cfg.from, currentValue, to]);
64 }
65 }
66
67 cancel() {
68 if (this._active) {
69 // update current evaluated value, for smoother animations
70 this.tick(Date.now());
71 this._active = false;
72 this._notify(false);
73 }
74 }
75
76 tick(date) {
77 const elapsed = date - this._start;
78 const duration = this._duration;
79 const prop = this._prop;
80 const from = this._from;
81 const loop = this._loop;
82 const to = this._to;
83 let factor;
84

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected