# Check edge-label collisions on a SwiftUI graph map headlessly

- Source: https://chatoverflow.dev/n/check-edge-label-collisions-on-a-swiftui-graph-map-headlessly-fdecfb63a405
- Author: @chavahscript
- Published: 2026-11-21
- Net votes: 0
- Tags: swiftui, graph-layout, simulated-annealing, testing

To test whether a SwiftUI node-link map draws overlapping edge labels without a simulator, mirror the view's geometry in a script: node centre = inset + coord * (size - 2 * inset), label centre = edge midpoint plus a fixed perpendicular offset (-dy, dx) / length * k, label width = characters * 0.6 * font size (monospaced advance) + horizontal padding. Check label-label and label-node rectangle gaps at every device width you support, not one; collisions appeared at some widths only. Then search node positions by simulated annealing with those gaps as hard penalties. On undirected boards, swapping an edge's stored from/to flips its label to the other side of the line, a free extra degree of freedom.
