diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 07d450257..c3d721bc7 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -363,32 +363,32 @@ func (c *compiler) compileReserved(attrs *d2graph.Attributes, f *d2ir.Field) { } attrs.Constraint.Value = scalar.ScalarString() attrs.Constraint.MapKey = f.LastPrimaryKey() - case "rows": + case "grid-rows": v, err := strconv.Atoi(scalar.ScalarString()) if err != nil { - c.errorf(scalar, "non-integer rows %#v: %s", scalar.ScalarString(), err) + c.errorf(scalar, "non-integer grid-rows %#v: %s", scalar.ScalarString(), err) return } if v <= 0 { - c.errorf(scalar, "rows must be a positive integer: %#v", scalar.ScalarString()) + c.errorf(scalar, "grid-rows must be a positive integer: %#v", scalar.ScalarString()) return } - attrs.Rows = &d2graph.Scalar{} - attrs.Rows.Value = scalar.ScalarString() - attrs.Rows.MapKey = f.LastPrimaryKey() - case "columns": + attrs.GridRows = &d2graph.Scalar{} + attrs.GridRows.Value = scalar.ScalarString() + attrs.GridRows.MapKey = f.LastPrimaryKey() + case "grid-columns": v, err := strconv.Atoi(scalar.ScalarString()) if err != nil { - c.errorf(scalar, "non-integer columns %#v: %s", scalar.ScalarString(), err) + c.errorf(scalar, "non-integer grid-columns %#v: %s", scalar.ScalarString(), err) return } if v <= 0 { - c.errorf(scalar, "columns must be a positive integer: %#v", scalar.ScalarString()) + c.errorf(scalar, "grid-columns must be a positive integer: %#v", scalar.ScalarString()) return } - attrs.Columns = &d2graph.Scalar{} - attrs.Columns.Value = scalar.ScalarString() - attrs.Columns.MapKey = f.LastPrimaryKey() + attrs.GridColumns = &d2graph.Scalar{} + attrs.GridColumns.Value = scalar.ScalarString() + attrs.GridColumns.MapKey = f.LastPrimaryKey() } if attrs.Link != nil && attrs.Tooltip != nil { @@ -705,7 +705,7 @@ func (c *compiler) validateKey(obj *d2graph.Object, f *d2ir.Field) { if !in && arrowheadIn { c.errorf(f.LastPrimaryKey(), fmt.Sprintf(`invalid shape, can only set "%s" for arrowheads`, obj.Attributes.Shape.Value)) } - case "rows", "columns": + case "grid-rows", "grid-columns": for _, child := range obj.ChildrenArray { if child.IsContainer() { c.errorf(f.LastPrimaryKey(), diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 92d8fd41e..89b8b04f2 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -2271,27 +2271,27 @@ obj { { name: "grid", text: `hey: { - rows: 200 - columns: 230 + grid-rows: 200 + grid-columns: 230 } `, assertions: func(t *testing.T, g *d2graph.Graph) { - tassert.Equal(t, "200", g.Objects[0].Attributes.Rows.Value) + tassert.Equal(t, "200", g.Objects[0].Attributes.GridRows.Value) }, }, { name: "grid_negative", text: `hey: { - rows: 200 - columns: -200 + grid-rows: 200 + grid-columns: -200 } `, - expErr: `d2/testdata/d2compiler/TestCompile/grid_negative.d2:3:11: columns must be a positive integer: "-200"`, + expErr: `d2/testdata/d2compiler/TestCompile/grid_negative.d2:3:16: grid-columns must be a positive integer: "-200"`, }, { name: "grid_edge", text: `hey: { - rows: 1 + grid-rows: 1 a -> b } c -> hey.b @@ -2306,8 +2306,8 @@ d2/testdata/d2compiler/TestCompile/grid_edge.d2:6:2: edges in grid diagrams are { name: "grid_nested", text: `hey: { - rows: 200 - columns: 200 + grid-rows: 200 + grid-columns: 200 a b @@ -2315,8 +2315,8 @@ d2/testdata/d2compiler/TestCompile/grid_edge.d2:6:2: edges in grid diagrams are 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")`, + expErr: `d2/testdata/d2compiler/TestCompile/grid_nested.d2:2:2: "grid-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: "grid-columns" can only be used on containers with one level of nesting right now. ("hey.d" has nested "invalid descendant")`, }, } diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index d9ae9a89d..be2892e97 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -133,8 +133,8 @@ type Attributes struct { Direction Scalar `json:"direction"` Constraint Scalar `json:"constraint"` - Rows *Scalar `json:"rows,omitempty"` - Columns *Scalar `json:"columns,omitempty"` + GridRows *Scalar `json:"gridRows,omitempty"` + GridColumns *Scalar `json:"gridColumns,omitempty"` } // TODO references at the root scope should have their Scope set to root graph AST @@ -1531,21 +1531,21 @@ var ReservedKeywords2 map[string]struct{} // Non Style/Holder keywords. var SimpleReservedKeywords = map[string]struct{}{ - "label": {}, - "desc": {}, - "shape": {}, - "icon": {}, - "constraint": {}, - "tooltip": {}, - "link": {}, - "near": {}, - "width": {}, - "height": {}, - "direction": {}, - "top": {}, - "left": {}, - "rows": {}, - "columns": {}, + "label": {}, + "desc": {}, + "shape": {}, + "icon": {}, + "constraint": {}, + "tooltip": {}, + "link": {}, + "near": {}, + "width": {}, + "height": {}, + "direction": {}, + "top": {}, + "left": {}, + "grid-rows": {}, + "grid-columns": {}, } // ReservedKeywordHolders are reserved keywords that are meaningless on its own and exist solely to hold a set of reserved keywords diff --git a/d2graph/grid_diagram.go b/d2graph/grid_diagram.go index 9f1aff9e9..6c40667a5 100644 --- a/d2graph/grid_diagram.go +++ b/d2graph/grid_diagram.go @@ -2,7 +2,7 @@ package d2graph func (obj *Object) IsGridDiagram() bool { return obj != nil && obj.Attributes != nil && - (obj.Attributes.Rows != nil || obj.Attributes.Columns != nil) + (obj.Attributes.GridRows != nil || obj.Attributes.GridColumns != nil) } func (obj *Object) ClosestGridDiagram() *Object { diff --git a/d2layouts/d2grid/grid_diagram.go b/d2layouts/d2grid/grid_diagram.go index bb68aad79..264bc07cc 100644 --- a/d2layouts/d2grid/grid_diagram.go +++ b/d2layouts/d2grid/grid_diagram.go @@ -23,11 +23,11 @@ type gridDiagram struct { func newGridDiagram(root *d2graph.Object) *gridDiagram { gd := gridDiagram{root: root, objects: root.ChildrenArray} - if root.Attributes.Rows != nil { - gd.rows, _ = strconv.Atoi(root.Attributes.Rows.Value) + if root.Attributes.GridRows != nil { + gd.rows, _ = strconv.Atoi(root.Attributes.GridRows.Value) } - if root.Attributes.Columns != nil { - gd.columns, _ = strconv.Atoi(root.Attributes.Columns.Value) + if root.Attributes.GridColumns != nil { + gd.columns, _ = strconv.Atoi(root.Attributes.GridColumns.Value) } if gd.rows != 0 && gd.columns != 0 { @@ -38,7 +38,7 @@ func newGridDiagram(root *d2graph.Object) *gridDiagram { // . │ g h i │ │ c f i │ // . └───────┘ └───────┘ // if keyword rows is first, make it row-directed, if columns is first it is column-directed - if root.Attributes.Rows.MapKey.Range.Before(root.Attributes.Columns.MapKey.Range) { + if root.Attributes.GridRows.MapKey.Range.Before(root.Attributes.GridColumns.MapKey.Range) { gd.rowDirected = true } diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 376634e22..58aaab1b6 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -314,14 +314,14 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { attrs.Left.MapKey.SetScalar(mk.Value.ScalarBox()) return nil } - case "rows": - if attrs.Rows != nil && attrs.Rows.MapKey != nil { - attrs.Rows.MapKey.SetScalar(mk.Value.ScalarBox()) + case "grid-rows": + if attrs.GridRows != nil && attrs.GridRows.MapKey != nil { + attrs.GridRows.MapKey.SetScalar(mk.Value.ScalarBox()) return nil } - case "columns": - if attrs.Columns != nil && attrs.Columns.MapKey != nil { - attrs.Columns.MapKey.SetScalar(mk.Value.ScalarBox()) + case "grid-columns": + if attrs.GridColumns != nil && attrs.GridColumns.MapKey != nil { + attrs.GridColumns.MapKey.SetScalar(mk.Value.ScalarBox()) return nil } case "source-arrowhead", "target-arrowhead": diff --git a/e2etests/testdata/files/dagger_grid.d2 b/e2etests/testdata/files/dagger_grid.d2 index dc9d8debe..2f6167c06 100644 --- a/e2etests/testdata/files/dagger_grid.d2 +++ b/e2etests/testdata/files/dagger_grid.d2 @@ -1,4 +1,4 @@ -rows: 5 +grid-rows: 5 style.fill: black flow1: "" { diff --git a/e2etests/testdata/files/executive_grid.d2 b/e2etests/testdata/files/executive_grid.d2 index 4a3a5c3ab..a5178fbd6 100644 --- a/e2etests/testdata/files/executive_grid.d2 +++ b/e2etests/testdata/files/executive_grid.d2 @@ -1,4 +1,4 @@ -rows: 3 +grid-rows: 3 Executive Services.width: 1000 diff --git a/e2etests/testdata/files/grid_tests.d2 b/e2etests/testdata/files/grid_tests.d2 index 501c9ea24..aab1481e9 100644 --- a/e2etests/testdata/files/grid_tests.d2 +++ b/e2etests/testdata/files/grid_tests.d2 @@ -1,5 +1,5 @@ rows 1: { - rows: 1 + grid-rows: 1 a b c @@ -10,7 +10,7 @@ rows 1: { } columns 1: { - columns: 1 + grid-columns: 1 a b c @@ -21,7 +21,7 @@ columns 1: { } rows 2: { - rows: 2 + grid-rows: 2 a b c @@ -32,7 +32,7 @@ rows 2: { } columns 2: { - columns: 2 + grid-columns: 2 a b c @@ -43,8 +43,8 @@ columns 2: { } rows 2 columns 2: { - rows: 2 - columns: 2 + grid-rows: 2 + grid-columns: 2 a b @@ -56,8 +56,8 @@ rows 2 columns 2: { } columns 2 rows 2: { - columns: 2 - rows: 2 + grid-columns: 2 + grid-rows: 2 a b @@ -69,8 +69,8 @@ columns 2 rows 2: { } rows 3 columns 3: { - rows: 3 - columns: 3 + grid-rows: 3 + grid-columns: 3 a b @@ -82,8 +82,8 @@ rows 3 columns 3: { } columns 3 rows 3: { - columns: 3 - rows: 3 + grid-columns: 3 + grid-rows: 3 a b @@ -95,7 +95,7 @@ columns 3 rows 3: { } rows 3: { - rows: 3 + grid-rows: 3 a b @@ -107,7 +107,7 @@ rows 3: { } columns 3: { - columns: 3 + grid-columns: 3 a b @@ -119,8 +119,8 @@ columns 3: { } widths heights: { - rows: 3 - columns: 3 + grid-rows: 3 + grid-columns: 3 a w200.width: 200 b h300.height: 300 diff --git a/e2etests/testdata/files/teleport_grid.d2 b/e2etests/testdata/files/teleport_grid.d2 index baec9fe60..d0e737513 100644 --- a/e2etests/testdata/files/teleport_grid.d2 +++ b/e2etests/testdata/files/teleport_grid.d2 @@ -9,7 +9,7 @@ teleport -> identity provider teleport <- identity provider users: "" { - columns: 1 + grid-columns: 1 Engineers: { shape: circle @@ -22,7 +22,7 @@ users: "" { } via: "" { - columns: 1 + grid-columns: 1 https: "HTTPS://" kubectl: "> kubectl" @@ -32,7 +32,7 @@ via: "" { } teleport: Teleport { - rows: 2 + grid-rows: 2 inp: |md # Identity Native Proxy @@ -45,7 +45,7 @@ teleport: Teleport { } jita: "Just-in-time Access via" { - rows: 1 + grid-rows: 1 Slack.icon: https://icons.terrastruct.com/dev%2Fslack.svg Mattermost @@ -55,7 +55,7 @@ jita: "Just-in-time Access via" { } infra: Infrastructure { - rows: 2 + grid-rows: 2 ssh.icon: https://icons.terrastruct.com/essentials%2F112-server.svg Kubernetes.icon: https://icons.terrastruct.com/azure%2F_Companies%2FKubernetes.svg diff --git a/testdata/d2compiler/TestCompile/grid.exp.json b/testdata/d2compiler/TestCompile/grid.exp.json index 8cad38d75..8b4e621bc 100644 --- a/testdata/d2compiler/TestCompile/grid.exp.json +++ b/testdata/d2compiler/TestCompile/grid.exp.json @@ -3,11 +3,11 @@ "name": "", "isFolderOnly": false, "ast": { - "range": "d2/testdata/d2compiler/TestCompile/grid.d2,0:0:0-4:0:34", + "range": "d2/testdata/d2compiler/TestCompile/grid.d2,0:0:0-4:0:44", "nodes": [ { "map_key": { - "range": "d2/testdata/d2compiler/TestCompile/grid.d2,0:0:0-3:1:33", + "range": "d2/testdata/d2compiler/TestCompile/grid.d2,0:0:0-3:1:43", "key": { "range": "d2/testdata/d2compiler/TestCompile/grid.d2,0:0:0-0:3:3", "path": [ @@ -27,21 +27,21 @@ "primary": {}, "value": { "map": { - "range": "d2/testdata/d2compiler/TestCompile/grid.d2,0:5:5-3:0:32", + "range": "d2/testdata/d2compiler/TestCompile/grid.d2,0:5:5-3:0:42", "nodes": [ { "map_key": { - "range": "d2/testdata/d2compiler/TestCompile/grid.d2,1:1:8-1:10:17", + "range": "d2/testdata/d2compiler/TestCompile/grid.d2,1:1:8-1:15:22", "key": { - "range": "d2/testdata/d2compiler/TestCompile/grid.d2,1:1:8-1:5:12", + "range": "d2/testdata/d2compiler/TestCompile/grid.d2,1:1:8-1:10:17", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/grid.d2,1:1:8-1:5:12", + "range": "d2/testdata/d2compiler/TestCompile/grid.d2,1:1:8-1:10:17", "value": [ { - "string": "rows", - "raw_string": "rows" + "string": "grid-rows", + "raw_string": "grid-rows" } ] } @@ -51,7 +51,7 @@ "primary": {}, "value": { "number": { - "range": "d2/testdata/d2compiler/TestCompile/grid.d2,1:7:14-1:10:17", + "range": "d2/testdata/d2compiler/TestCompile/grid.d2,1:12:19-1:15:22", "raw": "200", "value": "200" } @@ -60,17 +60,17 @@ }, { "map_key": { - "range": "d2/testdata/d2compiler/TestCompile/grid.d2,2:1:19-2:13:31", + "range": "d2/testdata/d2compiler/TestCompile/grid.d2,2:1:24-2:18:41", "key": { - "range": "d2/testdata/d2compiler/TestCompile/grid.d2,2:1:19-2:8:26", + "range": "d2/testdata/d2compiler/TestCompile/grid.d2,2:1:24-2:13:36", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/grid.d2,2:1:19-2:8:26", + "range": "d2/testdata/d2compiler/TestCompile/grid.d2,2:1:24-2:13:36", "value": [ { - "string": "columns", - "raw_string": "columns" + "string": "grid-columns", + "raw_string": "grid-columns" } ] } @@ -80,7 +80,7 @@ "primary": {}, "value": { "number": { - "range": "d2/testdata/d2compiler/TestCompile/grid.d2,2:10:28-2:13:31", + "range": "d2/testdata/d2compiler/TestCompile/grid.d2,2:15:38-2:18:41", "raw": "230", "value": "230" } @@ -165,10 +165,10 @@ "constraint": { "value": "" }, - "rows": { + "gridRows": { "value": "200" }, - "columns": { + "gridColumns": { "value": "230" } }, diff --git a/testdata/d2compiler/TestCompile/grid_edge.exp.json b/testdata/d2compiler/TestCompile/grid_edge.exp.json index d8b36c51b..52a77accb 100644 --- a/testdata/d2compiler/TestCompile/grid_edge.exp.json +++ b/testdata/d2compiler/TestCompile/grid_edge.exp.json @@ -4,15 +4,15 @@ "ioerr": null, "errs": [ { - "range": "d2/testdata/d2compiler/TestCompile/grid_edge.d2,2:1:17-2:7:23", + "range": "d2/testdata/d2compiler/TestCompile/grid_edge.d2,2:1:22-2:7:28", "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", + "range": "d2/testdata/d2compiler/TestCompile/grid_edge.d2,4:1:32-4:11:42", "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", + "range": "d2/testdata/d2compiler/TestCompile/grid_edge.d2,5:1:44-5:11:54", "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_negative.exp.json b/testdata/d2compiler/TestCompile/grid_negative.exp.json index 5551871da..7999bc2b6 100644 --- a/testdata/d2compiler/TestCompile/grid_negative.exp.json +++ b/testdata/d2compiler/TestCompile/grid_negative.exp.json @@ -4,8 +4,8 @@ "ioerr": null, "errs": [ { - "range": "d2/testdata/d2compiler/TestCompile/grid_negative.d2,2:10:28-2:14:32", - "errmsg": "d2/testdata/d2compiler/TestCompile/grid_negative.d2:3:11: columns must be a positive integer: \"-200\"" + "range": "d2/testdata/d2compiler/TestCompile/grid_negative.d2,2:15:38-2:19:42", + "errmsg": "d2/testdata/d2compiler/TestCompile/grid_negative.d2:3:16: grid-columns must be a positive integer: \"-200\"" } ] } diff --git a/testdata/d2compiler/TestCompile/grid_nested.exp.json b/testdata/d2compiler/TestCompile/grid_nested.exp.json index ff55b27e7..c8db27f4f 100644 --- a/testdata/d2compiler/TestCompile/grid_nested.exp.json +++ b/testdata/d2compiler/TestCompile/grid_nested.exp.json @@ -4,12 +4,12 @@ "ioerr": null, "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: \"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,1:1:8-1:15:22", + "errmsg": "d2/testdata/d2compiler/TestCompile/grid_nested.d2:2:2: \"grid-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: \"columns\" 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:24-2:18:41", + "errmsg": "d2/testdata/d2compiler/TestCompile/grid_nested.d2:3:2: \"grid-columns\" can only be used on containers with one level of nesting right now. (\"hey.d\" has nested \"invalid descendant\")" } ] }