UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

45 lines 2.24 kB
export class AnimationPlanner { constructor(state, graphics, config, beforeExecute, afterExecute) { this.state = state, this.graphics = graphics, this.config = config || [], this.beforeExecute = beforeExecute, this.afterExecute = afterExecute; } execute(product, onComplete) { if (!this.graphics.length || !this.config.length) return void (null == onComplete || onComplete()); this.beforeExecute && this.beforeExecute(this.graphics); let completedCount = 0; const totalCount = this.graphics.length, onAnimationComplete = () => { completedCount++, completedCount >= totalCount && (this.afterExecute && this.afterExecute(this.graphics), null == onComplete || onComplete()); }; this.graphics.forEach((g => { if (!g) return void completedCount++; "exit" === this.state && (g.isExiting = !0); const animationConfig = this.config.length > 1 ? this.config.map((c => ({ name: this.state, animation: Object.assign(Object.assign({}, c), { customParameters: g.context }) }))) : { name: this.state, animation: Object.assign(Object.assign({}, this.config[0]), { customParameters: g.context }) }; g.applyAnimationState([ this.state ], [ animationConfig ], onAnimationComplete); })); } executeOnGroup(product, onComplete) { if (!this.graphics.length || !this.config.length || !product) return void (null == onComplete || onComplete()); this.beforeExecute && this.beforeExecute(this.graphics); const mainConfig = this.config[0], configArray = [ { name: this.state, animation: Object.assign({}, mainConfig) } ]; configArray.forEach((config => { config.animation.customParameters = (data, g) => g.context; })), product.applyAnimationState([ this.state ], configArray, (() => { this.afterExecute && this.afterExecute(this.graphics), null == onComplete || onComplete(); })); } } //# sourceMappingURL=animation-planner.js.map