Skip to content

Commit

Permalink
fix: render edge when source or target in render area
Browse files Browse the repository at this point in the history
  • Loading branch information
NewByVector committed Jul 4, 2023
1 parent 543de19 commit f0ba327
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 36 deletions.
39 changes: 16 additions & 23 deletions packages/x6/src/renderer/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class Scheduler extends Disposable {

setRenderArea(area?: Rectangle) {
this.renderArea = area
this.flushWaittingViews()
this.flushWaitingViews()
}

isViewMounted(view: CellView) {
Expand Down Expand Up @@ -203,15 +203,15 @@ export class Scheduler extends Disposable {
}

let result = 0
if (this.isUpdateable(view)) {
if (this.isUpdatable(view)) {
result = this.updateView(view, flag, options)
viewItem.flag = result
} else {
if (viewItem.state === Scheduler.ViewState.MOUNTED) {
result = this.updateView(view, flag, options)
viewItem.flag = result
} else {
viewItem.state = Scheduler.ViewState.WAITTING
viewItem.state = Scheduler.ViewState.WAITING
}
}

Expand Down Expand Up @@ -259,9 +259,9 @@ export class Scheduler extends Disposable {
: this.queue.queueFlushSync()
}

protected flushWaittingViews() {
protected flushWaitingViews() {
Object.values(this.views).forEach((viewItem) => {
if (viewItem && viewItem.state === Scheduler.ViewState.WAITTING) {
if (viewItem && viewItem.state === Scheduler.ViewState.WAITING) {
const { view, flag, options } = viewItem
this.requestViewUpdate(
view,
Expand Down Expand Up @@ -481,30 +481,23 @@ export class Scheduler extends Disposable {
return effectedEdges
}

protected isUpdateable(view: CellView) {
protected isUpdatable(view: CellView) {
if (view.isNodeView()) {
if (!this.renderArea) {
return true
if (this.renderArea) {
return this.renderArea.isIntersectWithRect(view.cell.getBBox())
}
const node = view.cell
return this.renderArea.isIntersectWithRect(node.getBBox())
return true
}

if (view.isEdgeView()) {
const edge = view.cell
const sourceCell = edge.getSourceCell()
const targetCell = edge.getTargetCell()
if (sourceCell) {
const sourceViewItem = this.views[sourceCell.id]
if (sourceViewItem && !this.isViewMounted(sourceViewItem.view)) {
return false
}
}

if (targetCell) {
const targetViewItem = this.views[targetCell.id]
if (targetViewItem && !this.isViewMounted(targetViewItem.view)) {
return false
}
if (this.renderArea && sourceCell && targetCell) {
return (
this.renderArea.isIntersectWithRect(sourceCell.getBBox()) ||
this.renderArea.isIntersectWithRect(targetCell.getBBox())
)
}
}

Expand Down Expand Up @@ -532,7 +525,7 @@ export namespace Scheduler {
export enum ViewState {
CREATED,
MOUNTED,
WAITTING,
WAITING,
}
export interface View {
view: CellView
Expand Down
13 changes: 0 additions & 13 deletions packages/x6/src/view/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,6 @@ export class EdgeView<
ref = this.removeAction(ref, 'target')
}

const graph = this.graph
const sourceView = this.sourceView
const targetView = this.targetView

if (
graph &&
((sourceView && !graph.renderer.isViewMounted(sourceView)) ||
(targetView && !graph.renderer.isViewMounted(targetView)))
) {
// Wait for the sourceView and targetView to be rendered.
return ref
}

if (this.hasAction(ref, 'render')) {
this.render()
ref = this.removeAction(ref, ['render', 'update', 'labels', 'tools'])
Expand Down

0 comments on commit f0ba327

Please sign in to comment.