From 86fb6d2facfb325edbaa709f7b777cad19b9c7b4 Mon Sep 17 00:00:00 2001 From: liihuu Date: Mon, 18 Mar 2024 03:28:19 +0800 Subject: [PATCH] opt: opt repeat render --- src/common/Canvas.ts | 17 ++++++++--------- src/store/ChartStore.ts | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/common/Canvas.ts b/src/common/Canvas.ts index 5f41b70dd..54928df20 100644 --- a/src/common/Canvas.ts +++ b/src/common/Canvas.ts @@ -15,7 +15,7 @@ import { getPixelRatio } from './utils/canvas' import { createDom } from './utils/dom' import { isValid } from './utils/typeChecks' -import { requestAnimationFrame, cancelAnimationFrame, DEFAULT_REQUEST_ID } from './utils/compatible' +import { requestAnimationFrame, DEFAULT_REQUEST_ID } from './utils/compatible' type DrawListener = () => void @@ -104,15 +104,14 @@ export default class Canvas { } private _executeListener (fn?: () => void): void { - if (this._requestAnimationId !== DEFAULT_REQUEST_ID) { - cancelAnimationFrame(this._requestAnimationId) - this._requestAnimationId = DEFAULT_REQUEST_ID + if (this._requestAnimationId === DEFAULT_REQUEST_ID) { + this._requestAnimationId = requestAnimationFrame(() => { + this._ctx.clearRect(0, 0, this._width, this._height) + fn?.() + this._listener() + this._requestAnimationId = DEFAULT_REQUEST_ID + }) } - this._requestAnimationId = requestAnimationFrame(() => { - this._ctx.clearRect(0, 0, this._width, this._height) - fn?.() - this._listener() - }) } update (w: number, h: number): void { diff --git a/src/store/ChartStore.ts b/src/store/ChartStore.ts index 6166fe765..2b8df19f7 100644 --- a/src/store/ChartStore.ts +++ b/src/store/ChartStore.ts @@ -278,8 +278,8 @@ export default class ChartStore { this._timeScaleStore.adjustVisibleRange() this._tooltipStore.recalculateCrosshair(true) await this._indicatorStore.calcInstance() + this._chart.adjustPaneViewport(false, true, true, true) } - this._chart.adjustPaneViewport(false, true, true, true) this._actionStore.execute(ActionType.OnDataReady) } catch {} }