From b4edc2914d38ae51725ee7a3ed2fb6d1762a240c Mon Sep 17 00:00:00 2001 From: root Date: Mon, 13 Apr 2026 11:03:18 -0300 Subject: [PATCH] Fix diagram generator: auto-port detection for clean edge routing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Edges now auto-detect exit/entry ports based on relative positions of source and target services. Uses absolute coordinates from the layout engine to determine whether connections should exit right→left, top→bottom, etc. - exitX/exitY/entryX/entryY added to every edge style - 1.5x threshold favors vertical routing over horizontal when positions are diagonal — matches Oracle ref arch top-down subnet flow - Eliminates crossing arrows in multi-subnet, multi-region diagrams - Verified with both PharmaCorp (dual-region) and MELI (single-region) Generic code fix — applies to all diagrams, not just this spec. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../opt02-architecture.drawio | 124 +++++++++--------- tools/oci_diagram_gen.py | 38 ++++++ 2 files changed, 100 insertions(+), 62 deletions(-) diff --git a/examples/output-demo-pharma-mx/opt02-architecture.drawio b/examples/output-demo-pharma-mx/opt02-architecture.drawio index 5c0fd80..95c3cc3 100644 --- a/examples/output-demo-pharma-mx/opt02-architecture.drawio +++ b/examples/output-demo-pharma-mx/opt02-architecture.drawio @@ -4,160 +4,160 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - + + + - + @@ -165,14 +165,14 @@ - + - + @@ -187,7 +187,7 @@ - + @@ -204,14 +204,14 @@ - + - + @@ -223,21 +223,21 @@ - + - + - + @@ -263,12 +263,12 @@ - + - + diff --git a/tools/oci_diagram_gen.py b/tools/oci_diagram_gen.py index 98cf241..e7e8a7c 100644 --- a/tools/oci_diagram_gen.py +++ b/tools/oci_diagram_gen.py @@ -938,6 +938,44 @@ class OCIDiagramGenerator: extra_style += "dashPattern=4 4;" # "standard", "data", and "db" use solid line defaults + # ── Auto-port detection ── + # Calculate exit/entry ports based on relative positions of source and + # target. This prevents draw.io's auto-router from creating crossing + # arrows — instead, edges exit/enter from the geometrically correct side. + src_pos = self._abs_positions.get(source) + tgt_pos = self._abs_positions.get(target) + if src_pos and tgt_pos: + src_obj_w = getattr(src_obj, 'width', 100) or 100 + src_obj_h = getattr(src_obj, 'height', 60) or 60 + # Center points + sx = src_pos[0] + src_obj_w / 2 + sy = src_pos[1] + src_obj_h / 2 + tgt_obj_w = getattr(tgt_obj, 'width', 100) or 100 + tgt_obj_h = getattr(tgt_obj, 'height', 60) or 60 + tx = tgt_pos[0] + tgt_obj_w / 2 + ty = tgt_pos[1] + tgt_obj_h / 2 + + dx = tx - sx + dy = ty - sy + + # Determine dominant direction and set ports. + # Use 1.5x threshold: prefer vertical within same container (natural + # top-down flow), only go horizontal when clearly side-by-side. + # This matches Oracle ref arch style where subnets stack vertically + # and connections flow down between them. + if abs(dx) > abs(dy) * 1.5: + # Clearly horizontal: exit right → enter left (or vice versa) + if dx > 0: + extra_style += "exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" + else: + extra_style += "exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" + else: + # Vertical or diagonal: exit bottom → enter top (or vice versa) + if dy > 0: + extra_style += "exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" + else: + extra_style += "exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" + # Add waypoints if provided if waypoints: for wx, wy in waypoints: