diff --git a/d2layouts/d2sequence/sequence_diagram.go b/d2layouts/d2sequence/sequence_diagram.go index 47c1f16ed..03abf99d6 100644 --- a/d2layouts/d2sequence/sequence_diagram.go +++ b/d2layouts/d2sequence/sequence_diagram.go @@ -157,7 +157,7 @@ func newSequenceDiagram(objects []*d2graph.Object, messages []*d2graph.Edge) *se if rankDiff != 0 { // rankDiff = 0 for self edges distributedLabelWidth := float64(message.LabelDimensions.Width) / rankDiff - for rank := sd.objectRank[message.Src]; rank <= sd.objectRank[message.Dst]-1; rank++ { + for rank := go2.IntMin(sd.objectRank[message.Src], sd.objectRank[message.Dst]); rank <= go2.IntMax(sd.objectRank[message.Src], sd.objectRank[message.Dst])-1; rank++ { sd.actorXStep[rank] = math.Max(sd.actorXStep[rank], distributedLabelWidth+HORIZONTAL_PAD) } } diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index a7e7d93e3..29eeb130b 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -1476,6 +1476,13 @@ a -> b b.note: "a note here to remember that padding must consider notes too" a.note: "just\na\nlong\nnote\nhere"`, }, + { + name: "sequence_diagram_distance", + script: `shape: sequence_diagram +alice -> bob: what does it mean to be well-adjusted +bob -> alice: The ability to play bridge or golf as if they were games +`, + }, } runa(t, tcs) diff --git a/e2etests/testdata/stable/sequence_diagram_distance/dagre/board.exp.json b/e2etests/testdata/stable/sequence_diagram_distance/dagre/board.exp.json new file mode 100644 index 000000000..9be45ea07 --- /dev/null +++ b/e2etests/testdata/stable/sequence_diagram_distance/dagre/board.exp.json @@ -0,0 +1,243 @@ +{ + "name": "", + "shapes": [ + { + "id": "alice", + "type": "", + "pos": { + "x": 24, + "y": 74 + }, + "width": 150, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "alice", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 37, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "bob", + "type": "", + "pos": { + "x": 426, + "y": 74 + }, + "width": 150, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "bob", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 31, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + } + ], + "connections": [ + { + "id": "(alice -> bob)[0]", + "src": "alice", + "srcArrow": "none", + "srcLabel": "", + "dst": "bob", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "what does it mean to be well-adjusted", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 249, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "labelPercentage": 0, + "route": [ + { + "x": 99, + "y": 330 + }, + { + "x": 501, + "y": 330 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 4 + }, + { + "id": "(bob -> alice)[0]", + "src": "bob", + "srcArrow": "none", + "srcLabel": "", + "dst": "alice", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "The ability to play bridge or golf as if they were games", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 352, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "labelPercentage": 0, + "route": [ + { + "x": 501, + "y": 460 + }, + { + "x": 99, + "y": 460 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 4 + }, + { + "id": "(alice -- )[0]", + "src": "alice", + "srcArrow": "none", + "srcLabel": "", + "dst": "alice-lifeline-end-3851299086", + "dstArrow": "none", + "dstLabel": "", + "opacity": 1, + "strokeDash": 6, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 99, + "y": 200 + }, + { + "x": 99, + "y": 590 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 1 + }, + { + "id": "(bob -- )[0]", + "src": "bob", + "srcArrow": "none", + "srcLabel": "", + "dst": "bob-lifeline-end-3036726343", + "dstArrow": "none", + "dstLabel": "", + "opacity": 1, + "strokeDash": 6, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 501, + "y": 200 + }, + { + "x": 501, + "y": 590 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 1 + } + ] +} diff --git a/e2etests/testdata/stable/sequence_diagram_distance/dagre/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_distance/dagre/sketch.exp.svg new file mode 100644 index 000000000..b810c6dd2 --- /dev/null +++ b/e2etests/testdata/stable/sequence_diagram_distance/dagre/sketch.exp.svg @@ -0,0 +1,39 @@ + +alicebob what does it mean to be well-adjustedThe ability to play bridge or golf as if they were games + + + + \ No newline at end of file diff --git a/e2etests/testdata/stable/sequence_diagram_distance/elk/board.exp.json b/e2etests/testdata/stable/sequence_diagram_distance/elk/board.exp.json new file mode 100644 index 000000000..9be45ea07 --- /dev/null +++ b/e2etests/testdata/stable/sequence_diagram_distance/elk/board.exp.json @@ -0,0 +1,243 @@ +{ + "name": "", + "shapes": [ + { + "id": "alice", + "type": "", + "pos": { + "x": 24, + "y": 74 + }, + "width": 150, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "alice", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 37, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "bob", + "type": "", + "pos": { + "x": 426, + "y": 74 + }, + "width": 150, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "bob", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 31, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + } + ], + "connections": [ + { + "id": "(alice -> bob)[0]", + "src": "alice", + "srcArrow": "none", + "srcLabel": "", + "dst": "bob", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "what does it mean to be well-adjusted", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 249, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "labelPercentage": 0, + "route": [ + { + "x": 99, + "y": 330 + }, + { + "x": 501, + "y": 330 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 4 + }, + { + "id": "(bob -> alice)[0]", + "src": "bob", + "srcArrow": "none", + "srcLabel": "", + "dst": "alice", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "The ability to play bridge or golf as if they were games", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 352, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "labelPercentage": 0, + "route": [ + { + "x": 501, + "y": 460 + }, + { + "x": 99, + "y": 460 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 4 + }, + { + "id": "(alice -- )[0]", + "src": "alice", + "srcArrow": "none", + "srcLabel": "", + "dst": "alice-lifeline-end-3851299086", + "dstArrow": "none", + "dstLabel": "", + "opacity": 1, + "strokeDash": 6, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 99, + "y": 200 + }, + { + "x": 99, + "y": 590 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 1 + }, + { + "id": "(bob -- )[0]", + "src": "bob", + "srcArrow": "none", + "srcLabel": "", + "dst": "bob-lifeline-end-3036726343", + "dstArrow": "none", + "dstLabel": "", + "opacity": 1, + "strokeDash": 6, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 501, + "y": 200 + }, + { + "x": 501, + "y": 590 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 1 + } + ] +} diff --git a/e2etests/testdata/stable/sequence_diagram_distance/elk/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_distance/elk/sketch.exp.svg new file mode 100644 index 000000000..b810c6dd2 --- /dev/null +++ b/e2etests/testdata/stable/sequence_diagram_distance/elk/sketch.exp.svg @@ -0,0 +1,39 @@ + +alicebob what does it mean to be well-adjustedThe ability to play bridge or golf as if they were games + + + + \ No newline at end of file diff --git a/e2etests/testdata/stable/sequence_diagram_simple/dagre/board.exp.json b/e2etests/testdata/stable/sequence_diagram_simple/dagre/board.exp.json index 1ceb33052..5daa335fc 100644 --- a/e2etests/testdata/stable/sequence_diagram_simple/dagre/board.exp.json +++ b/e2etests/testdata/stable/sequence_diagram_simple/dagre/board.exp.json @@ -45,7 +45,7 @@ "id": "bob", "type": "person", "pos": { - "x": 288, + "x": 297, "y": 165 }, "width": 150, @@ -85,7 +85,7 @@ "id": "db", "type": "cylinder", "pos": { - "x": 605, + "x": 614, "y": 186 }, "width": 150, @@ -125,7 +125,7 @@ "id": "queue", "type": "queue", "pos": { - "x": 922, + "x": 931, "y": 186 }, "width": 150, @@ -165,7 +165,7 @@ "id": "service", "type": "", "pos": { - "x": 1216, + "x": 1225, "y": 74 }, "width": 197, @@ -233,7 +233,7 @@ "y": 442 }, { - "x": 363, + "x": 372, "y": 442 } ], @@ -268,11 +268,11 @@ "labelPercentage": 0, "route": [ { - "x": 363, + "x": 372, "y": 572 }, { - "x": 1314.5, + "x": 1323.5, "y": 572 } ], @@ -307,11 +307,11 @@ "labelPercentage": 0, "route": [ { - "x": 1314.5, + "x": 1323.5, "y": 702 }, { - "x": 680, + "x": 689, "y": 702 } ], @@ -346,11 +346,11 @@ "labelPercentage": 0, "route": [ { - "x": 680, + "x": 689, "y": 832 }, { - "x": 1314.5, + "x": 1323.5, "y": 832 } ], @@ -385,11 +385,11 @@ "labelPercentage": 0, "route": [ { - "x": 1314.5, + "x": 1323.5, "y": 962 }, { - "x": 363, + "x": 372, "y": 962 } ], @@ -424,7 +424,7 @@ "labelPercentage": 0, "route": [ { - "x": 363, + "x": 372, "y": 1092 }, { @@ -467,7 +467,7 @@ "y": 1222 }, { - "x": 363, + "x": 372, "y": 1222 } ], @@ -502,11 +502,11 @@ "labelPercentage": 0, "route": [ { - "x": 363, + "x": 372, "y": 1352 }, { - "x": 997, + "x": 1006, "y": 1352 } ], @@ -541,11 +541,11 @@ "labelPercentage": 0, "route": [ { - "x": 997, + "x": 1006, "y": 1482 }, { - "x": 363, + "x": 372, "y": 1482 } ], @@ -580,7 +580,7 @@ "labelPercentage": 0, "route": [ { - "x": 363, + "x": 372, "y": 1612 }, { @@ -658,11 +658,11 @@ "labelPercentage": 0, "route": [ { - "x": 363, + "x": 372, "y": 317 }, { - "x": 363, + "x": 372, "y": 1742 } ], @@ -697,11 +697,11 @@ "labelPercentage": 0, "route": [ { - "x": 680, + "x": 689, "y": 312 }, { - "x": 680, + "x": 689, "y": 1742 } ], @@ -736,11 +736,11 @@ "labelPercentage": 0, "route": [ { - "x": 997, + "x": 1006, "y": 312 }, { - "x": 997, + "x": 1006, "y": 1742 } ], @@ -775,11 +775,11 @@ "labelPercentage": 0, "route": [ { - "x": 1314.5, + "x": 1323.5, "y": 312 }, { - "x": 1314.5, + "x": 1323.5, "y": 1742 } ], diff --git a/e2etests/testdata/stable/sequence_diagram_simple/dagre/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_simple/dagre/sketch.exp.svg index 7dab648c4..608019d3a 100644 --- a/e2etests/testdata/stable/sequence_diagram_simple/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_simple/dagre/sketch.exp.svg @@ -2,7 +2,7 @@ AlicelinebreakerBobdbqueueanoddservicewithanameinmultiple lines Authentication Requestmake request for something that is quite far away and requires a really long label to take all the space between the objectsvalidate credentialsAuthentication ResponseAnother authentication Requestdo it later storedAnother authentication Response + + + + + + + + + AlicelinebreakerBobdbqueueanoddservicewithanameinmultiple lines Authentication Requestmake request for something that is quite far away and requires a really long label to take all the space between the objectsvalidate credentialsAuthentication ResponseAnother authentication Requestdo it later storedAnother authentication Response - - - - - - - - - +AlicelinebreakerBobdbqueueanoddservicewithanameinmultiple lines Authentication Requestmake request for something that is quite far away and requires a really long label to take all the space between the objectsvalidate credentialsAuthentication ResponseAnother authentication Requestdo it later storedAnother authentication Response + + + + + + + + +