Skip to content

Commit

Permalink
auto-position groups better
Browse files Browse the repository at this point in the history
  • Loading branch information
fechan committed May 27, 2024
1 parent 3b11661 commit 173030b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion client/src/Layouting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ export async function getLayoutedElements(nodes: Node[], edges: Edge[], factory:
children: [],
}

// convert React Flow graph to ELK graph format
for (let [machineId, machine] of Object.entries(factory.machines)) {
const machineNodeFlow = nodeMap[machineId];
const machineNodeElk: ElkNode = {
...machineNodeFlow,
layoutOptions: {
"elk.padding": "[top=30,right=30,bottom=30,left=30]",
"elk.layered.crossingMinimization.semiInteractive": "true", // allows groups to "position" themselves with elk.position
},
width: 1,
height: 1,
Expand All @@ -50,16 +52,20 @@ export async function getLayoutedElements(nodes: Node[], edges: Edge[], factory:

const groupNodeElk: ElkNode = {
...groupNodeFlow,
layoutOptions: {
"elk.position": `(${group.slots[0].slot * 100},1)`,
},
width: getWidth(group.slots.length),
height: getHeight(group.slots.length),
};
machineNodeElk.children!.push(groupNodeElk);
}
}

// fulfill width information first
// lay out ELK graph
let layout = await elk.layout(graph);

// Convert back to React Flow Graph
const layoutedNodes: Node[] = [];
for (let machineNodeElk of layout.children!) {
const machine = factory.machines[machineNodeElk.id];
Expand Down

0 comments on commit 173030b

Please sign in to comment.