cleanup
This commit is contained in:
parent
bab54b4030
commit
37fc3ea8e0
8 changed files with 24 additions and 22 deletions
|
|
@ -708,7 +708,8 @@ func (c *compiler) validateKey(obj *d2graph.Object, f *d2ir.Field) {
|
|||
case "rows", "columns":
|
||||
for _, child := range obj.ChildrenArray {
|
||||
if child.IsContainer() {
|
||||
c.errorf(f.LastPrimaryKey(), fmt.Sprintf(`invalid grid diagram %#v. can only set %#v with no descendants (see %#v)`, obj.AbsID(), keyword, child.ChildrenArray[0].AbsID()))
|
||||
c.errorf(f.LastPrimaryKey(),
|
||||
fmt.Sprintf(`%#v can only be used on containers with one level of nesting right now. (%#v has nested %#v)`, keyword, child.AbsID(), child.ChildrenArray[0].ID))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -796,12 +797,12 @@ func (c *compiler) validateNear(g *d2graph.Graph) {
|
|||
|
||||
func (c *compiler) validateEdges(g *d2graph.Graph) {
|
||||
for _, edge := range g.Edges {
|
||||
if gd := edge.Src.ClosestGridDiagram(); gd != nil {
|
||||
c.errorf(edge.GetAstEdge(), "edge %#v cannot enter grid diagram %#v", d2format.Format(edge.GetAstEdge()), gd.AbsID())
|
||||
if gd := edge.Src.Parent.ClosestGridDiagram(); gd != nil {
|
||||
c.errorf(edge.GetAstEdge(), "edges in grid diagrams are not supported yet")
|
||||
continue
|
||||
}
|
||||
if gd := edge.Dst.ClosestGridDiagram(); gd != nil {
|
||||
c.errorf(edge.GetAstEdge(), "edge %#v cannot enter grid diagram %#v", d2format.Format(edge.GetAstEdge()), gd.AbsID())
|
||||
if gd := edge.Dst.Parent.ClosestGridDiagram(); gd != nil {
|
||||
c.errorf(edge.GetAstEdge(), "edges in grid diagrams are not supported yet")
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2299,9 +2299,9 @@ obj {
|
|||
|
||||
hey -> c: ok
|
||||
`,
|
||||
expErr: `d2/testdata/d2compiler/TestCompile/grid_edge.d2:3:2: edge "a -> b" cannot enter grid diagram "hey"
|
||||
d2/testdata/d2compiler/TestCompile/grid_edge.d2:5:2: edge "c -> hey.b" cannot enter grid diagram "hey"
|
||||
d2/testdata/d2compiler/TestCompile/grid_edge.d2:6:2: edge "hey.a -> c" cannot enter grid diagram "hey"`,
|
||||
expErr: `d2/testdata/d2compiler/TestCompile/grid_edge.d2:3:2: edges in grid diagrams are not supported yet
|
||||
d2/testdata/d2compiler/TestCompile/grid_edge.d2:5:2: edges in grid diagrams are not supported yet
|
||||
d2/testdata/d2compiler/TestCompile/grid_edge.d2:6:2: edges in grid diagrams are not supported yet`,
|
||||
},
|
||||
{
|
||||
name: "grid_nested",
|
||||
|
|
@ -2315,8 +2315,8 @@ d2/testdata/d2compiler/TestCompile/grid_edge.d2:6:2: edge "hey.a -> c" cannot en
|
|||
d.invalid descendant
|
||||
}
|
||||
`,
|
||||
expErr: `d2/testdata/d2compiler/TestCompile/grid_nested.d2:2:2: invalid grid diagram "hey". can only set "rows" with no descendants (see "hey.d.invalid descendant")
|
||||
d2/testdata/d2compiler/TestCompile/grid_nested.d2:3:2: invalid grid diagram "hey". can only set "columns" with no descendants (see "hey.d.invalid descendant")`,
|
||||
expErr: `d2/testdata/d2compiler/TestCompile/grid_nested.d2:2:2: "rows" can only be used on containers with one level of nesting right now. ("hey.d" has nested "invalid descendant")
|
||||
d2/testdata/d2compiler/TestCompile/grid_nested.d2:3:2: "columns" can only be used on containers with one level of nesting right now. ("hey.d" has nested "invalid descendant")`,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ func (obj *Object) IsGridDiagram() bool {
|
|||
}
|
||||
|
||||
func (obj *Object) ClosestGridDiagram() *Object {
|
||||
if obj.Parent == nil {
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
if obj.Parent.IsGridDiagram() {
|
||||
return obj.Parent
|
||||
if obj.IsGridDiagram() {
|
||||
return obj
|
||||
}
|
||||
return obj.Parent.ClosestGridDiagram()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package d2grid
|
|||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"oss.terrastruct.com/d2/d2graph"
|
||||
)
|
||||
|
|
@ -79,7 +80,7 @@ func (gd *gridDiagram) cleanup(obj *d2graph.Object, graph *d2graph.Graph) {
|
|||
obj.Children = make(map[string]*d2graph.Object)
|
||||
obj.ChildrenArray = make([]*d2graph.Object, 0)
|
||||
for _, child := range gd.objects {
|
||||
obj.Children[child.ID] = child
|
||||
obj.Children[strings.ToLower(child.ID)] = child
|
||||
obj.ChildrenArray = append(obj.ChildrenArray, child)
|
||||
}
|
||||
graph.Objects = append(graph.Objects, gd.objects...)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje
|
|||
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
|
||||
g.Objects = append(g.Objects, obj)
|
||||
obj.Parent.Children[obj.ID] = obj
|
||||
obj.Parent.Children[strings.ToLower(obj.ID)] = obj
|
||||
obj.Parent.ChildrenArray = append(obj.Parent.ChildrenArray, obj)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,12 +171,12 @@ func cleanup(g *d2graph.Graph, sequenceDiagrams map[string]*sequenceDiagram, obj
|
|||
obj.Children = make(map[string]*d2graph.Object)
|
||||
obj.ChildrenArray = make([]*d2graph.Object, 0)
|
||||
for _, child := range sd.actors {
|
||||
obj.Children[child.ID] = child
|
||||
obj.Children[strings.ToLower(child.ID)] = child
|
||||
obj.ChildrenArray = append(obj.ChildrenArray, child)
|
||||
}
|
||||
for _, child := range sd.groups {
|
||||
if child.Parent.AbsID() == obj.AbsID() {
|
||||
obj.Children[child.ID] = child
|
||||
obj.Children[strings.ToLower(child.ID)] = child
|
||||
obj.ChildrenArray = append(obj.ChildrenArray, child)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
6
testdata/d2compiler/TestCompile/grid_edge.exp.json
generated
vendored
6
testdata/d2compiler/TestCompile/grid_edge.exp.json
generated
vendored
|
|
@ -5,15 +5,15 @@
|
|||
"errs": [
|
||||
{
|
||||
"range": "d2/testdata/d2compiler/TestCompile/grid_edge.d2,2:1:17-2:7:23",
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_edge.d2:3:2: edge \"a -> b\" cannot enter grid diagram \"hey\""
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_edge.d2:3:2: edges in grid diagrams are not supported yet"
|
||||
},
|
||||
{
|
||||
"range": "d2/testdata/d2compiler/TestCompile/grid_edge.d2,4:1:27-4:11:37",
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_edge.d2:5:2: edge \"c -> hey.b\" cannot enter grid diagram \"hey\""
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_edge.d2:5:2: edges in grid diagrams are not supported yet"
|
||||
},
|
||||
{
|
||||
"range": "d2/testdata/d2compiler/TestCompile/grid_edge.d2,5:1:39-5:11:49",
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_edge.d2:6:2: edge \"hey.a -> c\" cannot enter grid diagram \"hey\""
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_edge.d2:6:2: edges in grid diagrams are not supported yet"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
4
testdata/d2compiler/TestCompile/grid_nested.exp.json
generated
vendored
4
testdata/d2compiler/TestCompile/grid_nested.exp.json
generated
vendored
|
|
@ -5,11 +5,11 @@
|
|||
"errs": [
|
||||
{
|
||||
"range": "d2/testdata/d2compiler/TestCompile/grid_nested.d2,1:1:8-1:10:17",
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_nested.d2:2:2: invalid grid diagram \"hey\". can only set \"rows\" with no descendants (see \"hey.d.invalid descendant\")"
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_nested.d2:2:2: \"rows\" can only be used on containers with one level of nesting right now. (\"hey.d\" has nested \"invalid descendant\")"
|
||||
},
|
||||
{
|
||||
"range": "d2/testdata/d2compiler/TestCompile/grid_nested.d2,2:1:19-2:13:31",
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_nested.d2:3:2: invalid grid diagram \"hey\". can only set \"columns\" with no descendants (see \"hey.d.invalid descendant\")"
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_nested.d2:3:2: \"columns\" can only be used on containers with one level of nesting right now. (\"hey.d\" has nested \"invalid descendant\")"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue