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

Optimise positionableItems / empty getters #373

Merged
merged 2 commits into from
Dec 7, 2024
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
9 changes: 6 additions & 3 deletions src/LGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,15 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {

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

/** @returns All items on the canvas that can be selected */
get positionableItems(): Positionable[] {
return [...this._nodes, ...this._groups, ...this.reroutes.values()]
*positionableItems(): Generator<LGraphNode | LGraphGroup | Reroute> {
for (const node of this._nodes) yield node
for (const group of this._groups) yield group
for (const reroute of this.reroutes.values()) yield reroute
return
}

#reroutes = new Map<RerouteId, Reroute>()
Expand Down
6 changes: 3 additions & 3 deletions src/LGraphCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3958,8 +3958,8 @@ export class LGraphCanvas {
return this.graph.empty
}

get positionableItems(): Positionable[] {
return this.graph.positionableItems
get positionableItems() {
return this.graph.positionableItems()
}

/**
Expand Down Expand Up @@ -8420,7 +8420,7 @@ export class LGraphCanvas {
* If nothing is selected, the view is fitted around all items in the graph.
*/
fitViewToSelectionAnimated(options: AnimationOptions = {}) {
const items: Positionable[] = this.selectedItems.size
const items = this.selectedItems.size
? Array.from(this.selectedItems)
: this.positionableItems
this.animateToBounds(createBounds(items), options)
Expand Down
Loading