Skip to content

Commit

Permalink
fix: 快扫动画进行中时,修改数据,图表显示异常 (#1916)
Browse files Browse the repository at this point in the history
* fix: 快扫动画进行中时,修改数据,图表显示异常

---------

Co-authored-by: 兵人 <xuezhiqiang.xzq@antgroup.com>
  • Loading branch information
zengyue and 兵人 committed Jan 3, 2024
1 parent 2446f22 commit 095ce5f
Show file tree
Hide file tree
Showing 3 changed files with 2,325 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/f2/src/components/candlestick/candlestickView.tsx
Expand Up @@ -17,6 +17,7 @@ export default (props) => {
return (
<group>
<line
key={`${key}-line`}
style={{
x1: x,
y1: y[2],
Expand Down Expand Up @@ -45,7 +46,7 @@ export default (props) => {
}}
/>
<rect
key={key}
key={`${key}-rect`}
style={{
x: xMin,
y: yMin,
Expand Down
35 changes: 26 additions & 9 deletions packages/f2/src/components/zoom/index.tsx
Expand Up @@ -144,8 +144,12 @@ export default (View) => {
}

willReceiveProps(nextProps: P): void {
const { range: nextRange } = nextProps;
const { range: lastRange } = this.props;
// @ts-ignore
const { range: nextRange, data: nextData } = nextProps;
const { range: lastRange, data: lastData } = this.props;
if (nextData !== lastData) {
this._cancelAnimationFrame();
}
if (!isEqual(nextRange, lastRange)) {
const cacheRange = {};
each(this.dims, (dim) => {
Expand Down Expand Up @@ -215,7 +219,21 @@ export default (View) => {
}

didUnmount(): void {
this.loop && cancelAnimationFrame(this.loop);
this._cancelAnimationFrame();
}

_requestAnimationFrame(calllback: Function) {
const { context } = this;
const { requestAnimationFrame } = context.canvas;
this.loop = requestAnimationFrame(calllback);
return this.loop;
}

_cancelAnimationFrame() {
const { loop, context } = this;
if (loop) {
context.canvas.cancelAnimationFrame(loop);
}
}

_bindEvents() {
Expand Down Expand Up @@ -273,7 +291,7 @@ export default (View) => {
const { state } = this;
const { range } = state;
this.startRange = range;
this.loop && cancelAnimationFrame(this.loop);
this._cancelAnimationFrame();
};

onPan = (ev) => {
Expand Down Expand Up @@ -317,16 +335,15 @@ export default (View) => {

this.startRange = range;

this.loop = requestAnimationFrame(() => this.update());
this._requestAnimationFrame(() => this.update());
if (Math.abs(x - endX) < 0.0005 && Math.abs(y - endY) < 0.0005) {
this.onEnd();
cancelAnimationFrame(this.loop);
this._cancelAnimationFrame();
}
}

animateSwipe(dim: string, dimRange: ZoomRange, velocity: number) {
const { context, props } = this;
const { requestAnimationFrame } = context.canvas;
const { props } = this;
const { swipeDuration = 1000 } = props;

const diff = (dimRange[1] - dimRange[0]) * velocity;
Expand Down Expand Up @@ -357,7 +374,7 @@ export default (View) => {
const easedProgress = easeing(progress);
updateRange(easedProgress);

requestAnimationFrame(() => {
this._requestAnimationFrame(() => {
update();
});
};
Expand Down

0 comments on commit 095ce5f

Please sign in to comment.