Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add render:done event #3919

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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([...])
```
Loading