toElkEdges method
Generate ELK JSON edge maps for this hyperedge.
For a 1:1 edge returns a single map keyed on id.
For N:M, returns the cartesian product with deterministic sub-IDs
of the form "${id}_$n".
resolvePort maps (nodeId, portIndex) to the temporary string port
ID that ELK expects, supplied by LayoutNode.toJson.
Implementation
List<Map<String, dynamic>> toElkEdges(
String Function(String nodeId, int portIndex) resolvePort,
) {
final hwMeta = <String, dynamic>{
'name': name,
if (width > 1) 'signalWidth': width,
if (signal.address != null) 'addr': signal.address!.path,
};
// Tell ELK to allocate more routing space for multi-bit buses.
final edgeProps = <String, dynamic>{
if (width > 1) 'org.eclipse.elk.edge.thickness': 3,
};
if (isOneToOne) {
final (src, srcPort) = sources.first;
final (tgt, tgtPort) = targets.first;
return [
{
'id': id,
'source': src,
'sourcePort': resolvePort(src, srcPort),
'target': tgt,
'targetPort': resolvePort(tgt, tgtPort),
'hwMeta': hwMeta,
if (edgeProps.isNotEmpty) 'properties': edgeProps,
},
];
}
// N:M: cartesian product with deterministic sub-IDs.
final edges = <Map<String, dynamic>>[];
var sub = 0;
for (final (src, srcPort) in sources) {
for (final (tgt, tgtPort) in targets) {
edges.add({
'id': '${id}_$sub',
'source': src,
'sourcePort': resolvePort(src, srcPort),
'target': tgt,
'targetPort': resolvePort(tgt, tgtPort),
'hwMeta': hwMeta,
if (edgeProps.isNotEmpty) 'properties': edgeProps,
});
sub++;
}
}
return edges;
}