Merge pull request #2040 from alixander/self-referential

d2sequence: self-referential messages account for message height
This commit is contained in:
Alexander Wang 2024-08-03 11:05:44 -06:00 committed by GitHub
commit 3d3bf057b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 1218 additions and 229 deletions

View file

@ -3,5 +3,6 @@
#### Improvements 🧹
- Sequence diagram edge groups account for edge label heights [#2038](https://github.com/terrastruct/d2/pull/2038)
- Sequence diagram self-referential edges account for edge label heights [#2040](https://github.com/terrastruct/d2/pull/2040)
#### Bugfixes ⛑️

View file

@ -162,8 +162,6 @@ func newSequenceDiagram(objects []*d2graph.Object, messages []*d2graph.Edge) (*s
for _, message := range sd.messages {
sd.verticalIndices[message.AbsID()] = getEdgeEarliestLineNum(message)
// TODO this should not be global yStep, only affect the neighbors
sd.yStep = math.Max(sd.yStep, float64(message.LabelDimensions.Height))
// ensures that long labels, spanning over multiple actors, don't make for large gaps between actors
// by distributing the label length across the actors rank difference
@ -585,7 +583,7 @@ func (sd *sequenceDiagram) routeMessages() error {
if isSelfMessage || isToDescendant || isFromDescendant || isToSibling {
midX := startX + SELF_MESSAGE_HORIZONTAL_TRAVEL
endY := startY + MIN_MESSAGE_DISTANCE*1.5
endY := startY + math.Max(float64(message.LabelDimensions.Height), MIN_MESSAGE_DISTANCE)*1.5
message.Route = []*geo.Point{
geo.NewPoint(startX, startY),
geo.NewPoint(midX, startY),
@ -600,7 +598,7 @@ func (sd *sequenceDiagram) routeMessages() error {
}
prevIsLoop = false
}
messageOffset += sd.yStep
messageOffset += math.Max(sd.yStep, float64(message.LabelDimensions.Height)+MIN_MESSAGE_DISTANCE*1.5)
if message.Label.Value != "" {
message.LabelPosition = go2.Pointer(label.InsideMiddleCenter.String())

View file

@ -79,7 +79,7 @@ a -> c
func testTxtar(t *testing.T) {
var tcs []testCase
archive, err := txtar.ParseFile("./testdata/txtar.txt")
archive, err := txtar.ParseFile("./txtar.txt")
assert.Success(t, err)
for _, f := range archive.Files {
tcs = append(tcs, testCase{

View file

@ -11,7 +11,7 @@
"y": 0
},
"width": 424,
"height": 1387,
"height": 1123,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 0,
@ -172,10 +172,10 @@
"type": "rectangle",
"pos": {
"x": 10,
"y": 232
"y": 161
},
"width": 254,
"height": 904,
"height": 777,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 0,
@ -214,7 +214,7 @@
"type": "rectangle",
"pos": {
"x": 22,
"y": 968
"y": 770
},
"width": 230,
"height": 156,
@ -256,7 +256,7 @@
"type": "rectangle",
"pos": {
"x": 172,
"y": 1140
"y": 947
},
"width": 230,
"height": 156,
@ -321,11 +321,11 @@
"route": [
{
"x": 62,
"y": 326
"y": 255
},
{
"x": 212,
"y": 326
"y": 255
}
],
"animated": false,
@ -359,11 +359,11 @@
"route": [
{
"x": 62,
"y": 467
"y": 401
},
{
"x": 212,
"y": 467
"y": 401
}
],
"animated": false,
@ -397,11 +397,11 @@
"route": [
{
"x": 62,
"y": 608
"y": 547
},
{
"x": 212,
"y": 608
"y": 547
}
],
"animated": false,
@ -435,11 +435,11 @@
"route": [
{
"x": 62,
"y": 749
"y": 617
},
{
"x": 212,
"y": 749
"y": 617
}
],
"animated": false,
@ -473,11 +473,11 @@
"route": [
{
"x": 62,
"y": 890
"y": 687
},
{
"x": 212,
"y": 890
"y": 687
}
],
"animated": false,
@ -511,11 +511,11 @@
"route": [
{
"x": 62,
"y": 1062
"y": 864
},
{
"x": 212,
"y": 1062
"y": 864
}
],
"animated": false,
@ -549,11 +549,11 @@
"route": [
{
"x": 362,
"y": 1234
"y": 1041
},
{
"x": 212,
"y": 1234
"y": 1041
}
],
"animated": false,
@ -591,7 +591,7 @@
},
{
"x": 62,
"y": 1375
"y": 1111
}
],
"animated": false,
@ -629,7 +629,7 @@
},
{
"x": 212,
"y": 1375
"y": 1111
}
],
"animated": false,
@ -667,7 +667,7 @@
},
{
"x": 362,
"y": 1375
"y": 1111
}
],
"animated": false,

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View file

@ -11,7 +11,7 @@
"y": 12
},
"width": 424,
"height": 1387,
"height": 1123,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 0,
@ -172,10 +172,10 @@
"type": "rectangle",
"pos": {
"x": 22,
"y": 244
"y": 173
},
"width": 254,
"height": 904,
"height": 777,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 0,
@ -214,7 +214,7 @@
"type": "rectangle",
"pos": {
"x": 34,
"y": 980
"y": 782
},
"width": 230,
"height": 156,
@ -256,7 +256,7 @@
"type": "rectangle",
"pos": {
"x": 184,
"y": 1152
"y": 959
},
"width": 230,
"height": 156,
@ -321,11 +321,11 @@
"route": [
{
"x": 74,
"y": 338
"y": 267
},
{
"x": 224,
"y": 338
"y": 267
}
],
"animated": false,
@ -359,11 +359,11 @@
"route": [
{
"x": 74,
"y": 479
"y": 413
},
{
"x": 224,
"y": 479
"y": 413
}
],
"animated": false,
@ -397,11 +397,11 @@
"route": [
{
"x": 74,
"y": 620
"y": 559
},
{
"x": 224,
"y": 620
"y": 559
}
],
"animated": false,
@ -435,11 +435,11 @@
"route": [
{
"x": 74,
"y": 761
"y": 629
},
{
"x": 224,
"y": 761
"y": 629
}
],
"animated": false,
@ -473,11 +473,11 @@
"route": [
{
"x": 74,
"y": 902
"y": 699
},
{
"x": 224,
"y": 902
"y": 699
}
],
"animated": false,
@ -511,11 +511,11 @@
"route": [
{
"x": 74,
"y": 1074
"y": 876
},
{
"x": 224,
"y": 1074
"y": 876
}
],
"animated": false,
@ -549,11 +549,11 @@
"route": [
{
"x": 374,
"y": 1246
"y": 1053
},
{
"x": 224,
"y": 1246
"y": 1053
}
],
"animated": false,
@ -591,7 +591,7 @@
},
{
"x": 74,
"y": 1387
"y": 1123
}
],
"animated": false,
@ -629,7 +629,7 @@
},
{
"x": 224,
"y": 1387
"y": 1123
}
],
"animated": false,
@ -667,7 +667,7 @@
},
{
"x": 374,
"y": 1387
"y": 1123
}
],
"animated": false,

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View file

@ -0,0 +1,383 @@
{
"name": "",
"isFolderOnly": false,
"fontFamily": "SourceSansPro",
"shapes": [
{
"id": "x",
"type": "rectangle",
"pos": {
"x": 12,
"y": 52
},
"width": 100,
"height": 66,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B5",
"stroke": "B1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "x",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N1",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 7,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
},
{
"id": "y",
"type": "rectangle",
"pos": {
"x": 162,
"y": 52
},
"width": 100,
"height": 66,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B5",
"stroke": "B1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "y",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N1",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 8,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
}
],
"connections": [
{
"id": "(x -> x)[0]",
"src": "x",
"srcArrow": "none",
"dst": "x",
"dstArrow": "triangle",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "B1",
"borderRadius": 10,
"label": "self referential long description which is\nmultirow\n3 rows",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N2",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 261,
"labelHeight": 53,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 62,
"y": 188
},
{
"x": 142,
"y": 188
},
{
"x": 142,
"y": 267.5
},
{
"x": 62,
"y": 267.5
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "(x -> x)[1]",
"src": "x",
"srcArrow": "none",
"dst": "x",
"dstArrow": "triangle",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "B1",
"borderRadius": 10,
"label": "self referential long description which is\nmultirow",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N2",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 261,
"labelHeight": 37,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 62,
"y": 286
},
{
"x": 142,
"y": 286
},
{
"x": 142,
"y": 341.5
},
{
"x": 62,
"y": 341.5
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "(x -> y)[0]",
"src": "x",
"srcArrow": "none",
"dst": "y",
"dstArrow": "triangle",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "B1",
"borderRadius": 10,
"label": "normal",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N2",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 48,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 62,
"y": 368
},
{
"x": 212,
"y": 368
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "(y -> y)[0]",
"src": "y",
"srcArrow": "none",
"dst": "y",
"dstArrow": "triangle",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "B1",
"borderRadius": 10,
"label": "self referential long description which is\nmultirow\n3 rows",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N2",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 261,
"labelHeight": 53,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 212,
"y": 438
},
{
"x": 292,
"y": 438
},
{
"x": 292,
"y": 517.5
},
{
"x": 212,
"y": 517.5
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "(x -- )[0]",
"src": "x",
"srcArrow": "none",
"dst": "x-lifeline-end-1678191278",
"dstArrow": "none",
"opacity": 1,
"strokeDash": 6,
"strokeWidth": 2,
"stroke": "B2",
"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": 62,
"y": 118
},
{
"x": 62,
"y": 587.5
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 1
},
{
"id": "(y -- )[0]",
"src": "y",
"srcArrow": "none",
"dst": "y-lifeline-end-35261543",
"dstArrow": "none",
"opacity": 1,
"strokeDash": 6,
"strokeWidth": 2,
"stroke": "B2",
"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": 212,
"y": 118
},
{
"x": 212,
"y": 587.5
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 1
}
],
"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
}
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -0,0 +1,383 @@
{
"name": "",
"isFolderOnly": false,
"fontFamily": "SourceSansPro",
"shapes": [
{
"id": "x",
"type": "rectangle",
"pos": {
"x": 12,
"y": 52
},
"width": 100,
"height": 66,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B5",
"stroke": "B1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "x",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N1",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 7,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
},
{
"id": "y",
"type": "rectangle",
"pos": {
"x": 162,
"y": 52
},
"width": 100,
"height": 66,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "B5",
"stroke": "B1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "y",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N1",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 8,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
}
],
"connections": [
{
"id": "(x -> x)[0]",
"src": "x",
"srcArrow": "none",
"dst": "x",
"dstArrow": "triangle",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "B1",
"borderRadius": 10,
"label": "self referential long description which is\nmultirow\n3 rows",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N2",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 261,
"labelHeight": 53,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 62,
"y": 188
},
{
"x": 142,
"y": 188
},
{
"x": 142,
"y": 267.5
},
{
"x": 62,
"y": 267.5
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "(x -> x)[1]",
"src": "x",
"srcArrow": "none",
"dst": "x",
"dstArrow": "triangle",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "B1",
"borderRadius": 10,
"label": "self referential long description which is\nmultirow",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N2",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 261,
"labelHeight": 37,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 62,
"y": 286
},
{
"x": 142,
"y": 286
},
{
"x": 142,
"y": 341.5
},
{
"x": 62,
"y": 341.5
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "(x -> y)[0]",
"src": "x",
"srcArrow": "none",
"dst": "y",
"dstArrow": "triangle",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "B1",
"borderRadius": 10,
"label": "normal",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N2",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 48,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 62,
"y": 368
},
{
"x": 212,
"y": 368
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "(y -> y)[0]",
"src": "y",
"srcArrow": "none",
"dst": "y",
"dstArrow": "triangle",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "B1",
"borderRadius": 10,
"label": "self referential long description which is\nmultirow\n3 rows",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "N2",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 261,
"labelHeight": 53,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"labelPercentage": 0,
"route": [
{
"x": 212,
"y": 438
},
{
"x": 292,
"y": 438
},
{
"x": 292,
"y": 517.5
},
{
"x": 212,
"y": 517.5
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "(x -- )[0]",
"src": "x",
"srcArrow": "none",
"dst": "x-lifeline-end-1678191278",
"dstArrow": "none",
"opacity": 1,
"strokeDash": 6,
"strokeWidth": 2,
"stroke": "B2",
"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": 62,
"y": 118
},
{
"x": 62,
"y": 587.5
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 1
},
{
"id": "(y -- )[0]",
"src": "y",
"srcArrow": "none",
"dst": "y-lifeline-end-35261543",
"dstArrow": "none",
"opacity": 1,
"strokeDash": 6,
"strokeWidth": 2,
"stroke": "B2",
"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": 212,
"y": 118
},
{
"x": 212,
"y": 587.5
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 1
}
],
"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
}
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -303,3 +303,13 @@ Sequence: {
A -> File: One\nTwo\nThree\nFour\nFive\nSix
}
}
-- sequence-multiline-self-reference --
shape: sequence_diagram
x
y
x -> x: self referential long description which is\nmultirow\n3 rows
x -> x: self referential long description which is\nmultirow
x -> y: normal
y -> y: self referential long description which is\nmultirow\n3 rows