Skip to content

Commit

Permalink
Add LGraph.empty
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Dec 6, 2024
1 parent 0d0dfaf commit 3277ac1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/LGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
inputs: Dictionary<IGraphInput>
outputs: Dictionary<IGraphInput>

/** @returns Whether the graph has no items */
get empty(): boolean {
return this.positionableItems.length === 0
}

/** @returns All items on the canvas that can be selected */
get positionableItems(): Positionable[] {
return [...this._nodes, ...this._groups, ...this.reroutes.values()]
}

#reroutes = new Map<RerouteId, Reroute>()
/** All reroutes in this graph. */
public get reroutes(): Map<RerouteId, Reroute> {
Expand Down
13 changes: 5 additions & 8 deletions src/LGraphCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3954,15 +3954,12 @@ export class LGraphCanvas {
}
}

/**
* @returns All items on the canvas that can be selected
*/
get empty(): boolean {
return this.graph.empty
}

get positionableItems(): Positionable[] {
return [
...this.graph._nodes,
...this.graph._groups,
...this.graph.reroutes.values(),
]
return this.graph.positionableItems
}

/**
Expand Down

0 comments on commit 3277ac1

Please sign in to comment.