Skip to content

Commit

Permalink
opt: opt repeat render
Browse files Browse the repository at this point in the history
  • Loading branch information
liihuu committed Mar 17, 2024
1 parent 61954b8 commit 86fb6d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/common/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/store/ChartStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
Expand Down

0 comments on commit 86fb6d2

Please sign in to comment.