Merge pull request #397 from ejulio-ts/gh-391-spans

sequence_diagram: Fix span size
This commit is contained in:
ejulio-ts 2022-12-07 09:48:04 -08:00 committed by GitHub
commit cb414e5382
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 506 additions and 7 deletions

View file

@ -3,3 +3,5 @@
#### Improvements 🧹
#### Bugfixes ⛑️
- Fixed sequence diagram span size for self-edges [#397](https://github.com/terrastruct/d2/pull/397)

View file

@ -402,8 +402,7 @@ func (sd *sequenceDiagram) placeSpans() {
// finds the position if there are messages to this span
minMessageY := math.Inf(1)
if firstMessage, exists := sd.firstMessage[span]; exists {
// needs to check Src/Dst because of self-edges or edges to/from descendants
if span == firstMessage.Src {
if firstMessage.Src == firstMessage.Dst || span == firstMessage.Src {
minMessageY = firstMessage.Route[0].Y
} else {
minMessageY = firstMessage.Route[len(firstMessage.Route)-1].Y
@ -411,10 +410,10 @@ func (sd *sequenceDiagram) placeSpans() {
}
maxMessageY := math.Inf(-1)
if lastMessage, exists := sd.lastMessage[span]; exists {
if span == lastMessage.Src {
maxMessageY = lastMessage.Route[0].Y
} else {
if lastMessage.Src == lastMessage.Dst || span == lastMessage.Dst {
maxMessageY = lastMessage.Route[len(lastMessage.Route)-1].Y
} else {
maxMessageY = lastMessage.Route[0].Y
}
}

View file

@ -28,8 +28,12 @@ B: goodbye {
shape: sequence_diagram
}
A->B
`,
A->B`,
}, {
name: "sequence_diagram_span_cover",
script: `shape: sequence_diagram
b.1 -> b.1
b.1 -> b.1`,
},
}

View file

@ -0,0 +1,219 @@
{
"name": "",
"shapes": [
{
"id": "b",
"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": "b",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 13,
"labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
},
{
"id": "b.1",
"type": "rectangle",
"pos": {
"x": 93,
"y": 314
},
"width": 12,
"height": 242,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#E3E9FD",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 12,
"labelHeight": 26,
"zIndex": 2,
"level": 2
}
],
"connections": [
{
"id": "b.(1 -> 1)[0]",
"src": "b.1",
"srcArrow": "none",
"srcLabel": "",
"dst": "b.1",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"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": 105,
"y": 330
},
{
"x": 199,
"y": 330
},
{
"x": 199,
"y": 410
},
{
"x": 105,
"y": 410
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "b.(1 -> 1)[1]",
"src": "b.1",
"srcArrow": "none",
"srcLabel": "",
"dst": "b.1",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"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": 105,
"y": 460
},
{
"x": 199,
"y": 460
},
{
"x": 199,
"y": 540
},
{
"x": 105,
"y": 540
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "(b -- )[0]",
"src": "b",
"srcArrow": "none",
"srcLabel": "",
"dst": "b-lifeline-end-668380428",
"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": 670
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 1
}
]
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 326 KiB

View file

@ -0,0 +1,219 @@
{
"name": "",
"shapes": [
{
"id": "b",
"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": "b",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 13,
"labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
},
{
"id": "b.1",
"type": "rectangle",
"pos": {
"x": 93,
"y": 314
},
"width": 12,
"height": 242,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#E3E9FD",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 12,
"labelHeight": 26,
"zIndex": 2,
"level": 2
}
],
"connections": [
{
"id": "b.(1 -> 1)[0]",
"src": "b.1",
"srcArrow": "none",
"srcLabel": "",
"dst": "b.1",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"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": 105,
"y": 330
},
{
"x": 199,
"y": 330
},
{
"x": 199,
"y": 410
},
{
"x": 105,
"y": 410
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "b.(1 -> 1)[1]",
"src": "b.1",
"srcArrow": "none",
"srcLabel": "",
"dst": "b.1",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"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": 105,
"y": 460
},
{
"x": 199,
"y": 460
},
{
"x": 199,
"y": 540
},
{
"x": 105,
"y": 540
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "(b -- )[0]",
"src": "b",
"srcArrow": "none",
"srcLabel": "",
"dst": "b-lifeline-end-668380428",
"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": 670
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 1
}
]
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 326 KiB