From f60f0e3033de4b5f5338ad34ff9228f2f891033a Mon Sep 17 00:00:00 2001 From: Mine Starks Date: Mon, 5 Jan 2026 11:03:41 -0800 Subject: [PATCH] auto-expand all single nested operations --- source/npm/qsharp/ux/circuit-vis/sqore.ts | 39 ++++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/source/npm/qsharp/ux/circuit-vis/sqore.ts b/source/npm/qsharp/ux/circuit-vis/sqore.ts index 7fd0afeb02..64aadd5c7b 100644 --- a/source/npm/qsharp/ux/circuit-vis/sqore.ts +++ b/source/npm/qsharp/ux/circuit-vis/sqore.ts @@ -122,21 +122,7 @@ export class Sqore { ); // If only one top-level operation, expand automatically: - if ( - _circuit.componentGrid.length == 1 && - _circuit.componentGrid[0].components.length == 1 && - _circuit.componentGrid[0].components[0].dataAttributes != null && - Object.prototype.hasOwnProperty.call( - _circuit.componentGrid[0].components[0].dataAttributes, - "location", - ) && - _circuit.componentGrid[0].components[0].dataAttributes["expanded"] !== - "false" - ) { - const location: string = - _circuit.componentGrid[0].components[0].dataAttributes["location"]; - this.expandOperation(_circuit.componentGrid, location); - } + this.expandIfSingleOperation(_circuit.componentGrid); // Create visualization components const composedSqore: ComposedSqore = this.compose(_circuit); @@ -169,6 +155,29 @@ export class Sqore { } } + private expandIfSingleOperation(grid: ComponentGrid) { + if (grid.length == 1 && grid[0].components.length == 1) { + const onlyComponent = grid[0].components[0]; + if ( + onlyComponent.dataAttributes != null && + Object.prototype.hasOwnProperty.call( + onlyComponent.dataAttributes, + "location", + ) && + onlyComponent.dataAttributes["expanded"] !== "false" + ) { + const location: string = onlyComponent.dataAttributes["location"]; + this.expandOperation(grid, location); + } + } + // Recursively expand if the only child is also a single operation + for (const col of grid) { + for (const op of col.components) { + this.expandIfSingleOperation(op.children || []); + } + } + } + /** * Sets the viewBox attribute of the SVG element to enable zooming and panning. *