Summary
ELK algorithms other than layered panic with "index out of range" when an edge connects an external node to a node inside a nested container.
Reproduction
test.d2:
outer: {
inner: {
a
}
}
external -> outer.inner.a
Working:
❯ d2 --layout=elk --elk-algorithm=layered test.d2 test.png
success: successfully compiled test.d2 to test.png in 372.446125ms
Error:
d2 --layout=elk --elk-algorithm=stress test.d2 test.png
panic: runtime error: index out of range [0] with length 0
goroutine 8 [running]:
oss.terrastruct.com/d2/d2layouts/d2elklayout.Layout(...)
oss.terrastruct.com/d2/d2layouts/d2elklayout/layout.go:604 +0x1dcc
Root Cause
|
points := edge.Route |
|
|
|
startIndex, endIndex := 0, len(points)-1 |
|
start := points[startIndex] |
|
end := points[endIndex] |
Non-layered ELK algorithms return empty Route arrays for edges that cross container boundaries. The code assumes edge.Route is non-empty.
AI Disclaimer
Issue diagnosed with assistance from Claude 4.5 Opus.
Summary
ELK algorithms other than
layeredpanic with "index out of range" when an edge connects an external node to a node inside a nested container.Reproduction
test.d2:
Working:
❯ d2 --layout=elk --elk-algorithm=layered test.d2 test.png success: successfully compiled test.d2 to test.png in 372.446125msError:
Root Cause
d2/d2layouts/d2elklayout/layout.go
Lines 601 to 605 in 93f9720
Non-layered ELK algorithms return empty
Routearrays for edges that cross container boundaries. The code assumesedge.Routeis non-empty.AI Disclaimer
Issue diagnosed with assistance from Claude 4.5 Opus.