diff --git a/d2layouts/d2sequence/sequence_diagram.go b/d2layouts/d2sequence/sequence_diagram.go index 3659a63b8..394adccc6 100644 --- a/d2layouts/d2sequence/sequence_diagram.go +++ b/d2layouts/d2sequence/sequence_diagram.go @@ -646,7 +646,19 @@ func (sd *sequenceDiagram) isActor(obj *d2graph.Object) bool { func (sd *sequenceDiagram) getWidth() float64 { // the layout is always placed starting at 0, so the width is just the last actor lastActor := sd.actors[len(sd.actors)-1] - return lastActor.TopLeft.X + lastActor.Width + rightmost := lastActor.TopLeft.X + lastActor.Width + + for _, m := range sd.messages { + for _, p := range m.Route { + rightmost = math.Max(rightmost, p.X) + } + // Self referential messages may have labels that extend further + if m.Src == m.Dst { + rightmost = math.Max(rightmost, m.Route[1].X+float64(m.LabelDimensions.Width)/2.) + } + } + + return rightmost } func (sd *sequenceDiagram) getHeight() float64 { diff --git a/e2etests/testdata/txtar/sequence-bounding-box/dagre/board.exp.json b/e2etests/testdata/txtar/sequence-bounding-box/dagre/board.exp.json new file mode 100644 index 000000000..93cc3aba2 --- /dev/null +++ b/e2etests/testdata/txtar/sequence-bounding-box/dagre/board.exp.json @@ -0,0 +1,256 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "backend", + "type": "rectangle", + "pos": { + "x": 10, + "y": 20 + }, + "width": 263, + "height": 406, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B4", + "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": "backend", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 98, + "labelHeight": 36, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "backend.client", + "type": "sequence_diagram", + "pos": { + "x": 40, + "y": 50 + }, + "width": 203, + "height": 346, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 0, + "borderRadius": 0, + "fill": "N7", + "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": "client", + "fontSize": 24, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 55, + "labelHeight": 31, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "backend.client.client", + "type": "rectangle", + "pos": { + "x": 52, + "y": 133 + }, + "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": "client", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 38, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 3 + } + ], + "connections": [ + { + "id": "backend.client.(client -> client)[0]", + "src": "backend.client.client", + "srcArrow": "none", + "dst": "backend.client.client", + "dstArrow": "triangle", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "BO_ID -> D2_ID", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 99, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "labelPercentage": 0, + "route": [ + { + "x": 102, + "y": 269 + }, + { + "x": 182, + "y": 269 + }, + { + "x": 182, + "y": 314 + }, + { + "x": 102, + "y": 314 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 4 + }, + { + "id": "(backend.client.client -- )[0]", + "src": "backend.client.client", + "srcArrow": "none", + "dst": "client-lifeline-end-2119091193", + "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": 102, + "y": 199 + }, + { + "x": 102, + "y": 384 + } + ], + "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 + } +} diff --git a/e2etests/testdata/txtar/sequence-bounding-box/dagre/sketch.exp.svg b/e2etests/testdata/txtar/sequence-bounding-box/dagre/sketch.exp.svg new file mode 100644 index 000000000..c86b9a754 --- /dev/null +++ b/e2etests/testdata/txtar/sequence-bounding-box/dagre/sketch.exp.svg @@ -0,0 +1,105 @@ +backendclientclient BO_ID -> D2_ID + + + + + + \ No newline at end of file diff --git a/e2etests/testdata/txtar/sequence-bounding-box/elk/board.exp.json b/e2etests/testdata/txtar/sequence-bounding-box/elk/board.exp.json new file mode 100644 index 000000000..11e468f6d --- /dev/null +++ b/e2etests/testdata/txtar/sequence-bounding-box/elk/board.exp.json @@ -0,0 +1,256 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "backend", + "type": "rectangle", + "pos": { + "x": 12, + "y": 12 + }, + "width": 304, + "height": 446, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B4", + "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": "backend", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 98, + "labelHeight": 36, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "backend.client", + "type": "sequence_diagram", + "pos": { + "x": 62, + "y": 62 + }, + "width": 204, + "height": 346, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 0, + "borderRadius": 0, + "fill": "N7", + "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": "client", + "fontSize": 24, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 55, + "labelHeight": 31, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "backend.client.client", + "type": "rectangle", + "pos": { + "x": 74, + "y": 145 + }, + "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": "client", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 38, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 3 + } + ], + "connections": [ + { + "id": "backend.client.(client -> client)[0]", + "src": "backend.client.client", + "srcArrow": "none", + "dst": "backend.client.client", + "dstArrow": "triangle", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "BO_ID -> D2_ID", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 99, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "labelPercentage": 0, + "route": [ + { + "x": 124, + "y": 281 + }, + { + "x": 204, + "y": 281 + }, + { + "x": 204, + "y": 326 + }, + { + "x": 124, + "y": 326 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 4 + }, + { + "id": "(backend.client.client -- )[0]", + "src": "backend.client.client", + "srcArrow": "none", + "dst": "client-lifeline-end-2119091193", + "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": 124, + "y": 211 + }, + { + "x": 124, + "y": 396 + } + ], + "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 + } +} diff --git a/e2etests/testdata/txtar/sequence-bounding-box/elk/sketch.exp.svg b/e2etests/testdata/txtar/sequence-bounding-box/elk/sketch.exp.svg new file mode 100644 index 000000000..a8793aa97 --- /dev/null +++ b/e2etests/testdata/txtar/sequence-bounding-box/elk/sketch.exp.svg @@ -0,0 +1,105 @@ +backendclientclient BO_ID -> D2_ID + + + + + + \ No newline at end of file diff --git a/e2etests/txtar.txt b/e2etests/txtar.txt index 7019b2258..cea8672ef 100644 --- a/e2etests/txtar.txt +++ b/e2etests/txtar.txt @@ -313,3 +313,9 @@ 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 + +-- sequence-bounding-box -- +backend.client: { + shape: sequence_diagram + client -> client: BO_ID -> D2_ID +}