update keywords rows -> grid-rows

This commit is contained in:
Gavin Nishizawa 2023-04-06 15:43:03 -07:00
parent 37fc3ea8e0
commit a75d4dd0b9
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
14 changed files with 102 additions and 102 deletions

View file

@ -363,32 +363,32 @@ func (c *compiler) compileReserved(attrs *d2graph.Attributes, f *d2ir.Field) {
} }
attrs.Constraint.Value = scalar.ScalarString() attrs.Constraint.Value = scalar.ScalarString()
attrs.Constraint.MapKey = f.LastPrimaryKey() attrs.Constraint.MapKey = f.LastPrimaryKey()
case "rows": case "grid-rows":
v, err := strconv.Atoi(scalar.ScalarString()) v, err := strconv.Atoi(scalar.ScalarString())
if err != nil { 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 return
} }
if v <= 0 { 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 return
} }
attrs.Rows = &d2graph.Scalar{} attrs.GridRows = &d2graph.Scalar{}
attrs.Rows.Value = scalar.ScalarString() attrs.GridRows.Value = scalar.ScalarString()
attrs.Rows.MapKey = f.LastPrimaryKey() attrs.GridRows.MapKey = f.LastPrimaryKey()
case "columns": case "grid-columns":
v, err := strconv.Atoi(scalar.ScalarString()) v, err := strconv.Atoi(scalar.ScalarString())
if err != nil { 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 return
} }
if v <= 0 { 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 return
} }
attrs.Columns = &d2graph.Scalar{} attrs.GridColumns = &d2graph.Scalar{}
attrs.Columns.Value = scalar.ScalarString() attrs.GridColumns.Value = scalar.ScalarString()
attrs.Columns.MapKey = f.LastPrimaryKey() attrs.GridColumns.MapKey = f.LastPrimaryKey()
} }
if attrs.Link != nil && attrs.Tooltip != nil { if attrs.Link != nil && attrs.Tooltip != nil {
@ -705,7 +705,7 @@ func (c *compiler) validateKey(obj *d2graph.Object, f *d2ir.Field) {
if !in && arrowheadIn { if !in && arrowheadIn {
c.errorf(f.LastPrimaryKey(), fmt.Sprintf(`invalid shape, can only set "%s" for arrowheads`, obj.Attributes.Shape.Value)) 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 { for _, child := range obj.ChildrenArray {
if child.IsContainer() { if child.IsContainer() {
c.errorf(f.LastPrimaryKey(), c.errorf(f.LastPrimaryKey(),

View file

@ -2271,27 +2271,27 @@ obj {
{ {
name: "grid", name: "grid",
text: `hey: { text: `hey: {
rows: 200 grid-rows: 200
columns: 230 grid-columns: 230
} }
`, `,
assertions: func(t *testing.T, g *d2graph.Graph) { 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", name: "grid_negative",
text: `hey: { text: `hey: {
rows: 200 grid-rows: 200
columns: -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", name: "grid_edge",
text: `hey: { text: `hey: {
rows: 1 grid-rows: 1
a -> b a -> b
} }
c -> hey.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", name: "grid_nested",
text: `hey: { text: `hey: {
rows: 200 grid-rows: 200
columns: 200 grid-columns: 200
a a
b b
@ -2315,8 +2315,8 @@ d2/testdata/d2compiler/TestCompile/grid_edge.d2:6:2: edges in grid diagrams are
d.invalid descendant 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") 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: "columns" 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")`,
}, },
} }

View file

@ -133,8 +133,8 @@ type Attributes struct {
Direction Scalar `json:"direction"` Direction Scalar `json:"direction"`
Constraint Scalar `json:"constraint"` Constraint Scalar `json:"constraint"`
Rows *Scalar `json:"rows,omitempty"` GridRows *Scalar `json:"gridRows,omitempty"`
Columns *Scalar `json:"columns,omitempty"` GridColumns *Scalar `json:"gridColumns,omitempty"`
} }
// TODO references at the root scope should have their Scope set to root graph AST // TODO references at the root scope should have their Scope set to root graph AST
@ -1544,8 +1544,8 @@ var SimpleReservedKeywords = map[string]struct{}{
"direction": {}, "direction": {},
"top": {}, "top": {},
"left": {}, "left": {},
"rows": {}, "grid-rows": {},
"columns": {}, "grid-columns": {},
} }
// ReservedKeywordHolders are reserved keywords that are meaningless on its own and exist solely to hold a set of reserved keywords // ReservedKeywordHolders are reserved keywords that are meaningless on its own and exist solely to hold a set of reserved keywords

View file

@ -2,7 +2,7 @@ package d2graph
func (obj *Object) IsGridDiagram() bool { func (obj *Object) IsGridDiagram() bool {
return obj != nil && obj.Attributes != nil && 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 { func (obj *Object) ClosestGridDiagram() *Object {

View file

@ -23,11 +23,11 @@ type gridDiagram struct {
func newGridDiagram(root *d2graph.Object) *gridDiagram { func newGridDiagram(root *d2graph.Object) *gridDiagram {
gd := gridDiagram{root: root, objects: root.ChildrenArray} gd := gridDiagram{root: root, objects: root.ChildrenArray}
if root.Attributes.Rows != nil { if root.Attributes.GridRows != nil {
gd.rows, _ = strconv.Atoi(root.Attributes.Rows.Value) gd.rows, _ = strconv.Atoi(root.Attributes.GridRows.Value)
} }
if root.Attributes.Columns != nil { if root.Attributes.GridColumns != nil {
gd.columns, _ = strconv.Atoi(root.Attributes.Columns.Value) gd.columns, _ = strconv.Atoi(root.Attributes.GridColumns.Value)
} }
if gd.rows != 0 && gd.columns != 0 { if gd.rows != 0 && gd.columns != 0 {
@ -38,7 +38,7 @@ func newGridDiagram(root *d2graph.Object) *gridDiagram {
// . │ g h i │ │ c f i │ // . │ g h i │ │ c f i │
// . └───────┘ └───────┘ // . └───────┘ └───────┘
// if keyword rows is first, make it row-directed, if columns is first it is column-directed // 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 gd.rowDirected = true
} }

View file

@ -314,14 +314,14 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error {
attrs.Left.MapKey.SetScalar(mk.Value.ScalarBox()) attrs.Left.MapKey.SetScalar(mk.Value.ScalarBox())
return nil return nil
} }
case "rows": case "grid-rows":
if attrs.Rows != nil && attrs.Rows.MapKey != nil { if attrs.GridRows != nil && attrs.GridRows.MapKey != nil {
attrs.Rows.MapKey.SetScalar(mk.Value.ScalarBox()) attrs.GridRows.MapKey.SetScalar(mk.Value.ScalarBox())
return nil return nil
} }
case "columns": case "grid-columns":
if attrs.Columns != nil && attrs.Columns.MapKey != nil { if attrs.GridColumns != nil && attrs.GridColumns.MapKey != nil {
attrs.Columns.MapKey.SetScalar(mk.Value.ScalarBox()) attrs.GridColumns.MapKey.SetScalar(mk.Value.ScalarBox())
return nil return nil
} }
case "source-arrowhead", "target-arrowhead": case "source-arrowhead", "target-arrowhead":

View file

@ -1,4 +1,4 @@
rows: 5 grid-rows: 5
style.fill: black style.fill: black
flow1: "" { flow1: "" {

View file

@ -1,4 +1,4 @@
rows: 3 grid-rows: 3
Executive Services.width: 1000 Executive Services.width: 1000

View file

@ -1,5 +1,5 @@
rows 1: { rows 1: {
rows: 1 grid-rows: 1
a a
b b
c c
@ -10,7 +10,7 @@ rows 1: {
} }
columns 1: { columns 1: {
columns: 1 grid-columns: 1
a a
b b
c c
@ -21,7 +21,7 @@ columns 1: {
} }
rows 2: { rows 2: {
rows: 2 grid-rows: 2
a a
b b
c c
@ -32,7 +32,7 @@ rows 2: {
} }
columns 2: { columns 2: {
columns: 2 grid-columns: 2
a a
b b
c c
@ -43,8 +43,8 @@ columns 2: {
} }
rows 2 columns 2: { rows 2 columns 2: {
rows: 2 grid-rows: 2
columns: 2 grid-columns: 2
a a
b b
@ -56,8 +56,8 @@ rows 2 columns 2: {
} }
columns 2 rows 2: { columns 2 rows 2: {
columns: 2 grid-columns: 2
rows: 2 grid-rows: 2
a a
b b
@ -69,8 +69,8 @@ columns 2 rows 2: {
} }
rows 3 columns 3: { rows 3 columns 3: {
rows: 3 grid-rows: 3
columns: 3 grid-columns: 3
a a
b b
@ -82,8 +82,8 @@ rows 3 columns 3: {
} }
columns 3 rows 3: { columns 3 rows 3: {
columns: 3 grid-columns: 3
rows: 3 grid-rows: 3
a a
b b
@ -95,7 +95,7 @@ columns 3 rows 3: {
} }
rows 3: { rows 3: {
rows: 3 grid-rows: 3
a a
b b
@ -107,7 +107,7 @@ rows 3: {
} }
columns 3: { columns 3: {
columns: 3 grid-columns: 3
a a
b b
@ -119,8 +119,8 @@ columns 3: {
} }
widths heights: { widths heights: {
rows: 3 grid-rows: 3
columns: 3 grid-columns: 3
a w200.width: 200 a w200.width: 200
b h300.height: 300 b h300.height: 300

View file

@ -9,7 +9,7 @@ teleport -> identity provider
teleport <- identity provider teleport <- identity provider
users: "" { users: "" {
columns: 1 grid-columns: 1
Engineers: { Engineers: {
shape: circle shape: circle
@ -22,7 +22,7 @@ users: "" {
} }
via: "" { via: "" {
columns: 1 grid-columns: 1
https: "HTTPS://" https: "HTTPS://"
kubectl: "> kubectl" kubectl: "> kubectl"
@ -32,7 +32,7 @@ via: "" {
} }
teleport: Teleport { teleport: Teleport {
rows: 2 grid-rows: 2
inp: |md inp: |md
# Identity Native Proxy # Identity Native Proxy
@ -45,7 +45,7 @@ teleport: Teleport {
} }
jita: "Just-in-time Access via" { jita: "Just-in-time Access via" {
rows: 1 grid-rows: 1
Slack.icon: https://icons.terrastruct.com/dev%2Fslack.svg Slack.icon: https://icons.terrastruct.com/dev%2Fslack.svg
Mattermost Mattermost
@ -55,7 +55,7 @@ jita: "Just-in-time Access via" {
} }
infra: Infrastructure { infra: Infrastructure {
rows: 2 grid-rows: 2
ssh.icon: https://icons.terrastruct.com/essentials%2F112-server.svg ssh.icon: https://icons.terrastruct.com/essentials%2F112-server.svg
Kubernetes.icon: https://icons.terrastruct.com/azure%2F_Companies%2FKubernetes.svg Kubernetes.icon: https://icons.terrastruct.com/azure%2F_Companies%2FKubernetes.svg

View file

@ -3,11 +3,11 @@
"name": "", "name": "",
"isFolderOnly": false, "isFolderOnly": false,
"ast": { "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": [ "nodes": [
{ {
"map_key": { "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": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/grid.d2,0:0:0-0:3:3", "range": "d2/testdata/d2compiler/TestCompile/grid.d2,0:0:0-0:3:3",
"path": [ "path": [
@ -27,21 +27,21 @@
"primary": {}, "primary": {},
"value": { "value": {
"map": { "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": [ "nodes": [
{ {
"map_key": { "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": { "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": [ "path": [
{ {
"unquoted_string": { "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": [ "value": [
{ {
"string": "rows", "string": "grid-rows",
"raw_string": "rows" "raw_string": "grid-rows"
} }
] ]
} }
@ -51,7 +51,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"number": { "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", "raw": "200",
"value": "200" "value": "200"
} }
@ -60,17 +60,17 @@
}, },
{ {
"map_key": { "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": { "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": [ "path": [
{ {
"unquoted_string": { "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": [ "value": [
{ {
"string": "columns", "string": "grid-columns",
"raw_string": "columns" "raw_string": "grid-columns"
} }
] ]
} }
@ -80,7 +80,7 @@
"primary": {}, "primary": {},
"value": { "value": {
"number": { "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", "raw": "230",
"value": "230" "value": "230"
} }
@ -165,10 +165,10 @@
"constraint": { "constraint": {
"value": "" "value": ""
}, },
"rows": { "gridRows": {
"value": "200" "value": "200"
}, },
"columns": { "gridColumns": {
"value": "230" "value": "230"
} }
}, },

View file

@ -4,15 +4,15 @@
"ioerr": null, "ioerr": null,
"errs": [ "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" "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" "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" "errmsg": "d2/testdata/d2compiler/TestCompile/grid_edge.d2:6:2: edges in grid diagrams are not supported yet"
} }
] ]

View file

@ -4,8 +4,8 @@
"ioerr": null, "ioerr": null,
"errs": [ "errs": [
{ {
"range": "d2/testdata/d2compiler/TestCompile/grid_negative.d2,2:10:28-2:14:32", "range": "d2/testdata/d2compiler/TestCompile/grid_negative.d2,2:15:38-2:19:42",
"errmsg": "d2/testdata/d2compiler/TestCompile/grid_negative.d2:3:11: columns must be a positive integer: \"-200\"" "errmsg": "d2/testdata/d2compiler/TestCompile/grid_negative.d2:3:16: grid-columns must be a positive integer: \"-200\""
} }
] ]
} }

View file

@ -4,12 +4,12 @@
"ioerr": null, "ioerr": null,
"errs": [ "errs": [
{ {
"range": "d2/testdata/d2compiler/TestCompile/grid_nested.d2,1:1:8-1:10:17", "range": "d2/testdata/d2compiler/TestCompile/grid_nested.d2,1:1:8-1:15:22",
"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\")" "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", "range": "d2/testdata/d2compiler/TestCompile/grid_nested.d2,2:1:24-2:18:41",
"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\")" "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\")"
} }
] ]
} }