Skip to content
Merged
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
39 changes: 24 additions & 15 deletions source/npm/qsharp/ux/circuit-vis/sqore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
*
Expand Down
Loading