| 4 | import {isArray, isObject} from '../helpers/helpers.core.js'; |
| 5 | |
| 6 | export default class Animations { |
| 7 | constructor(chart, config) { |
| 8 | this._chart = chart; |
| 9 | this._properties = new Map(); |
| 10 | this.configure(config); |
| 11 | } |
| 12 | |
| 13 | configure(config) { |
| 14 | if (!isObject(config)) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | const animationOptions = Object.keys(defaults.animation); |
| 19 | const animatedProps = this._properties; |
| 20 | |
| 21 | Object.getOwnPropertyNames(config).forEach(key => { |
| 22 | const cfg = config[key]; |
| 23 | if (!isObject(cfg)) { |
| 24 | return; |
| 25 | } |
| 26 | const resolved = {}; |
| 27 | for (const option of animationOptions) { |
| 28 | resolved[option] = cfg[option]; |
| 29 | } |
| 30 | |
| 31 | (isArray(cfg.properties) && cfg.properties || [key]).forEach((prop) => { |
| 32 | if (prop === key || !animatedProps.has(prop)) { |
| 33 | animatedProps.set(prop, resolved); |
| 34 | } |
| 35 | }); |
| 36 | }); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Utility to handle animation of `options`. |
| 41 | * @private |
| 42 | */ |
| 43 | _animateOptions(target, values) { |
| 44 | const newOptions = values.options; |
| 45 | const options = resolveTargetOptions(target, newOptions); |
| 46 | if (!options) { |
| 47 | return []; |
| 48 | } |
| 49 | |
| 50 | const animations = this._createAnimations(options, newOptions); |
| 51 | if (newOptions.$shared) { |
| 52 | // Going to shared options: |
| 53 | // After all animations are done, assign the shared options object to the element |
| 54 | // So any new updates to the shared options are observed |
| 55 | awaitAll(target.options.$animations, newOptions).then(() => { |
| 56 | target.options = newOptions; |
| 57 | }, () => { |
| 58 | // rejected, noop |
| 59 | }); |
| 60 | } |
| 61 | |
| 62 | return animations; |
| 63 | } |
nothing calls this directly
no outgoing calls
no test coverage detected