From 801d307807c98a35acd6f34bb44ed6825376baef Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Sat, 17 Dec 2022 20:40:56 -0800 Subject: [PATCH 1/3] trace elk edges to shape border --- d2layouts/d2elklayout/layout.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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)) } From 98a2d59aea3838d857432209ca4dae42c3722cb4 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Sat, 17 Dec 2022 20:41:42 -0800 Subject: [PATCH 2/3] update tests --- .../stable/all_shapes/elk/board.exp.json | 26 +++++----- .../stable/all_shapes/elk/sketch.exp.svg | 2 +- .../all_shapes_multiple/elk/board.exp.json | 26 +++++----- .../all_shapes_multiple/elk/sketch.exp.svg | 2 +- .../all_shapes_shadow/elk/board.exp.json | 26 +++++----- .../all_shapes_shadow/elk/sketch.exp.svg | 2 +- .../arrowhead_adjustment/elk/board.exp.json | 18 +++---- .../arrowhead_adjustment/elk/sketch.exp.svg | 2 +- .../testdata/stable/chaos1/elk/board.exp.json | 2 +- .../testdata/stable/chaos1/elk/sketch.exp.svg | 4 +- .../testdata/stable/chaos2/elk/board.exp.json | 20 ++++---- .../testdata/stable/chaos2/elk/sketch.exp.svg | 6 +-- .../stable/investigate/elk/board.exp.json | 48 +++++++++---------- .../stable/investigate/elk/sketch.exp.svg | 6 +-- .../sequence_diagrams/elk/board.exp.json | 4 +- .../sequence_diagrams/elk/sketch.exp.svg | 2 +- 16 files changed, 98 insertions(+), 98 deletions(-) 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 - + aabbllmm

nn

oocciikkdd

gg

hhjj

ee

-
ff1122 334455667788 +ff1122 334455667788 - + - + aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac 123456 +aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac 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) From a0515da60b4582a00acd6deddd9e6bc5e46e48ce Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Sat, 17 Dec 2022 20:47:14 -0800 Subject: [PATCH 3/3] changelog --- ci/release/changelogs/next.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 14a6c2a39..10392f641 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -17,4 +17,5 @@ [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)