Skip to content

Commit

Permalink
Merge pull request #1778 from gavin-ts/dir-right
Browse files Browse the repository at this point in the history
fix disconnected edge with dagre layout in direction right
  • Loading branch information
gavin-ts authored Dec 13, 2023
2 parents 2829a6a + b67764d commit 6aaf795
Show file tree
Hide file tree
Showing 8 changed files with 1,062 additions and 4 deletions.
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

0 comments on commit 6aaf795

Please sign in to comment.