diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go
index ebab1e73e..6d004e25f 100644
--- a/d2layouts/d2dagrelayout/layout.go
+++ b/d2layouts/d2dagrelayout/layout.go
@@ -856,6 +856,7 @@ func shiftUp(g *d2graph.Graph, start, distance float64, isHorizontal bool) {
func shiftReachableDown(g *d2graph.Graph, obj *d2graph.Object, start, distance float64, isHorizontal, isMargin bool) map[*d2graph.Object]struct{} {
q := []*d2graph.Object{obj}
+ needsMove := make(map[*d2graph.Object]struct{})
seen := make(map[*d2graph.Object]struct{})
shifted := make(map[*d2graph.Object]struct{})
shiftedEdges := make(map[*d2graph.Edge]struct{})
@@ -915,23 +916,27 @@ func shiftReachableDown(g *d2graph.Graph, obj *d2graph.Object, start, distance f
}
// skip other objects behind start
if curr != obj {
- if isHorizontal {
- if curr.TopLeft.X < start {
- continue
- }
- } else {
- if curr.TopLeft.Y < start {
- continue
+ if _, in := needsMove[curr]; !in {
+ if isHorizontal {
+ if curr.TopLeft.X < start {
+ continue
+ }
+ } else {
+ if curr.TopLeft.Y < start {
+ continue
+ }
}
}
}
if isHorizontal {
- shift := false
- if !isMargin {
- shift = start < curr.TopLeft.X
- } else {
- shift = start <= curr.TopLeft.X
+ _, shift := needsMove[curr]
+ if !shift {
+ if !isMargin {
+ shift = start < curr.TopLeft.X
+ } else {
+ shift = start <= curr.TopLeft.X
+ }
}
if shift {
@@ -939,11 +944,13 @@ func shiftReachableDown(g *d2graph.Graph, obj *d2graph.Object, start, distance f
shifted[curr] = struct{}{}
}
} else {
- shift := false
- if !isMargin {
- shift = start < curr.TopLeft.Y
- } else {
- shift = start <= curr.TopLeft.Y
+ _, shift := needsMove[curr]
+ if !shift {
+ if !isMargin {
+ shift = start < curr.TopLeft.Y
+ } else {
+ shift = start <= curr.TopLeft.Y
+ }
}
if shift {
curr.TopLeft.Y += distance
@@ -977,6 +984,18 @@ func shiftReachableDown(g *d2graph.Graph, obj *d2graph.Object, start, distance f
shiftedEdges[e] = struct{}{}
continue
} else if e.Src == curr {
+ last := e.Route[len(e.Route)-1]
+ if isHorizontal {
+ if start <= last.X &&
+ e.Dst.TopLeft.X+e.Dst.Width < last.X+distance {
+ needsMove[e.Dst] = struct{}{}
+ }
+ } else {
+ if start <= last.Y &&
+ e.Dst.TopLeft.Y+e.Dst.Height < last.Y+distance {
+ needsMove[e.Dst] = struct{}{}
+ }
+ }
queue(e.Dst)
if isHorizontal {
for _, p := range e.Route {
@@ -993,6 +1012,18 @@ func shiftReachableDown(g *d2graph.Graph, obj *d2graph.Object, start, distance f
}
shiftedEdges[e] = struct{}{}
} else if e.Dst == curr {
+ first := e.Route[0]
+ if isHorizontal {
+ if start <= first.X &&
+ e.Src.TopLeft.X+e.Src.Width < first.X+distance {
+ needsMove[e.Src] = struct{}{}
+ }
+ } else {
+ if start <= first.Y &&
+ e.Src.TopLeft.Y+e.Src.Height < first.Y+distance {
+ needsMove[e.Src] = struct{}{}
+ }
+ }
queue(e.Src)
if isHorizontal {
for _, p := range e.Route {
diff --git a/e2etests/regression_test.go b/e2etests/regression_test.go
index e66d250ed..55bc62b14 100644
--- a/e2etests/regression_test.go
+++ b/e2etests/regression_test.go
@@ -1038,6 +1038,7 @@ cf many required: {
loadFromFile(t, "cylinder_grid_label"),
loadFromFile(t, "grid_with_latex"),
loadFromFile(t, "icons_on_top"),
+ loadFromFile(t, "dagre_disconnected_edge"),
}
runa(t, tcs)
diff --git a/e2etests/testdata/files/dagre_disconnected_edge.d2 b/e2etests/testdata/files/dagre_disconnected_edge.d2
new file mode 100644
index 000000000..a51b8241c
--- /dev/null
+++ b/e2etests/testdata/files/dagre_disconnected_edge.d2
@@ -0,0 +1,13 @@
+x -> y
+
+x: program {
+ label.near: top-center
+ icon: https://icons.terrastruct.com/essentials%2F005-programmer.svg
+ icon.near: outside-top-right
+}
+
+y: profits {
+ label.near: bottom-right
+ icon: https://icons.terrastruct.com/essentials%2Fprofits.svg
+ icon.near: outside-left-center
+}
diff --git a/e2etests/testdata/regression/dagre_disconnected_edge/dagre/board.exp.json b/e2etests/testdata/regression/dagre_disconnected_edge/dagre/board.exp.json
new file mode 100644
index 000000000..f74f94ee7
--- /dev/null
+++ b/e2etests/testdata/regression/dagre_disconnected_edge/dagre/board.exp.json
@@ -0,0 +1,202 @@
+{
+ "name": "",
+ "isFolderOnly": false,
+ "fontFamily": "SourceSansPro",
+ "shapes": [
+ {
+ "id": "x",
+ "type": "rectangle",
+ "pos": {
+ "x": 74,
+ "y": 0
+ },
+ "width": 131,
+ "height": 92,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B6",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": {
+ "Scheme": "https",
+ "Opaque": "",
+ "User": null,
+ "Host": "icons.terrastruct.com",
+ "Path": "/essentials/005-programmer.svg",
+ "RawPath": "/essentials%2F005-programmer.svg",
+ "OmitHost": false,
+ "ForceQuery": false,
+ "RawQuery": "",
+ "Fragment": "",
+ "RawFragment": ""
+ },
+ "iconPosition": "OUTSIDE_TOP_RIGHT",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "program",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 60,
+ "labelHeight": 21,
+ "labelPosition": "INSIDE_TOP_CENTER",
+ "zIndex": 0,
+ "level": 1
+ },
+ {
+ "id": "y",
+ "type": "rectangle",
+ "pos": {
+ "x": 81,
+ "y": 192
+ },
+ "width": 118,
+ "height": 92,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B6",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": {
+ "Scheme": "https",
+ "Opaque": "",
+ "User": null,
+ "Host": "icons.terrastruct.com",
+ "Path": "/essentials/profits.svg",
+ "RawPath": "/essentials%2Fprofits.svg",
+ "OmitHost": false,
+ "ForceQuery": false,
+ "RawQuery": "",
+ "Fragment": "",
+ "RawFragment": ""
+ },
+ "iconPosition": "OUTSIDE_LEFT_MIDDLE",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "profits",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 47,
+ "labelHeight": 21,
+ "labelPosition": "INSIDE_BOTTOM_RIGHT",
+ "zIndex": 0,
+ "level": 1
+ }
+ ],
+ "connections": [
+ {
+ "id": "(x -> y)[0]",
+ "src": "x",
+ "srcArrow": "none",
+ "dst": "y",
+ "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": 139.5,
+ "y": 92
+ },
+ {
+ "x": 139.5,
+ "y": 132
+ },
+ {
+ "x": 139.5,
+ "y": 152
+ },
+ {
+ "x": 139.5,
+ "y": 192
+ }
+ ],
+ "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/dagre_disconnected_edge/dagre/sketch.exp.svg b/e2etests/testdata/regression/dagre_disconnected_edge/dagre/sketch.exp.svg
new file mode 100644
index 000000000..7fcca0eb3
--- /dev/null
+++ b/e2etests/testdata/regression/dagre_disconnected_edge/dagre/sketch.exp.svg
@@ -0,0 +1,96 @@
+
\ No newline at end of file
diff --git a/e2etests/testdata/regression/dagre_disconnected_edge/elk/board.exp.json b/e2etests/testdata/regression/dagre_disconnected_edge/elk/board.exp.json
new file mode 100644
index 000000000..4630de718
--- /dev/null
+++ b/e2etests/testdata/regression/dagre_disconnected_edge/elk/board.exp.json
@@ -0,0 +1,193 @@
+{
+ "name": "",
+ "isFolderOnly": false,
+ "fontFamily": "SourceSansPro",
+ "shapes": [
+ {
+ "id": "x",
+ "type": "rectangle",
+ "pos": {
+ "x": 40,
+ "y": 12
+ },
+ "width": 131,
+ "height": 118,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B6",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": {
+ "Scheme": "https",
+ "Opaque": "",
+ "User": null,
+ "Host": "icons.terrastruct.com",
+ "Path": "/essentials/005-programmer.svg",
+ "RawPath": "/essentials%2F005-programmer.svg",
+ "OmitHost": false,
+ "ForceQuery": false,
+ "RawQuery": "",
+ "Fragment": "",
+ "RawFragment": ""
+ },
+ "iconPosition": "OUTSIDE_TOP_RIGHT",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "program",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 60,
+ "labelHeight": 21,
+ "labelPosition": "INSIDE_TOP_CENTER",
+ "zIndex": 0,
+ "level": 1
+ },
+ {
+ "id": "y",
+ "type": "rectangle",
+ "pos": {
+ "x": 81,
+ "y": 200
+ },
+ "width": 118,
+ "height": 118,
+ "opacity": 1,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "B6",
+ "stroke": "B1",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "double-border": false,
+ "tooltip": "",
+ "link": "",
+ "icon": {
+ "Scheme": "https",
+ "Opaque": "",
+ "User": null,
+ "Host": "icons.terrastruct.com",
+ "Path": "/essentials/profits.svg",
+ "RawPath": "/essentials%2Fprofits.svg",
+ "OmitHost": false,
+ "ForceQuery": false,
+ "RawQuery": "",
+ "Fragment": "",
+ "RawFragment": ""
+ },
+ "iconPosition": "OUTSIDE_LEFT_MIDDLE",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "profits",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "N1",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 47,
+ "labelHeight": 21,
+ "labelPosition": "INSIDE_BOTTOM_RIGHT",
+ "zIndex": 0,
+ "level": 1
+ }
+ ],
+ "connections": [
+ {
+ "id": "(x -> y)[0]",
+ "src": "x",
+ "srcArrow": "none",
+ "dst": "y",
+ "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": 105.5,
+ "y": 130
+ },
+ {
+ "x": 105.5,
+ "y": 200
+ }
+ ],
+ "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/dagre_disconnected_edge/elk/sketch.exp.svg b/e2etests/testdata/regression/dagre_disconnected_edge/elk/sketch.exp.svg
new file mode 100644
index 000000000..93a255fb8
--- /dev/null
+++ b/e2etests/testdata/regression/dagre_disconnected_edge/elk/sketch.exp.svg
@@ -0,0 +1,96 @@
+programprofits
+
+
+
+
\ No newline at end of file