From a9cebc23d11282a6321e8f4c09db6129ec76540a Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Wed, 17 May 2023 20:37:12 -0500 Subject: [PATCH] Use upper graph in subgraph stack for saved offset/scale --- src/lib/ComfyGraphCanvas.ts | 12 +++++++++--- src/lib/nodes/ComfyPickImageNode.ts | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/ComfyGraphCanvas.ts b/src/lib/ComfyGraphCanvas.ts index 45fc6e3..50bcc52 100644 --- a/src/lib/ComfyGraphCanvas.ts +++ b/src/lib/ComfyGraphCanvas.ts @@ -47,10 +47,16 @@ export default class ComfyGraphCanvas extends LGraphCanvas { _selectedNodes: Set = new Set(); serialize(): SerializedGraphCanvasState { - return { - offset: this.ds.offset, - scale: this.ds.scale + let offset = this.ds.offset; + let scale = this.ds.scale; + + // Use top-level graph for saved offset if we're viewing a subgraph + if (this._graph_stack?.length > 0) { + offset = this._graph_stack[0].offset; + scale = this._graph_stack[0].scale; } + + return { offset, scale } } deserialize(data: SerializedGraphCanvasState) { diff --git a/src/lib/nodes/ComfyPickImageNode.ts b/src/lib/nodes/ComfyPickImageNode.ts index bc22e0f..6f6f559 100644 --- a/src/lib/nodes/ComfyPickImageNode.ts +++ b/src/lib/nodes/ComfyPickImageNode.ts @@ -78,6 +78,9 @@ export default class ComfyPickImageNode extends ComfyGraphNode { this.setOutputData(2, this._image.width); this.setOutputData(3, this._image.height); + // XXX: image size doesn't load until the element is ready on + // the page so this can come after several frames' worth of + // execution this.widthWidget.value = this._image.width this.heightWidget.value = this._image.height }