diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md
index 60e1ebc6f9..a61c9436fe 100644
--- a/ci/release/changelogs/next.md
+++ b/ci/release/changelogs/next.md
@@ -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)
diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go
index fbf618ed76..b367e404ca 100644
--- a/d2layouts/d2dagrelayout/layout.go
+++ b/d2layouts/d2dagrelayout/layout.go
@@ -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
}
@@ -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
}
diff --git a/e2etests/regression_test.go b/e2etests/regression_test.go
index 10a96e2634..c8cdd44db0 100644
--- a/e2etests/regression_test.go
+++ b/e2etests/regression_test.go
@@ -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)
diff --git a/e2etests/testdata/files/disconnect_direction_right.d2 b/e2etests/testdata/files/disconnect_direction_right.d2
new file mode 100644
index 0000000000..53657bb2db
--- /dev/null
+++ b/e2etests/testdata/files/disconnect_direction_right.d2
@@ -0,0 +1,16 @@
+direction: right
+
+a: {
+ b
+}
+
+c: {
+ d
+}
+
+e: {
+ f
+}
+
+a.b -> c.d
+a.b -> e.f
diff --git a/e2etests/testdata/regression/disconnect_direction_right/dagre/board.exp.json b/e2etests/testdata/regression/disconnect_direction_right/dagre/board.exp.json
new file mode 100644
index 0000000000..0702d7c9e6
--- /dev/null
+++ b/e2etests/testdata/regression/disconnect_direction_right/dagre/board.exp.json
@@ -0,0 +1,413 @@
+{
+ "name": "",
+ "isFolderOnly": false,
+ "fontFamily": "SourceSansPro",
+ "shapes": [
+ {
+ "id": "a",
+ "type": "rectangle",
+ "pos": {
+ "x": 20,
+ "y": 185
+ },
+ "width": 113,
+ "height": 126,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B4",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "a",
+ "fontSize": 28,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 12,
+ "labelHeight": 36,
+ "labelPosition": "OUTSIDE_TOP_CENTER",
+ "zIndex": 0,
+ "level": 1
+ },
+ {
+ "id": "a.b",
+ "type": "rectangle",
+ "pos": {
+ "x": 50,
+ "y": 215
+ },
+ "width": 53,
+ "height": 66,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B5",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "b",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 8,
+ "labelHeight": 21,
+ "labelPosition": "INSIDE_MIDDLE_CENTER",
+ "zIndex": 0,
+ "level": 2
+ },
+ {
+ "id": "c",
+ "type": "rectangle",
+ "pos": {
+ "x": 273,
+ "y": 56
+ },
+ "width": 114,
+ "height": 126,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B4",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "c",
+ "fontSize": 28,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 12,
+ "labelHeight": 36,
+ "labelPosition": "OUTSIDE_TOP_CENTER",
+ "zIndex": 0,
+ "level": 1
+ },
+ {
+ "id": "c.d",
+ "type": "rectangle",
+ "pos": {
+ "x": 303,
+ "y": 86
+ },
+ "width": 54,
+ "height": 66,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B5",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "d",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 9,
+ "labelHeight": 21,
+ "labelPosition": "INSIDE_MIDDLE_CENTER",
+ "zIndex": 0,
+ "level": 2
+ },
+ {
+ "id": "e",
+ "type": "rectangle",
+ "pos": {
+ "x": 275,
+ "y": 268
+ },
+ "width": 111,
+ "height": 126,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B4",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "e",
+ "fontSize": 28,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 12,
+ "labelHeight": 36,
+ "labelPosition": "OUTSIDE_TOP_CENTER",
+ "zIndex": 0,
+ "level": 1
+ },
+ {
+ "id": "e.f",
+ "type": "rectangle",
+ "pos": {
+ "x": 305,
+ "y": 298
+ },
+ "width": 51,
+ "height": 66,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B5",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "f",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 6,
+ "labelHeight": 21,
+ "labelPosition": "INSIDE_MIDDLE_CENTER",
+ "zIndex": 0,
+ "level": 2
+ }
+ ],
+ "connections": [
+ {
+ "id": "(a.b -> c.d)[0]",
+ "src": "a.b",
+ "srcArrow": "none",
+ "dst": "c.d",
+ "dstArrow": "triangle",
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "stroke": "B1",
+ "borderRadius": 10,
+ "label": "",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N2",
+ "italic": true,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 0,
+ "labelHeight": 0,
+ "labelPosition": "",
+ "labelPercentage": 0,
+ "route": [
+ {
+ "x": 103,
+ "y": 219
+ },
+ {
+ "x": 143,
+ "y": 139
+ },
+ {
+ "x": 163,
+ "y": 119
+ },
+ {
+ "x": 178,
+ "y": 119
+ },
+ {
+ "x": 193,
+ "y": 119
+ },
+ {
+ "x": 263,
+ "y": 119
+ },
+ {
+ "x": 303,
+ "y": 119
+ }
+ ],
+ "isCurve": true,
+ "animated": false,
+ "tooltip": "",
+ "icon": null,
+ "zIndex": 0
+ },
+ {
+ "id": "(a.b -> e.f)[0]",
+ "src": "a.b",
+ "srcArrow": "none",
+ "dst": "e.f",
+ "dstArrow": "triangle",
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "stroke": "B1",
+ "borderRadius": 10,
+ "label": "",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N2",
+ "italic": true,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 0,
+ "labelHeight": 0,
+ "labelPosition": "",
+ "labelPercentage": 0,
+ "route": [
+ {
+ "x": 103,
+ "y": 277
+ },
+ {
+ "x": 143,
+ "y": 320.20001220703125
+ },
+ {
+ "x": 163,
+ "y": 331
+ },
+ {
+ "x": 178,
+ "y": 331
+ },
+ {
+ "x": 193,
+ "y": 331
+ },
+ {
+ "x": 263.29998779296875,
+ "y": 331
+ },
+ {
+ "x": 304.5,
+ "y": 331
+ }
+ ],
+ "isCurve": true,
+ "animated": false,
+ "tooltip": "",
+ "icon": null,
+ "zIndex": 0
+ }
+ ],
+ "root": {
+ "id": "",
+ "type": "",
+ "pos": {
+ "x": 0,
+ "y": 0
+ },
+ "width": 0,
+ "height": 0,
+ "opacity": 0,
+ "strokeDash": 0,
+ "strokeWidth": 0,
+ "borderRadius": 0,
+ "fill": "N7",
+ "stroke": "",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "",
+ "fontSize": 0,
+ "fontFamily": "",
+ "language": "",
+ "color": "",
+ "italic": false,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 0,
+ "labelHeight": 0,
+ "zIndex": 0,
+ "level": 0
+ }
+}
diff --git a/e2etests/testdata/regression/disconnect_direction_right/dagre/sketch.exp.svg b/e2etests/testdata/regression/disconnect_direction_right/dagre/sketch.exp.svg
new file mode 100644
index 0000000000..44c07ff733
--- /dev/null
+++ b/e2etests/testdata/regression/disconnect_direction_right/dagre/sketch.exp.svg
@@ -0,0 +1,107 @@
+
\ No newline at end of file
diff --git a/e2etests/testdata/regression/disconnect_direction_right/elk/board.exp.json b/e2etests/testdata/regression/disconnect_direction_right/elk/board.exp.json
new file mode 100644
index 0000000000..52dd59166d
--- /dev/null
+++ b/e2etests/testdata/regression/disconnect_direction_right/elk/board.exp.json
@@ -0,0 +1,387 @@
+{
+ "name": "",
+ "isFolderOnly": false,
+ "fontFamily": "SourceSansPro",
+ "shapes": [
+ {
+ "id": "a",
+ "type": "rectangle",
+ "pos": {
+ "x": 12,
+ "y": 98
+ },
+ "width": 153,
+ "height": 180,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B4",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "a",
+ "fontSize": 28,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 12,
+ "labelHeight": 36,
+ "labelPosition": "INSIDE_TOP_CENTER",
+ "zIndex": 0,
+ "level": 1
+ },
+ {
+ "id": "a.b",
+ "type": "rectangle",
+ "pos": {
+ "x": 62,
+ "y": 148
+ },
+ "width": 53,
+ "height": 80,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B5",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "b",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 8,
+ "labelHeight": 21,
+ "labelPosition": "INSIDE_MIDDLE_CENTER",
+ "zIndex": 0,
+ "level": 2
+ },
+ {
+ "id": "c",
+ "type": "rectangle",
+ "pos": {
+ "x": 255,
+ "y": 12
+ },
+ "width": 154,
+ "height": 166,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B4",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "c",
+ "fontSize": 28,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 12,
+ "labelHeight": 36,
+ "labelPosition": "INSIDE_TOP_CENTER",
+ "zIndex": 0,
+ "level": 1
+ },
+ {
+ "id": "c.d",
+ "type": "rectangle",
+ "pos": {
+ "x": 305,
+ "y": 62
+ },
+ "width": 54,
+ "height": 66,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B5",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "d",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 9,
+ "labelHeight": 21,
+ "labelPosition": "INSIDE_MIDDLE_CENTER",
+ "zIndex": 0,
+ "level": 2
+ },
+ {
+ "id": "e",
+ "type": "rectangle",
+ "pos": {
+ "x": 255,
+ "y": 198
+ },
+ "width": 151,
+ "height": 166,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B4",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "e",
+ "fontSize": 28,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 12,
+ "labelHeight": 36,
+ "labelPosition": "INSIDE_TOP_CENTER",
+ "zIndex": 0,
+ "level": 1
+ },
+ {
+ "id": "e.f",
+ "type": "rectangle",
+ "pos": {
+ "x": 305,
+ "y": 248
+ },
+ "width": 51,
+ "height": 66,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B5",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "f",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 6,
+ "labelHeight": 21,
+ "labelPosition": "INSIDE_MIDDLE_CENTER",
+ "zIndex": 0,
+ "level": 2
+ }
+ ],
+ "connections": [
+ {
+ "id": "(a.b -> c.d)[0]",
+ "src": "a.b",
+ "srcArrow": "none",
+ "dst": "c.d",
+ "dstArrow": "triangle",
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "stroke": "B1",
+ "borderRadius": 10,
+ "label": "",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N2",
+ "italic": true,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 0,
+ "labelHeight": 0,
+ "labelPosition": "",
+ "labelPercentage": 0,
+ "route": [
+ {
+ "x": 115,
+ "y": 174.66600036621094
+ },
+ {
+ "x": 210,
+ "y": 174.66600036621094
+ },
+ {
+ "x": 210,
+ "y": 95
+ },
+ {
+ "x": 305,
+ "y": 95
+ }
+ ],
+ "animated": false,
+ "tooltip": "",
+ "icon": null,
+ "zIndex": 0
+ },
+ {
+ "id": "(a.b -> e.f)[0]",
+ "src": "a.b",
+ "srcArrow": "none",
+ "dst": "e.f",
+ "dstArrow": "triangle",
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "stroke": "B1",
+ "borderRadius": 10,
+ "label": "",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N2",
+ "italic": true,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 0,
+ "labelHeight": 0,
+ "labelPosition": "",
+ "labelPercentage": 0,
+ "route": [
+ {
+ "x": 115,
+ "y": 201.33299255371094
+ },
+ {
+ "x": 210,
+ "y": 201.33299255371094
+ },
+ {
+ "x": 210,
+ "y": 281
+ },
+ {
+ "x": 305,
+ "y": 281
+ }
+ ],
+ "animated": false,
+ "tooltip": "",
+ "icon": null,
+ "zIndex": 0
+ }
+ ],
+ "root": {
+ "id": "",
+ "type": "",
+ "pos": {
+ "x": 0,
+ "y": 0
+ },
+ "width": 0,
+ "height": 0,
+ "opacity": 0,
+ "strokeDash": 0,
+ "strokeWidth": 0,
+ "borderRadius": 0,
+ "fill": "N7",
+ "stroke": "",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "",
+ "fontSize": 0,
+ "fontFamily": "",
+ "language": "",
+ "color": "",
+ "italic": false,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 0,
+ "labelHeight": 0,
+ "zIndex": 0,
+ "level": 0
+ }
+}
diff --git a/e2etests/testdata/regression/disconnect_direction_right/elk/sketch.exp.svg b/e2etests/testdata/regression/disconnect_direction_right/elk/sketch.exp.svg
new file mode 100644
index 0000000000..c6404d1592
--- /dev/null
+++ b/e2etests/testdata/regression/disconnect_direction_right/elk/sketch.exp.svg
@@ -0,0 +1,107 @@
+acebdf
+
+
+
+
+
+
+
+
\ No newline at end of file