fix empty sequence panic

This commit is contained in:
Alexander Wang 2022-12-05 14:51:01 -08:00
parent d0659439af
commit 80d59be429
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
10 changed files with 348 additions and 0 deletions

View file

@ -32,6 +32,9 @@ func Layout(ctx context.Context, g *d2graph.Graph, layout func(ctx context.Conte
for len(queue) > 0 { for len(queue) > 0 {
obj := queue[0] obj := queue[0]
queue = queue[1:] queue = queue[1:]
if len(obj.ChildrenArray) == 0 {
continue
}
if obj.Attributes.Shape.Value != d2target.ShapeSequenceDiagram { if obj.Attributes.Shape.Value != d2target.ShapeSequenceDiagram {
queue = append(queue, obj.ChildrenArray...) queue = append(queue, obj.ChildrenArray...)
continue continue

View file

@ -12,6 +12,20 @@ func testRegression(t *testing.T) {
ninety\nnine ninety\nnine
eighty\reight eighty\reight
seventy\r\nseven seventy\r\nseven
`,
},
{
name: "empty_sequence",
script: `
A: hello {
shape: sequence_diagram
}
B: goodbye {
shape: sequence_diagram
}
A->B
`, `,
}, },
} }

View file

@ -23,6 +23,7 @@
"link": "", "link": "",
"icon": null, "icon": null,
"iconPosition": "", "iconPosition": "",
"blend": false,
"fields": null, "fields": null,
"methods": null, "methods": null,
"columns": null, "columns": null,
@ -62,6 +63,7 @@
"link": "", "link": "",
"icon": null, "icon": null,
"iconPosition": "", "iconPosition": "",
"blend": false,
"fields": null, "fields": null,
"methods": null, "methods": null,
"columns": null, "columns": null,
@ -101,6 +103,7 @@
"link": "", "link": "",
"icon": null, "icon": null,
"iconPosition": "", "iconPosition": "",
"blend": false,
"fields": null, "fields": null,
"methods": null, "methods": null,
"columns": null, "columns": null,

View file

@ -12,6 +12,10 @@ width="784" height="342" viewBox="-100 -100 784 342"><style type="text/css">
stroke-linecap: round; stroke-linecap: round;
stroke-linejoin: round; stroke-linejoin: round;
} }
.blend {
mix-blend-mode: multiply;
opacity: 0.5;
}
]]> ]]>
</style><g id="&#34;ninety\nnine&#34;"><g class="shape" ><rect x="0" y="0" width="151" height="142" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="75.500000" y="66.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25"><tspan x="75.500000" dy="0.000000">ninety</tspan><tspan x="75.500000" dy="21.000000">nine</tspan></text></g><g id="eighty&#xD;eight"><g class="shape" ><rect x="211" y="8" width="151" height="126" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="286.500000" y="74.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">eighty&#xD;eight</text></g><g id="&#34;seventy&#xD;\nseven&#34;"><g class="shape" ><rect x="422" y="0" width="162" height="142" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="503.000000" y="66.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25"><tspan x="503.000000" dy="0.000000">seventy&#xD;</tspan><tspan x="503.000000" dy="21.000000">seven</tspan></text></g><style type="text/css"><![CDATA[ </style><g id="&#34;ninety\nnine&#34;"><g class="shape" ><rect x="0" y="0" width="151" height="142" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="75.500000" y="66.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25"><tspan x="75.500000" dy="0.000000">ninety</tspan><tspan x="75.500000" dy="21.000000">nine</tspan></text></g><g id="eighty&#xD;eight"><g class="shape" ><rect x="211" y="8" width="151" height="126" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="286.500000" y="74.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">eighty&#xD;eight</text></g><g id="&#34;seventy&#xD;\nseven&#34;"><g class="shape" ><rect x="422" y="0" width="162" height="142" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="503.000000" y="66.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25"><tspan x="503.000000" dy="0.000000">seventy&#xD;</tspan><tspan x="503.000000" dy="21.000000">seven</tspan></text></g><style type="text/css"><![CDATA[

Before

Width:  |  Height:  |  Size: 324 KiB

After

Width:  |  Height:  |  Size: 324 KiB

View file

@ -23,6 +23,7 @@
"link": "", "link": "",
"icon": null, "icon": null,
"iconPosition": "", "iconPosition": "",
"blend": false,
"fields": null, "fields": null,
"methods": null, "methods": null,
"columns": null, "columns": null,
@ -62,6 +63,7 @@
"link": "", "link": "",
"icon": null, "icon": null,
"iconPosition": "", "iconPosition": "",
"blend": false,
"fields": null, "fields": null,
"methods": null, "methods": null,
"columns": null, "columns": null,
@ -101,6 +103,7 @@
"link": "", "link": "",
"icon": null, "icon": null,
"iconPosition": "", "iconPosition": "",
"blend": false,
"fields": null, "fields": null,
"methods": null, "methods": null,
"columns": null, "columns": null,

View file

@ -12,6 +12,10 @@ width="704" height="342" viewBox="-88 -88 704 342"><style type="text/css">
stroke-linecap: round; stroke-linecap: round;
stroke-linejoin: round; stroke-linejoin: round;
} }
.blend {
mix-blend-mode: multiply;
opacity: 0.5;
}
]]> ]]>
</style><g id="&#34;ninety\nnine&#34;"><g class="shape" ><rect x="194" y="12" width="151" height="142" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="269.500000" y="78.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25"><tspan x="269.500000" dy="0.000000">ninety</tspan><tspan x="269.500000" dy="21.000000">nine</tspan></text></g><g id="eighty&#xD;eight"><g class="shape" ><rect x="365" y="20" width="151" height="126" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="440.500000" y="86.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">eighty&#xD;eight</text></g><g id="&#34;seventy&#xD;\nseven&#34;"><g class="shape" ><rect x="12" y="12" width="162" height="142" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="93.000000" y="78.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25"><tspan x="93.000000" dy="0.000000">seventy&#xD;</tspan><tspan x="93.000000" dy="21.000000">seven</tspan></text></g><style type="text/css"><![CDATA[ </style><g id="&#34;ninety\nnine&#34;"><g class="shape" ><rect x="194" y="12" width="151" height="142" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="269.500000" y="78.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25"><tspan x="269.500000" dy="0.000000">ninety</tspan><tspan x="269.500000" dy="21.000000">nine</tspan></text></g><g id="eighty&#xD;eight"><g class="shape" ><rect x="365" y="20" width="151" height="126" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="440.500000" y="86.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25">eighty&#xD;eight</text></g><g id="&#34;seventy&#xD;\nseven&#34;"><g class="shape" ><rect x="12" y="12" width="162" height="142" style="fill:#F7F8FE;stroke:#0D32B2;opacity:1.000000;stroke-width:2;" /></g><text class="text-bold" x="93.000000" y="78.000000" style="text-anchor:middle;font-size:16px;fill:#0A0F25"><tspan x="93.000000" dy="0.000000">seventy&#xD;</tspan><tspan x="93.000000" dy="21.000000">seven</tspan></text></g><style type="text/css"><![CDATA[

Before

Width:  |  Height:  |  Size: 324 KiB

After

Width:  |  Height:  |  Size: 324 KiB

View file

@ -0,0 +1,135 @@
{
"name": "",
"shapes": [
{
"id": "A",
"type": "sequence_diagram",
"pos": {
"x": 13,
"y": 0
},
"width": 140,
"height": 126,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 0,
"borderRadius": 0,
"fill": "#FFFFFF",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "hello",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 40,
"labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
},
{
"id": "B",
"type": "sequence_diagram",
"pos": {
"x": 0,
"y": 226
},
"width": 166,
"height": 126,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 0,
"borderRadius": 0,
"fill": "#FFFFFF",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "goodbye",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 66,
"labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
}
],
"connections": [
{
"id": "(A -> B)[0]",
"src": "A",
"srcArrow": "none",
"srcLabel": "",
"dst": "B",
"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": 83,
"y": 126
},
{
"x": 83,
"y": 166
},
{
"x": 83,
"y": 186
},
{
"x": 83,
"y": 226
}
],
"isCurve": true,
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 0
}
]
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 324 KiB

View file

@ -0,0 +1,126 @@
{
"name": "",
"shapes": [
{
"id": "A",
"type": "sequence_diagram",
"pos": {
"x": 25,
"y": 12
},
"width": 140,
"height": 126,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 0,
"borderRadius": 0,
"fill": "#FFFFFF",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "hello",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 40,
"labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
},
{
"id": "B",
"type": "sequence_diagram",
"pos": {
"x": 12,
"y": 238
},
"width": 166,
"height": 126,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 0,
"borderRadius": 0,
"fill": "#FFFFFF",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "goodbye",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 66,
"labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
}
],
"connections": [
{
"id": "(A -> B)[0]",
"src": "A",
"srcArrow": "none",
"srcLabel": "",
"dst": "B",
"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": 95,
"y": 138
},
{
"x": 95,
"y": 238
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 0
}
]
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 324 KiB