restrict edges in grid diagrams to between direct children (nested not implemented yet)

This commit is contained in:
Gavin Nishizawa 2023-09-12 22:17:57 -07:00
parent f4b153d059
commit 64313e1787
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
3 changed files with 33 additions and 3 deletions

View file

@ -1074,9 +1074,16 @@ func (c *compiler) validateEdges(g *d2graph.Graph) {
for _, edge := range g.Edges {
srcGrid := edge.Src.Parent.ClosestGridDiagram()
dstGrid := edge.Dst.Parent.ClosestGridDiagram()
if (srcGrid != nil || dstGrid != nil) && srcGrid != dstGrid {
c.errorf(edge.GetAstEdge(), "edges into grid diagrams are not supported yet")
continue
if srcGrid != nil || dstGrid != nil {
if srcGrid != dstGrid {
c.errorf(edge.GetAstEdge(), "edges into grid diagrams are not supported yet")
continue
} else {
if srcGrid != edge.Src.Parent || dstGrid != edge.Dst.Parent {
c.errorf(edge.GetAstEdge(), "grid diagrams can only have edges between children right now")
continue
}
}
}
}
}

View file

@ -2488,6 +2488,18 @@ d2/testdata/d2compiler/TestCompile/grid_gap_negative.d2:3:16: vertical-gap must
d2/testdata/d2compiler/TestCompile/grid_edge.d2:6:2: edges into grid diagrams are not supported yet
d2/testdata/d2compiler/TestCompile/grid_edge.d2:7:2: edges into grid diagrams are not supported yet`,
},
{
name: "grid_deeper_edge",
text: `hey: {
grid-rows: 1
a -> b: ok
b: {
c -> d: not yet
}
}
`,
expErr: `d2/testdata/d2compiler/TestCompile/grid_deeper_edge.d2:5:3: grid diagrams can only have edges between children right now`,
},
{
name: "grid_nested",
text: `hey: {

View file

@ -0,0 +1,11 @@
{
"graph": null,
"err": {
"errs": [
{
"range": "d2/testdata/d2compiler/TestCompile/grid_deeper_edge.d2,4:2:41-4:8:47",
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_deeper_edge.d2:5:3: grid diagrams can only have edges between children right now"
}
]
}
}