diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md
index 44728f188..ff0cbf2da 100644
--- a/ci/release/changelogs/next.md
+++ b/ci/release/changelogs/next.md
@@ -14,5 +14,6 @@
- Fixed crash when sequence diagrams had no messages. [https://github.com/terrastruct/d2/pull/427](https://github.com/terrastruct/d2/pull/427)
- Fixed `constraint` keyword setting label. [https://github.com/terrastruct/d2/issues/415](https://github.com/terrastruct/d2/issues/415)
- Fixed serialization affecting binary plugins (TALA). [https://github.com/terrastruct/d2/pull/426](https://github.com/terrastruct/d2/pull/426)
+- Fixed connections in elk layouts not going all the way to shape borders. [https://github.com/terrastruct/d2/pull/459](https://github.com/terrastruct/d2/pull/459)
- Fixed a connection rendering bug that could happen in firefox when there were no connection labels. [https://github.com/terrastruct/d2/pull/453](https://github.com/terrastruct/d2/pull/453)
- Fixed a crash when external connection IDs were prefixes of a sequence diagram ID. [https://github.com/terrastruct/d2/pull/462](https://github.com/terrastruct/d2/pull/462)
diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go
index 63b26c95f..dce31bc8a 100644
--- a/d2layouts/d2elklayout/layout.go
+++ b/d2layouts/d2elklayout/layout.go
@@ -10,6 +10,7 @@ import (
"encoding/json"
"fmt"
"math"
+ "strings"
"github.com/dop251/goja"
@@ -21,6 +22,7 @@ import (
"oss.terrastruct.com/d2/d2target"
"oss.terrastruct.com/d2/lib/geo"
"oss.terrastruct.com/d2/lib/label"
+ "oss.terrastruct.com/d2/lib/shape"
)
//go:embed elk.js
@@ -289,6 +291,14 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
})
}
+ startIndex, endIndex := 0, len(points)-1
+ srcShape := shape.NewShape(d2target.DSL_SHAPE_TO_SHAPE_TYPE[strings.ToLower(edge.Src.Attributes.Shape.Value)], edge.Src.Box)
+ dstShape := shape.NewShape(d2target.DSL_SHAPE_TO_SHAPE_TYPE[strings.ToLower(edge.Dst.Attributes.Shape.Value)], edge.Dst.Box)
+
+ // trace the edge to the specific shape's border
+ points[startIndex] = shape.TraceToShapeBorder(srcShape, points[startIndex], points[startIndex+1])
+ points[endIndex] = shape.TraceToShapeBorder(dstShape, points[endIndex], points[endIndex-1])
+
if edge.Attributes.Label.Value != "" {
edge.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
}
diff --git a/e2etests/testdata/stable/all_shapes/elk/board.exp.json b/e2etests/testdata/stable/all_shapes/elk/board.exp.json
index 3d2556ad8..a89fff02d 100644
--- a/e2etests/testdata/stable/all_shapes/elk/board.exp.json
+++ b/e2etests/testdata/stable/all_shapes/elk/board.exp.json
@@ -752,7 +752,7 @@
"y": 392
},
{
- "x": 854.5,
+ "x": 855,
"y": 492
}
],
@@ -827,7 +827,7 @@
"route": [
{
"x": 1062,
- "y": 378
+ "y": 361
},
{
"x": 1062,
@@ -865,11 +865,11 @@
"labelPercentage": 0,
"route": [
{
- "x": 93.5,
+ "x": 93,
"y": 138
},
{
- "x": 93.5,
+ "x": 94,
"y": 252
}
],
@@ -904,11 +904,11 @@
"labelPercentage": 0,
"route": [
{
- "x": 93.5,
+ "x": 93,
"y": 378
},
{
- "x": 93.5,
+ "x": 94,
"y": 492
}
],
@@ -943,11 +943,11 @@
"labelPercentage": 0,
"route": [
{
- "x": 290.5,
+ "x": 291,
"y": 138
},
{
- "x": 290.5,
+ "x": 291,
"y": 252
}
],
@@ -982,11 +982,11 @@
"labelPercentage": 0,
"route": [
{
- "x": 290.5,
+ "x": 290,
"y": 378
},
{
- "x": 290.5,
+ "x": 291,
"y": 492
}
],
@@ -1099,12 +1099,12 @@
"labelPercentage": 0,
"route": [
{
- "x": 478.5,
+ "x": 478,
"y": 138
},
{
- "x": 478.5,
- "y": 238
+ "x": 479,
+ "y": 240
}
],
"animated": false,
diff --git a/e2etests/testdata/stable/all_shapes/elk/sketch.exp.svg b/e2etests/testdata/stable/all_shapes/elk/sketch.exp.svg
index b6ca41575..7b2c4a56c 100644
--- a/e2etests/testdata/stable/all_shapes/elk/sketch.exp.svg
+++ b/e2etests/testdata/stable/all_shapes/elk/sketch.exp.svg
@@ -18,7 +18,7 @@ width="1352" height="824" viewBox="-88 -88 1352 824">rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud
+rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud
rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud
+rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud
cba *
+cba *
aaadddeeebbbccc111 222
+aaadddeeebbbccc111 222
-
+
aabbllmmoocciikkddhhjjff1122 334455667788
+ff1122 334455667788
-
+
-
+
aabbccddllffwwyyadnniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac 123456
+aabbccddllffwwyyadnniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac 123456
-
-
+
+
diff --git a/e2etests/testdata/stable/sequence_diagrams/elk/board.exp.json b/e2etests/testdata/stable/sequence_diagrams/elk/board.exp.json
index 3ed298e02..81a532b8a 100644
--- a/e2etests/testdata/stable/sequence_diagrams/elk/board.exp.json
+++ b/e2etests/testdata/stable/sequence_diagrams/elk/board.exp.json
@@ -3565,7 +3565,7 @@
"route": [
{
"x": 748,
- "y": 176
+ "y": 165
},
{
"x": 748,
@@ -3729,7 +3729,7 @@
"route": [
{
"x": 830,
- "y": 176
+ "y": 165
},
{
"x": 830,
diff --git a/e2etests/testdata/stable/sequence_diagrams/elk/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagrams/elk/sketch.exp.svg
index b043d6fdd..938982dd1 100644
--- a/e2etests/testdata/stable/sequence_diagrams/elk/sketch.exp.svg
+++ b/e2etests/testdata/stable/sequence_diagrams/elk/sketch.exp.svg
@@ -18,7 +18,7 @@ width="3324" height="4389" viewBox="-88 -88 3324 4389">a_shapea_sequenceanotherfinallysequencesequencesequencescoreritemResponseitemessayRubricconceptitemOutcomescorerconceptessayRubricitemitemOutcomeitemResponsescoreritemResponseitemessayRubricconceptitemOutcome getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts)getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts)
+a_shapea_sequenceanotherfinallysequencesequencesequencescoreritemResponseitemessayRubricconceptitemOutcomescorerconceptessayRubricitemitemOutcomeitemResponsescoreritemResponseitemessayRubricconceptitemOutcome getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts)getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts)