Skip to content

Commit 74d4690

Browse files
committed
fix: 快扫动画进行中时,修改数据,图表显示异常
1 parent 3023e67 commit 74d4690

File tree

3 files changed

+2284
-4144
lines changed

3 files changed

+2284
-4144
lines changed

packages/f2/src/components/candlestick/candlestickView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default (props) => {
1717
return (
1818
<group>
1919
<line
20+
key={`${key}-line`}
2021
style={{
2122
x1: x,
2223
y1: y[2],
@@ -45,7 +46,7 @@ export default (props) => {
4546
}}
4647
/>
4748
<rect
48-
key={key}
49+
key={`${key}-rect`}
4950
style={{
5051
x: xMin,
5152
y: yMin,

packages/f2/src/components/zoom/index.tsx

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@ export default (View) => {
144144
}
145145

146146
willReceiveProps(nextProps: P): void {
147-
const { range: nextRange } = nextProps;
148-
const { range: lastRange } = this.props;
147+
// @ts-ignore
148+
const { range: nextRange, data: nextData } = nextProps;
149+
const { range: lastRange, data: lastData } = this.props;
150+
if (nextData !== lastData) {
151+
this._cancelAnimationFrame();
152+
}
149153
if (!isEqual(nextRange, lastRange)) {
150154
const cacheRange = {};
151155
each(this.dims, (dim) => {
@@ -215,7 +219,21 @@ export default (View) => {
215219
}
216220

217221
didUnmount(): void {
218-
this.loop && cancelAnimationFrame(this.loop);
222+
this._cancelAnimationFrame();
223+
}
224+
225+
_requestAnimationFrame(calllback: Function) {
226+
const { context } = this;
227+
const { requestAnimationFrame } = context.canvas;
228+
this.loop = requestAnimationFrame(calllback);
229+
return this.loop;
230+
}
231+
232+
_cancelAnimationFrame() {
233+
const { loop, context } = this;
234+
if (loop) {
235+
context.canvas.cancelAnimationFrame(loop);
236+
}
219237
}
220238

221239
_bindEvents() {
@@ -273,7 +291,7 @@ export default (View) => {
273291
const { state } = this;
274292
const { range } = state;
275293
this.startRange = range;
276-
this.loop && cancelAnimationFrame(this.loop);
294+
this._cancelAnimationFrame();
277295
};
278296

279297
onPan = (ev) => {
@@ -317,16 +335,15 @@ export default (View) => {
317335

318336
this.startRange = range;
319337

320-
this.loop = requestAnimationFrame(() => this.update());
338+
this._requestAnimationFrame(() => this.update());
321339
if (Math.abs(x - endX) < 0.0005 && Math.abs(y - endY) < 0.0005) {
322340
this.onEnd();
323-
cancelAnimationFrame(this.loop);
341+
this._cancelAnimationFrame();
324342
}
325343
}
326344

327345
animateSwipe(dim: string, dimRange: ZoomRange, velocity: number) {
328-
const { context, props } = this;
329-
const { requestAnimationFrame } = context.canvas;
346+
const { props } = this;
330347
const { swipeDuration = 1000 } = props;
331348

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

360-
requestAnimationFrame(() => {
377+
this._requestAnimationFrame(() => {
361378
update();
362379
});
363380
};

0 commit comments

Comments
 (0)