Closed sagunji closed 2 months ago
Yes, portConstraints work.
For anyone in the future.
const elkLayout: LayoutAlgorithm = async (nodes, edges, options) => {
const graph = {
id: 'elk-root',
layoutOptions: {
'elk.algorithm': 'layered',
'elk.direction': 'DOWN',
'elk.edgeRouting': 'POLYLINE',
'elk.spacing.nodeNode': options.spacing[0],
'elk.spacing.edgeNode': options.spacing[1],
'elk.layered.spacing.nodeNodeBetweenLayers': '120',
},
children: nodes.map(node => {
const isBranchTask = node.type === 'Branch';
return {
id: node.id,
width: node.width ?? 0,
height: node.height ?? 0,
...(isBranchTask
? {
properties: {
'org.eclipse.elk.portConstraints': 'FIXED_ORDER',
},
ports: [
{ id: node.id },
{
id: `${node.id}-match`,
properties: {
side: 'SOUTH',
index: 1,
},
},
{
id: `${node.id}-nomatch`,
properties: {
side: 'SOUTH',
index: 0,
},
},
],
}
: {}),
};
}),
edges: edges.map(edge => {
return {
id: edge.id,
sources: [edge.sourceHandle || edge.source],
targets: [edge.target],
};
}),
};
Specifically, the following does the trick:
'org.eclipse.elk.portConstraints': 'FIXED_ORDER',
on a node "fixes" the order of the ports and also requires them to be constrained to a specific side. Here, side: 'SOUTH'
sets the desired port side, while index: 1
determines the ordering of both properties are set on a port of a node that has port constraints specified.
I'm working on a workflow graph visualization using ELK.js, and I'm facing challenges with node placement in graphs that have multiple and nested conditional branches.
Objective:
How can I configure ELK.js to consistently position nodes from True branches on the left and nodes from False branches on the right in a workflow graph with multiple and nested conditional branches?
Additional Context:
Snippet:
Current output: