Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: supporting bar race #607

Merged
merged 8 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Element.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -27,6 +27,7 @@ export interface ElementAnimateConfig {
delay?: number
easing?: AnimationEasing
done?: Function
during?: (percent: number) => void
/**
* If force animate
* Prevent stop animation and callback
Expand Down Expand Up @@ -1544,6 +1545,14 @@ function animateTo<T>(
if (!count) {
cfg.done && cfg.done();
}

// 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
// Incase any animator is done immediately when all animation properties are not changed
for (let i = 0; i < animators.length; i++) {
Expand Down
10 changes: 5 additions & 5 deletions src/animation/Animator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -35,7 +35,7 @@ function interpolate1DArray(
}
}

function interpolate2DArray(
export function interpolate2DArray(
out: NumberArray[],
p0: NumberArray[],
p1: NumberArray[],
Expand Down Expand Up @@ -665,7 +665,7 @@ class Track {


type DoneCallback = () => void;
type OnframeCallback<T> = (target: T, percent: number) => void;
export type OnframeCallback<T> = (target: T, percent: number) => void;

export type AnimationPropGetter<T> = (target: T, key: string) => InterpolatableType;
export type AnimationPropSetter<T> = (target: T, key: string, value: InterpolatableType) => void;
Expand Down
2 changes: 2 additions & 0 deletions src/graphic/Path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export interface PathProps extends DisplayableProps {

autoBatch?: boolean

__value?: (string | number)[] | (string | number)

buildPath?: (
ctx: PathProxy | CanvasRenderingContext2D,
shapeCfg: Dictionary<any>,
Expand Down