-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add back (most of) expression to circuit popup
- Loading branch information
Showing
6 changed files
with
153 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/site/pages/digital/src/utils/ExpressionParser/ComponentOrganizers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// TODO[model_refactor_api](trevor): Get this working for expression to circuit frontend | ||
import {Vector} from "Vector"; | ||
import {Circuit} from "core/public"; | ||
|
||
import {CreateGraph} from "core/utils/CircuitUtils"; | ||
|
||
|
||
const ORGANIZE_SEP_X = 4; | ||
const ORGANIZE_SEP_Y = 3; | ||
|
||
function OrganizeCore(circuit: Circuit, start: Vector, depths: string[][]): void { | ||
// Depths is a 2d array where the index of the inner array indicates the depth of all of the nodes inside that array | ||
depths.forEach((nodes, depth) => | ||
nodes.forEach((id, index) => | ||
circuit.getComponent(id)!.pos = ( // VVV extra space for labels | ||
start.add(ORGANIZE_SEP_X*(depth - (depths.length - 1)/2) + ORGANIZE_SEP_X/2, | ||
-ORGANIZE_SEP_Y*(index - (nodes.length - 1)/2)) | ||
) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Organizes the components so that components at greater depth are further to the right, | ||
* using the getMaxNodeDepths function of Graph to accomplish this. | ||
* | ||
* @param circuit The circuit to organize. | ||
* @param start The top left coordinate where the organization should start. | ||
*/ | ||
export function OrganizeMaxDepth(circuit: Circuit, start: Vector): void { | ||
OrganizeCore(circuit, start, CreateGraph(circuit).getMaxNodeDepths()); | ||
} | ||
|
||
/** | ||
* Organizes the components so that components at greater depth are further to the right, | ||
* using the getMinNodeDepths function of Graph to accomplish this. | ||
* | ||
* @param circuit The circuit to organize. | ||
* @param start The top left coordinate where the organization should start. | ||
*/ | ||
export function OrganizeMinDepth(circuit: Circuit, start: Vector): void { | ||
OrganizeCore(circuit, start, CreateGraph(circuit).getMinNodeDepths()); | ||
} |