Skip to content

Commit

Permalink
feat: 支持 Interval 和 TextGuide 的 animation 透传 (#1255)
Browse files Browse the repository at this point in the history
  • Loading branch information
El-Chiang committed Nov 16, 2021
1 parent 7662cc7 commit 05abb88
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 18 deletions.
13 changes: 11 additions & 2 deletions packages/f2/src/canvas/animation/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ export type InterpolateFunction = (t: number) => any;

export interface Animation {
// 缓动函数
easing: string | EasingFunction;
easing?: string | EasingFunction;
duration: number;
delay?: number;
property: string[];
property?: string[];
// 裁剪区动画
clip?: any;
// start 的 attrs
Expand All @@ -17,3 +17,12 @@ export interface Animation {
onFrame?: any;
onEnd?: any;
}

/**
* 动画生命周期
*/
export interface AnimationCycle {
appear?: Animation;
update?: Animation;
destroy?: Animation;
}
4 changes: 4 additions & 0 deletions packages/f2/src/components/geometry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { toTimeStamp } from '../../util/index';
import { GeomType, GeometryProps } from './interface';
import AttrController from '../../controller/attr';
import equal from '../../base/equal';
import { AnimationCycle } from '../../canvas/animation/interface';

// 保留原始数据的字段
const FIELD_ORIGIN = 'origin';
Expand All @@ -29,6 +30,9 @@ class Geometry<T extends GeometryProps = GeometryProps> extends Component<T> {

attrController: AttrController;

// 动画配置
animation: AnimationCycle;

getDefaultCfg() {
return {};
}
Expand Down
4 changes: 3 additions & 1 deletion packages/f2/src/components/geometry/interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Chart from '../../chart';
import Coord from '../../coord';
import { AnimationCycle } from '../../canvas/animation/interface';

export interface AttrRange {
shape?: any[];
Expand Down Expand Up @@ -31,5 +32,6 @@ export interface GeometryProps {
coord?: Coord;
startOnZero?: boolean;
style?: Style;
[k: string]: any; // TODO
animation?: AnimationCycle;
[k: string]: any; // TODO
}
6 changes: 3 additions & 3 deletions packages/f2/src/components/guide/views/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type TextGuideProps = {

export default (props: TextGuideProps) => {
const { theme = {} } = props;
const { points, style, offsetX, offsetY, content } = deepMix({ ...theme.text }, props);
const { points, style, offsetX, offsetY, content, animation } = deepMix({ ...theme.text }, props);
const { x, y } = points[0] || {};
const posX = x + (offsetX || 0);
const posY = y + (offsetY || 0);
Expand All @@ -25,13 +25,13 @@ export default (props: TextGuideProps) => {
y: posY,
...style,
}}
animation={{
animation={deepMix({
update: {
easing: 'linear',
duration: 450,
property: ['x', 'y'],
},
}}
}, animation)}
/>
);
};
9 changes: 5 additions & 4 deletions packages/f2/src/components/interval/view/rect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { deepMix } from '@antv/util';
import { jsx } from '../../../jsx';

export default (props) => {
const { records } = props;
export default props => {
const { records, animation } = props;
return (
<group>
{records.map((record) => {
Expand All @@ -20,7 +21,7 @@ export default (props) => {
height: yMax - yMin,
fill: color,
}}
animation={{
animation={deepMix({
appear: {
easing: 'linear',
duration: 450,
Expand All @@ -35,7 +36,7 @@ export default (props) => {
duration: 450,
property: ['x', 'y', 'width', 'height'],
},
}}
}, animation)}
/>
);
})}
Expand Down
4 changes: 2 additions & 2 deletions packages/f2/src/components/interval/withInterval.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ export default (Views) => {

render() {
const { props } = this;
const { coord, shape = 'rect', style } = props;
const { coord, shape = 'rect', style, animation } = props;
const View = Views[shape];

if (!View) return null;

const records = this.mapping();
return <View coord={coord} records={records} shape={shape} style={style} />;
return <View coord={coord} records={records} shape={shape} style={style} animation={animation} />;
}
};
};
7 changes: 3 additions & 4 deletions packages/f2/src/components/line/lineView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isArray } from '@antv/util';
import { deepMix, isArray } from '@antv/util';
import { jsx } from '../../jsx';
import { LineViewProps } from './types';

Expand Down Expand Up @@ -89,7 +89,6 @@ export default (props: LineViewProps) => {
width: width,
},
},
...animation,
};
return (
<group>
Expand All @@ -109,14 +108,14 @@ export default (props: LineViewProps) => {
stroke: color,
lineWidth: size,
}}
animation={{
animation={deepMix({
update: {
easing: 'linear',
duration: 450,
property: ['points'],
},
appear,
}}
}, animation)}
/>
);
})}
Expand Down
4 changes: 3 additions & 1 deletion packages/f2/test/timeline/line-race.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ describe('Chart', () => {
y="income"
color="country"
animation={{
duration: 5000,
appear: {
duration: 5000,
}
}}
endView={EndView}
/>
Expand Down
17 changes: 16 additions & 1 deletion packages/f2/test/timeline/race-country.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ describe('Chart', () => {
<Year year={year} />
<Axis field="country" />
<Axis field="income" />
<Interval x="country" y="income" color="country" />
<Interval x="country" y="income" color="country" animation={{
appear: {
duration: 100,
},
update: {
duration: 1000,
}
}} />
{data[year].map((record) => {
return (
<TextGuide
Expand All @@ -63,6 +70,14 @@ describe('Chart', () => {
fontSize: '40px',
textBaseline: 'middle',
}}
animation={{
appear: {
duration: 100,
},
update: {
duration: 1000,
}
}}
/>
);
})}
Expand Down

0 comments on commit 05abb88

Please sign in to comment.