fix: align main flow at DO_TRY top and stretch sections to full width
All checks were successful
CI / cleanup-branch (push) Has been skipped
CI / build (push) Successful in 59s
CI / docker (push) Successful in 41s
CI / deploy-feature (push) Has been skipped
CI / deploy (push) Successful in 36s

Port alignment BEGIN on DO_TRY compounds makes edges attach at the top
instead of center, keeping the main flow level. Post-processing also
stretches all DO_TRY sections (doFinally, doCatch) to match the widest
section's width for visual consistency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-03-28 10:26:28 +01:00
parent 99b97c53dd
commit 065517f032

View File

@@ -334,6 +334,7 @@ public class ElkDiagramRenderer implements DiagramRenderer {
}
// Post-process DO_TRY compounds: re-stack sections in correct order
// and stretch all sections to the same width
// (ELK doesn't reliably order disconnected children within a compound)
for (Map.Entry<String, List<String>> entry : doTrySectionOrder.entrySet()) {
List<String> orderedIds = entry.getValue();
@@ -344,6 +345,7 @@ public class ElkDiagramRenderer implements DiagramRenderer {
}
if (sections.size() < 2) continue;
// Re-stack in correct vertical order
double startY = sections.stream().mapToDouble(ElkNode::getY).min().orElse(0);
double spacing = NODE_SPACING * 0.4; // matches DO_TRY spacing
double currentY = startY;
@@ -351,6 +353,12 @@ public class ElkDiagramRenderer implements DiagramRenderer {
section.setY(currentY);
currentY += section.getHeight() + spacing;
}
// Stretch all sections to the widest one's width
double maxWidth = sections.stream().mapToDouble(ElkNode::getWidth).max().orElse(0);
for (ElkNode section : sections) {
section.setWidth(maxWidth);
}
}
// Extract positioned nodes
@@ -577,6 +585,9 @@ public class ElkDiagramRenderer implements DiagramRenderer {
elkNode.setProperty(CoreOptions.PADDING,
new org.eclipse.elk.core.math.ElkPadding(COMPOUND_TOP_PADDING,
COMPOUND_SIDE_PADDING, COMPOUND_SIDE_PADDING, COMPOUND_SIDE_PADDING));
// Attach edges at the top of the compound so the main flow stays level
elkNode.setProperty(CoreOptions.PORT_ALIGNMENT_DEFAULT,
org.eclipse.elk.core.options.PortAlignment.BEGIN);
// Separate try body children from handler children
List<RouteNode> tryBodyChildren = new ArrayList<>();