From 101e62bfec70af67de54a36acd4e6499408b7f49 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Wed, 6 May 2020 15:11:30 +0800 Subject: [PATCH 1/5] feat(bar-race): add during callback --- src/Element.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Element.ts b/src/Element.ts index d16279c1e..0e54a9c6a 100644 --- a/src/Element.ts +++ b/src/Element.ts @@ -28,6 +28,7 @@ export interface ElementAnimateConfig { delay?: number easing?: AnimationEasing done?: Function + during?: Function /** * If force animate * Prevent stop animation and callback @@ -1148,11 +1149,19 @@ function animateTo( if (!count) { cfg.done && cfg.done(); } + + function during() { + if (typeof cfg.during === 'function') { + cfg.during(); + } + } + // Start after all animators created // Incase any animator is done immediately when all animation properties are not changed for (let i = 0; i < animators.length; i++) { animators[i] .done(done) + .during(during) .start(cfg.easing, cfg.force); } } From b9b0dbcb24f39d0426111093364d86210ab163ea Mon Sep 17 00:00:00 2001 From: Ovilia Date: Wed, 13 May 2020 14:35:19 +0800 Subject: [PATCH 2/5] WIP --- src/graphic/Path.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/graphic/Path.ts b/src/graphic/Path.ts index 74b56905c..f4251ba31 100644 --- a/src/graphic/Path.ts +++ b/src/graphic/Path.ts @@ -66,6 +66,8 @@ export interface PathProps extends DisplayableProps { autoBatch?: boolean + __value?: number + buildPath?: ( ctx: PathProxy | CanvasRenderingContext2D, shapeCfg: Dictionary, @@ -111,6 +113,8 @@ class Path extends Displayable { */ autoBatch: boolean + __value: number + private _rectWithStroke: BoundingRect protected _normalState: PathState From 1b003ed365844ac7b9007a8e8cd9444111689e88 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Thu, 18 Jun 2020 14:09:04 +0800 Subject: [PATCH 3/5] feat(bar-race): update types --- src/Element.ts | 4 ++-- src/animation/Animator.ts | 2 +- src/graphic/Path.ts | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Element.ts b/src/Element.ts index 469d12565..5963af74c 100644 --- a/src/Element.ts +++ b/src/Element.ts @@ -1527,9 +1527,9 @@ function animateTo( cfg.done && cfg.done(); } - function during() { + function during(target: T, percent: number) { if (typeof cfg.during === 'function') { - cfg.during(); + cfg.during(target, percent); } } diff --git a/src/animation/Animator.ts b/src/animation/Animator.ts index 9d796bd4f..92860e177 100644 --- a/src/animation/Animator.ts +++ b/src/animation/Animator.ts @@ -652,7 +652,7 @@ class Track { type DoneCallback = () => void; -type OnframeCallback = (target: T, percent: number) => void; +export type OnframeCallback = (target: T, percent: number) => void; export type AnimationPropGetter = (target: T, key: string) => InterpolatableType; export type AnimationPropSetter = (target: T, key: string, value: InterpolatableType) => void; diff --git a/src/graphic/Path.ts b/src/graphic/Path.ts index 0155cced8..66539ce2e 100644 --- a/src/graphic/Path.ts +++ b/src/graphic/Path.ts @@ -86,7 +86,7 @@ export interface PathProps extends DisplayableProps { autoBatch?: boolean - __value?: number + __value?: (string | number)[] | (string | number) buildPath?: ( ctx: PathProxy | CanvasRenderingContext2D, @@ -133,8 +133,6 @@ class Path extends Displayable { */ autoBatch: boolean - __value: number - private _rectWithStroke: BoundingRect protected _normalState: PathState From 31c34df8ea659fbc315c71f03338ef43bf655d76 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Thu, 18 Jun 2020 14:44:27 +0800 Subject: [PATCH 4/5] fix: during implement --- src/Element.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Element.ts b/src/Element.ts index 5963af74c..e19b326c6 100644 --- a/src/Element.ts +++ b/src/Element.ts @@ -1,6 +1,6 @@ import Transformable from './core/Transformable'; import { AnimationEasing } from './animation/easing'; -import Animator, {cloneValue} from './animation/Animator'; +import Animator, {cloneValue, OnframeCallback} from './animation/Animator'; import { ZRenderType } from './zrender'; import { Dictionary, ElementEventName, ZRRawEvent, BuiltinTextPosition, AllPropTypes, TextVerticalAlign, TextAlign, MapToType } from './core/types'; import Path from './graphic/Path'; @@ -27,7 +27,7 @@ export interface ElementAnimateConfig { delay?: number easing?: AnimationEasing done?: Function - during?: Function + during?: (percent: number) => void /** * If force animate * Prevent stop animation and callback @@ -1527,10 +1527,11 @@ function animateTo( cfg.done && cfg.done(); } - function during(target: T, percent: number) { - if (typeof cfg.during === 'function') { - cfg.during(target, percent); - } + // Adding during callback to the first animator + if (animators.length > 0 && typeof cfg.during === 'function') { + animators[0].during((target, percent) => { + cfg.during(percent); + }); } // Start after all animators created @@ -1538,7 +1539,6 @@ function animateTo( for (let i = 0; i < animators.length; i++) { animators[i] .done(done) - .during(during) .start(cfg.easing, cfg.force); } From 95147f06c80b6c93f3c141556bc83dbfc2f4a73d Mon Sep 17 00:00:00 2001 From: Ovilia Date: Mon, 22 Jun 2020 14:37:43 +0800 Subject: [PATCH 5/5] fix(bar-race): export interpolate methods --- src/animation/Animator.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/animation/Animator.ts b/src/animation/Animator.ts index 670188ef3..51b6fc6e2 100644 --- a/src/animation/Animator.ts +++ b/src/animation/Animator.ts @@ -14,15 +14,15 @@ type InterpolatableType = string | number | NumberArray | NumberArray[]; const arraySlice = Array.prototype.slice; -function interpolateNumber(p0: number, p1: number, percent: number): number { +export function interpolateNumber(p0: number, p1: number, percent: number): number { return (p1 - p0) * percent + p0; } -function step(p0: any, p1: any, percent: number): any { +export function step(p0: any, p1: any, percent: number): any { return percent > 0.5 ? p1 : p0; } -function interpolate1DArray( +export function interpolate1DArray( out: NumberArray, p0: NumberArray, p1: NumberArray, @@ -35,7 +35,7 @@ function interpolate1DArray( } } -function interpolate2DArray( +export function interpolate2DArray( out: NumberArray[], p0: NumberArray[], p1: NumberArray[],