From 065517f032934318a9a62907411f0180bf78dd65 Mon Sep 17 00:00:00 2001 From: hsiegeln <37154749+hsiegeln@users.noreply.github.com> Date: Sat, 28 Mar 2026 10:26:28 +0100 Subject: [PATCH] fix: align main flow at DO_TRY top and stretch sections to full width 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) --- .../server/app/diagram/ElkDiagramRenderer.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cameleer3-server-app/src/main/java/com/cameleer3/server/app/diagram/ElkDiagramRenderer.java b/cameleer3-server-app/src/main/java/com/cameleer3/server/app/diagram/ElkDiagramRenderer.java index 8dc12604..06c7fb52 100644 --- a/cameleer3-server-app/src/main/java/com/cameleer3/server/app/diagram/ElkDiagramRenderer.java +++ b/cameleer3-server-app/src/main/java/com/cameleer3/server/app/diagram/ElkDiagramRenderer.java @@ -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> entry : doTrySectionOrder.entrySet()) { List 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 tryBodyChildren = new ArrayList<>();