| 10 | * Note: class is export for typedoc |
| 11 | */ |
| 12 | export class Animator { |
| 13 | constructor() { |
| 14 | this._request = null; |
| 15 | this._charts = new Map(); |
| 16 | this._running = false; |
| 17 | this._lastDate = undefined; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * @private |
| 22 | */ |
| 23 | _notify(chart, anims, date, type) { |
| 24 | const callbacks = anims.listeners[type]; |
| 25 | const numSteps = anims.duration; |
| 26 | |
| 27 | callbacks.forEach(fn => fn({ |
| 28 | chart, |
| 29 | initial: anims.initial, |
| 30 | numSteps, |
| 31 | currentStep: Math.min(date - anims.start, numSteps) |
| 32 | })); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @private |
| 37 | */ |
| 38 | _refresh() { |
| 39 | if (this._request) { |
| 40 | return; |
| 41 | } |
| 42 | this._running = true; |
| 43 | |
| 44 | this._request = requestAnimFrame.call(window, () => { |
| 45 | this._update(); |
| 46 | this._request = null; |
| 47 | |
| 48 | if (this._running) { |
| 49 | this._refresh(); |
| 50 | } |
| 51 | }); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @private |
| 56 | */ |
| 57 | _update(date = Date.now()) { |
| 58 | let remaining = 0; |
| 59 | |
| 60 | this._charts.forEach((anims, chart) => { |
| 61 | if (!anims.running || !anims.items.length) { |
| 62 | return; |
| 63 | } |
| 64 | const items = anims.items; |
| 65 | let i = items.length - 1; |
| 66 | let draw = false; |
| 67 | let item; |
| 68 | |
| 69 | for (; i >= 0; --i) { |
nothing calls this directly
no outgoing calls
no test coverage detected