Skip to content

Commit

Permalink
feat: add render:done event (#3919)
Browse files Browse the repository at this point in the history
  • Loading branch information
NewByVector authored Sep 19, 2023
1 parent 21a9739 commit 016a2be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/x6/src/renderer/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export class Scheduler extends Disposable {
this.queue.clearJobs()
this.removeZPivots()
this.resetViews()
this.renderViews(this.model.getCells(), options)
const cells = this.model.getCells()
this.renderViews(cells, { ...options, queue: cells.map((cell) => cell.id) })
}

protected onCellAdded({ cell, options }: Model.EventArgs['cell:added']) {
Expand Down Expand Up @@ -116,6 +117,16 @@ export class Scheduler extends Disposable {
priority,
cb: () => {
this.renderViewInArea(view, flag, options)
const queue = options.queue
if (queue) {
const index = queue.indexOf(view.cell.id)
if (index >= 0) {
queue.splice(index, 1)
}
if (queue.length === 0) {
this.graph.trigger('render:done')
}
}
},
})

Expand Down Expand Up @@ -537,5 +548,6 @@ export namespace Scheduler {
export interface EventArgs {
'view:mounted': { view: CellView }
'view:unmounted': { view: CellView }
'render:done': null
}
}
10 changes: 10 additions & 0 deletions sites/x6-sites/docs/tutorial/basic/events.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,13 @@ graph.on('edge:transition:finish', (args: Animation.CallbackArgs) => {})
graph.on('view:mounted', ({ view }) => {})
graph.on('view:unmounted', ({ view }) => {})
```

大家还有经常需要在调用 `fromJSON` 或者 `resetCells` 后监听画布完成渲染事件,这时候可以使用 `render:done` 事件来监听。

```typescript
graph.on('render:done', () => {
// pass
})

graph.fromJSON([...])
```

0 comments on commit 016a2be

Please sign in to comment.