diff --git a/d2compiler/compile.go b/d2compiler/compile.go index c1a252440..07d450257 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -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 } } diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index a031203ea..92d8fd41e 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -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")`, }, } diff --git a/d2graph/grid_diagram.go b/d2graph/grid_diagram.go index ec41e0460..9f1aff9e9 100644 --- a/d2graph/grid_diagram.go +++ b/d2graph/grid_diagram.go @@ -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() } diff --git a/d2layouts/d2grid/grid_diagram.go b/d2layouts/d2grid/grid_diagram.go index 6b4d8dfb3..bb68aad79 100644 --- a/d2layouts/d2grid/grid_diagram.go +++ b/d2layouts/d2grid/grid_diagram.go @@ -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...) diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index 082a0e296..695fda827 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -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) } } diff --git a/d2layouts/d2sequence/layout.go b/d2layouts/d2sequence/layout.go index a2c7df0a5..0da870f19 100644 --- a/d2layouts/d2sequence/layout.go +++ b/d2layouts/d2sequence/layout.go @@ -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) } } diff --git a/testdata/d2compiler/TestCompile/grid_edge.exp.json b/testdata/d2compiler/TestCompile/grid_edge.exp.json index dee805205..d8b36c51b 100644 --- a/testdata/d2compiler/TestCompile/grid_edge.exp.json +++ b/testdata/d2compiler/TestCompile/grid_edge.exp.json @@ -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" } ] } diff --git a/testdata/d2compiler/TestCompile/grid_nested.exp.json b/testdata/d2compiler/TestCompile/grid_nested.exp.json index a45781692..ff55b27e7 100644 --- a/testdata/d2compiler/TestCompile/grid_nested.exp.json +++ b/testdata/d2compiler/TestCompile/grid_nested.exp.json @@ -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\")" } ] }