Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix disconnected edge with dagre layout in direction right #1778

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
- Fixes missing unfilled triangle arrowheads when sketch flag is on. [#1763](https://github.com/terrastruct/d2/pull/1763)
- Fixes a bug where the render target could be incorrect if the target path contains "index". [#1764](https://github.com/terrastruct/d2/pull/1764)
- Fixes ELK layout with outside labels/icons. [#1776](https://github.com/terrastruct/d2/pull/1776)
- Fixes a bug where an edge could become disconnected with dagre layout and direction right. [#1778](https://github.com/terrastruct/d2/pull/1778)
34 changes: 30 additions & 4 deletions d2layouts/d2dagrelayout/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,14 +902,27 @@ func shiftReachableDown(g *d2graph.Graph, obj *d2graph.Object, start, distance f
}
}
queue(e.Dst)
first := e.Route[0]
startIndex := 0
_, wasShifted := shifted[curr]
if isHorizontal {
for _, p := range e.Route {
if wasShifted && first.X < curr.TopLeft.X && first.X < start {
first.X += distance
startIndex++
}
for i := startIndex; i < len(e.Route); i++ {
p := e.Route[i]
if start <= p.X {
p.X += distance
}
}
} else {
for _, p := range e.Route {
if wasShifted && first.Y < curr.TopLeft.Y && first.Y < start {
first.Y += distance
startIndex++
}
for i := startIndex; i < len(e.Route); i++ {
p := e.Route[i]
if start <= p.Y {
p.Y += distance
}
Expand All @@ -930,14 +943,27 @@ func shiftReachableDown(g *d2graph.Graph, obj *d2graph.Object, start, distance f
}
}
queue(e.Src)
last := e.Route[len(e.Route)-1]
endIndex := len(e.Route)
_, wasShifted := shifted[curr]
if isHorizontal {
for _, p := range e.Route {
if wasShifted && last.X < curr.TopLeft.X && last.X < start {
last.X += distance
endIndex--
}
for i := 0; i < endIndex; i++ {
p := e.Route[i]
if start <= p.X {
p.X += distance
}
}
} else {
for _, p := range e.Route {
if wasShifted && last.Y < curr.TopLeft.Y && last.Y < start {
last.Y += distance
endIndex--
}
for i := 0; i < endIndex; i++ {
p := e.Route[i]
if start <= p.Y {
p.Y += distance
}
Expand Down
1 change: 1 addition & 0 deletions e2etests/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ cf many required: {
loadFromFile(t, "shaped_grid_positioning"),
loadFromFile(t, "cloud_shaped_grid"),
loadFromFileWithOptions(t, "nested_layout_bug", testCase{testSerialization: true}),
loadFromFile(t, "disconnect_direction_right"),
}

runa(t, tcs)
Expand Down
16 changes: 16 additions & 0 deletions e2etests/testdata/files/disconnect_direction_right.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
direction: right

a: {
b
}

c: {
d
}

e: {
f
}

a.b -> c.d
a.b -> e.f
Loading