fix constant-near panic
This commit is contained in:
parent
5a727071ea
commit
320d631113
7 changed files with 411 additions and 37 deletions
|
|
@ -27,12 +27,12 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje
|
||||||
// So place the center ones first, then the later ones will consider them for bounding box
|
// So place the center ones first, then the later ones will consider them for bounding box
|
||||||
for _, processCenters := range []bool{true, false} {
|
for _, processCenters := range []bool{true, false} {
|
||||||
for _, obj := range constantNears {
|
for _, obj := range constantNears {
|
||||||
if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") {
|
if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "-center") {
|
||||||
obj.TopLeft = geo.NewPoint(place(obj))
|
obj.TopLeft = geo.NewPoint(place(obj))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, obj := range constantNears {
|
for _, obj := range constantNears {
|
||||||
if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") {
|
if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "-center") {
|
||||||
// The z-index for constant nears does not matter, as it will not collide
|
// The z-index for constant nears does not matter, as it will not collide
|
||||||
g.Objects = append(g.Objects, obj)
|
g.Objects = append(g.Objects, obj)
|
||||||
obj.Parent.Children[obj.ID] = obj
|
obj.Parent.Children[obj.ID] = obj
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ func WithoutSequenceDiagrams(ctx context.Context, g *d2graph.Graph) (map[string]
|
||||||
edgesToRemove := make(map[*d2graph.Edge]struct{})
|
edgesToRemove := make(map[*d2graph.Edge]struct{})
|
||||||
sequenceDiagrams := make(map[string]*sequenceDiagram)
|
sequenceDiagrams := make(map[string]*sequenceDiagram)
|
||||||
|
|
||||||
|
if len(g.Objects) > 0 {
|
||||||
queue := make([]*d2graph.Object, 1, len(g.Objects))
|
queue := make([]*d2graph.Object, 1, len(g.Objects))
|
||||||
queue[0] = g.Root
|
queue[0] = g.Root
|
||||||
for len(queue) > 0 {
|
for len(queue) > 0 {
|
||||||
|
|
@ -56,6 +57,7 @@ func WithoutSequenceDiagrams(ctx context.Context, g *d2graph.Graph) (map[string]
|
||||||
objectsToRemove[obj] = struct{}{}
|
objectsToRemove[obj] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
layoutEdges, edgeOrder := getLayoutEdges(g, edgesToRemove)
|
layoutEdges, edgeOrder := getLayoutEdges(g, edgesToRemove)
|
||||||
g.Edges = layoutEdges
|
g.Edges = layoutEdges
|
||||||
|
|
|
||||||
|
|
@ -1815,6 +1815,20 @@ x.y -> a.b: {
|
||||||
style.animated: true
|
style.animated: true
|
||||||
target-arrowhead.shape: cf-many
|
target-arrowhead.shape: cf-many
|
||||||
}
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "near-alone",
|
||||||
|
script: `
|
||||||
|
x: {
|
||||||
|
near: top-center
|
||||||
|
}
|
||||||
|
y: {
|
||||||
|
near: bottom-center
|
||||||
|
}
|
||||||
|
z: {
|
||||||
|
near: center-left
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
127
e2etests/testdata/stable/near-alone/dagre/board.exp.json
generated
vendored
Normal file
127
e2etests/testdata/stable/near-alone/dagre/board.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,127 @@
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"fontFamily": "SourceSansPro",
|
||||||
|
"shapes": [
|
||||||
|
{
|
||||||
|
"id": "x",
|
||||||
|
"type": "",
|
||||||
|
"pos": {
|
||||||
|
"x": -56,
|
||||||
|
"y": -146
|
||||||
|
},
|
||||||
|
"width": 113,
|
||||||
|
"height": 126,
|
||||||
|
"opacity": 1,
|
||||||
|
"strokeDash": 0,
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"borderRadius": 0,
|
||||||
|
"fill": "#F7F8FE",
|
||||||
|
"stroke": "#0D32B2",
|
||||||
|
"shadow": false,
|
||||||
|
"3d": false,
|
||||||
|
"multiple": false,
|
||||||
|
"tooltip": "",
|
||||||
|
"link": "",
|
||||||
|
"icon": null,
|
||||||
|
"iconPosition": "",
|
||||||
|
"blend": false,
|
||||||
|
"fields": null,
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "x",
|
||||||
|
"fontSize": 16,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": true,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 13,
|
||||||
|
"labelHeight": 26,
|
||||||
|
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "y",
|
||||||
|
"type": "",
|
||||||
|
"pos": {
|
||||||
|
"x": -57,
|
||||||
|
"y": 20
|
||||||
|
},
|
||||||
|
"width": 114,
|
||||||
|
"height": 126,
|
||||||
|
"opacity": 1,
|
||||||
|
"strokeDash": 0,
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"borderRadius": 0,
|
||||||
|
"fill": "#F7F8FE",
|
||||||
|
"stroke": "#0D32B2",
|
||||||
|
"shadow": false,
|
||||||
|
"3d": false,
|
||||||
|
"multiple": false,
|
||||||
|
"tooltip": "",
|
||||||
|
"link": "",
|
||||||
|
"icon": null,
|
||||||
|
"iconPosition": "",
|
||||||
|
"blend": false,
|
||||||
|
"fields": null,
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "y",
|
||||||
|
"fontSize": 16,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": true,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 14,
|
||||||
|
"labelHeight": 26,
|
||||||
|
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "z",
|
||||||
|
"type": "",
|
||||||
|
"pos": {
|
||||||
|
"x": -189,
|
||||||
|
"y": 0
|
||||||
|
},
|
||||||
|
"width": 112,
|
||||||
|
"height": 126,
|
||||||
|
"opacity": 1,
|
||||||
|
"strokeDash": 0,
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"borderRadius": 0,
|
||||||
|
"fill": "#F7F8FE",
|
||||||
|
"stroke": "#0D32B2",
|
||||||
|
"shadow": false,
|
||||||
|
"3d": false,
|
||||||
|
"multiple": false,
|
||||||
|
"tooltip": "",
|
||||||
|
"link": "",
|
||||||
|
"icon": null,
|
||||||
|
"iconPosition": "",
|
||||||
|
"blend": false,
|
||||||
|
"fields": null,
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "z",
|
||||||
|
"fontSize": 16,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": true,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 12,
|
||||||
|
"labelHeight": 26,
|
||||||
|
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"connections": []
|
||||||
|
}
|
||||||
52
e2etests/testdata/stable/near-alone/dagre/sketch.exp.svg
vendored
Normal file
52
e2etests/testdata/stable/near-alone/dagre/sketch.exp.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 325 KiB |
127
e2etests/testdata/stable/near-alone/elk/board.exp.json
generated
vendored
Normal file
127
e2etests/testdata/stable/near-alone/elk/board.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,127 @@
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"fontFamily": "SourceSansPro",
|
||||||
|
"shapes": [
|
||||||
|
{
|
||||||
|
"id": "x",
|
||||||
|
"type": "",
|
||||||
|
"pos": {
|
||||||
|
"x": -56,
|
||||||
|
"y": -146
|
||||||
|
},
|
||||||
|
"width": 113,
|
||||||
|
"height": 126,
|
||||||
|
"opacity": 1,
|
||||||
|
"strokeDash": 0,
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"borderRadius": 0,
|
||||||
|
"fill": "#F7F8FE",
|
||||||
|
"stroke": "#0D32B2",
|
||||||
|
"shadow": false,
|
||||||
|
"3d": false,
|
||||||
|
"multiple": false,
|
||||||
|
"tooltip": "",
|
||||||
|
"link": "",
|
||||||
|
"icon": null,
|
||||||
|
"iconPosition": "",
|
||||||
|
"blend": false,
|
||||||
|
"fields": null,
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "x",
|
||||||
|
"fontSize": 16,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": true,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 13,
|
||||||
|
"labelHeight": 26,
|
||||||
|
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "y",
|
||||||
|
"type": "",
|
||||||
|
"pos": {
|
||||||
|
"x": -57,
|
||||||
|
"y": 20
|
||||||
|
},
|
||||||
|
"width": 114,
|
||||||
|
"height": 126,
|
||||||
|
"opacity": 1,
|
||||||
|
"strokeDash": 0,
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"borderRadius": 0,
|
||||||
|
"fill": "#F7F8FE",
|
||||||
|
"stroke": "#0D32B2",
|
||||||
|
"shadow": false,
|
||||||
|
"3d": false,
|
||||||
|
"multiple": false,
|
||||||
|
"tooltip": "",
|
||||||
|
"link": "",
|
||||||
|
"icon": null,
|
||||||
|
"iconPosition": "",
|
||||||
|
"blend": false,
|
||||||
|
"fields": null,
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "y",
|
||||||
|
"fontSize": 16,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": true,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 14,
|
||||||
|
"labelHeight": 26,
|
||||||
|
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "z",
|
||||||
|
"type": "",
|
||||||
|
"pos": {
|
||||||
|
"x": -189,
|
||||||
|
"y": 0
|
||||||
|
},
|
||||||
|
"width": 112,
|
||||||
|
"height": 126,
|
||||||
|
"opacity": 1,
|
||||||
|
"strokeDash": 0,
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"borderRadius": 0,
|
||||||
|
"fill": "#F7F8FE",
|
||||||
|
"stroke": "#0D32B2",
|
||||||
|
"shadow": false,
|
||||||
|
"3d": false,
|
||||||
|
"multiple": false,
|
||||||
|
"tooltip": "",
|
||||||
|
"link": "",
|
||||||
|
"icon": null,
|
||||||
|
"iconPosition": "",
|
||||||
|
"blend": false,
|
||||||
|
"fields": null,
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "z",
|
||||||
|
"fontSize": 16,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": true,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 12,
|
||||||
|
"labelHeight": 26,
|
||||||
|
"labelPosition": "INSIDE_MIDDLE_CENTER",
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"connections": []
|
||||||
|
}
|
||||||
52
e2etests/testdata/stable/near-alone/elk/sketch.exp.svg
vendored
Normal file
52
e2etests/testdata/stable/near-alone/elk/sketch.exp.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 325 KiB |
Loading…
Reference in a new issue