diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md
index f3c0d2a77..13f3a6928 100644
--- a/ci/release/changelogs/next.md
+++ b/ci/release/changelogs/next.md
@@ -2,4 +2,6 @@
#### Improvements 🧹
+- ELK layouts tuned to have better defaults. [#627](https://github.com/terrastruct/d2/pull/627)
+
#### Bugfixes ⛑️
diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go
index d9b333385..ce4a44f34 100644
--- a/d2layouts/d2elklayout/layout.go
+++ b/d2layouts/d2elklayout/layout.go
@@ -94,11 +94,13 @@ var DefaultOpts = ConfigurableOpts{
}
type elkOpts struct {
- Direction string `json:"elk.direction"`
- HierarchyHandling string `json:"elk.hierarchyHandling,omitempty"`
- InlineEdgeLabels bool `json:"elk.edgeLabels.inline,omitempty"`
- ForceNodeModelOrder bool `json:"elk.layered.crossingMinimization.forceNodeModelOrder,omitempty"`
- ConsiderModelOrder string `json:"elk.layered.considerModelOrder.strategy,omitempty"`
+ Thoroughness int `json:"elk.layered.thoroughness,omitempty"`
+ EdgeEdgeBetweenLayersSpacing int `json:"elk.layered.spacing.edgeEdgeBetweenLayers,omitempty"`
+ Direction string `json:"elk.direction"`
+ HierarchyHandling string `json:"elk.hierarchyHandling,omitempty"`
+ InlineEdgeLabels bool `json:"elk.edgeLabels.inline,omitempty"`
+ ForceNodeModelOrder bool `json:"elk.layered.crossingMinimization.forceNodeModelOrder,omitempty"`
+ ConsiderModelOrder string `json:"elk.layered.considerModelOrder.strategy,omitempty"`
ConfigurableOpts
}
@@ -130,8 +132,10 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
elkGraph := &ELKGraph{
ID: "root",
LayoutOptions: &elkOpts{
- HierarchyHandling: "INCLUDE_CHILDREN",
- ConsiderModelOrder: "NODES_AND_EDGES",
+ Thoroughness: 20,
+ EdgeEdgeBetweenLayersSpacing: 50,
+ HierarchyHandling: "INCLUDE_CHILDREN",
+ ConsiderModelOrder: "NODES_AND_EDGES",
ConfigurableOpts: ConfigurableOpts{
Algorithm: opts.Algorithm,
NodeSpacing: opts.NodeSpacing,
@@ -183,9 +187,15 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
if len(obj.ChildrenArray) > 0 {
n.LayoutOptions = &elkOpts{
- ForceNodeModelOrder: true,
+ ForceNodeModelOrder: true,
+ Thoroughness: 20,
+ EdgeEdgeBetweenLayersSpacing: 50,
+ HierarchyHandling: "INCLUDE_CHILDREN",
+ ConsiderModelOrder: "NODES_AND_EDGES",
ConfigurableOpts: ConfigurableOpts{
- Padding: opts.Padding,
+ NodeSpacing: opts.NodeSpacing,
+ EdgeNodeSpacing: opts.EdgeNodeSpacing,
+ Padding: opts.Padding,
},
}
}
diff --git a/e2etests/testdata/regression/dagre_edge_label_spacing/elk/board.exp.json b/e2etests/testdata/regression/dagre_edge_label_spacing/elk/board.exp.json
index 363039200..5ea8e5617 100644
--- a/e2etests/testdata/regression/dagre_edge_label_spacing/elk/board.exp.json
+++ b/e2etests/testdata/regression/dagre_edge_label_spacing/elk/board.exp.json
@@ -9,7 +9,7 @@
"x": 12,
"y": 12
},
- "width": 1893,
+ "width": 2533,
"height": 287,
"opacity": 1,
"strokeDash": 0,
@@ -86,7 +86,7 @@
"id": "build_workflow.GHA",
"type": "",
"pos": {
- "x": 511,
+ "x": 671,
"y": 87
},
"width": 269,
@@ -126,7 +126,7 @@
"id": "build_workflow.S3",
"type": "",
"pos": {
- "x": 958,
+ "x": 1278,
"y": 87
},
"width": 131,
@@ -166,7 +166,7 @@
"id": "build_workflow.Terraform",
"type": "",
"pos": {
- "x": 1248,
+ "x": 1728,
"y": 87
},
"width": 218,
@@ -206,7 +206,7 @@
"id": "build_workflow.AWS",
"type": "",
"pos": {
- "x": 1675,
+ "x": 2315,
"y": 87
},
"width": 155,
@@ -274,7 +274,7 @@
"y": 155.5
},
{
- "x": 511,
+ "x": 671,
"y": 155.5
}
],
@@ -309,11 +309,11 @@
"labelPercentage": 0,
"route": [
{
- "x": 780,
+ "x": 940,
"y": 155.5
},
{
- "x": 958,
+ "x": 1278,
"y": 155.5
}
],
@@ -348,11 +348,11 @@
"labelPercentage": 0,
"route": [
{
- "x": 1089,
+ "x": 1409,
"y": 155.5
},
{
- "x": 1248,
+ "x": 1728,
"y": 155.5
}
],
@@ -387,11 +387,11 @@
"labelPercentage": 0,
"route": [
{
- "x": 1466,
+ "x": 1946,
"y": 155.5
},
{
- "x": 1675,
+ "x": 2315,
"y": 155.5
}
],
diff --git a/e2etests/testdata/regression/dagre_edge_label_spacing/elk/sketch.exp.svg b/e2etests/testdata/regression/dagre_edge_label_spacing/elk/sketch.exp.svg
index 5fb575b7c..72f4772c0 100644
--- a/e2etests/testdata/regression/dagre_edge_label_spacing/elk/sketch.exp.svg
+++ b/e2etests/testdata/regression/dagre_edge_label_spacing/elk/sketch.exp.svg
@@ -3,7 +3,7 @@
id="d2-svg"
style="background: white;"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
-width="2097" height="491" viewBox="-90 -90 2097 491">aabbllmmnnoocciikkddgghhjjeeff1122 334455667788
-
-
-
-
-
-
-
-
-
+aabbllmmnnoocciikkddgghhjjeeff1122 334455667788
+
+
+
+
+
+
+
+
+