add grid-gap keywords
This commit is contained in:
parent
a4cf396347
commit
c20c122ee4
3 changed files with 80 additions and 20 deletions
|
|
@ -420,6 +420,45 @@ func (c *compiler) compileReserved(attrs *d2graph.Attributes, f *d2ir.Field) {
|
||||||
attrs.GridColumns = &d2graph.Scalar{}
|
attrs.GridColumns = &d2graph.Scalar{}
|
||||||
attrs.GridColumns.Value = scalar.ScalarString()
|
attrs.GridColumns.Value = scalar.ScalarString()
|
||||||
attrs.GridColumns.MapKey = f.LastPrimaryKey()
|
attrs.GridColumns.MapKey = f.LastPrimaryKey()
|
||||||
|
case "grid-gap":
|
||||||
|
v, err := strconv.Atoi(scalar.ScalarString())
|
||||||
|
if err != nil {
|
||||||
|
c.errorf(scalar, "non-integer grid-gap %#v: %s", scalar.ScalarString(), err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if v < 0 {
|
||||||
|
c.errorf(scalar, "grid-gap must be a non-negative integer: %#v", scalar.ScalarString())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
attrs.GridGap = &d2graph.Scalar{}
|
||||||
|
attrs.GridGap.Value = scalar.ScalarString()
|
||||||
|
attrs.GridGap.MapKey = f.LastPrimaryKey()
|
||||||
|
case "grid-gap-rows":
|
||||||
|
v, err := strconv.Atoi(scalar.ScalarString())
|
||||||
|
if err != nil {
|
||||||
|
c.errorf(scalar, "non-integer grid-gap-rows %#v: %s", scalar.ScalarString(), err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if v < 0 {
|
||||||
|
c.errorf(scalar, "grid-gap-rows must be a non-negative integer: %#v", scalar.ScalarString())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
attrs.GridGapRows = &d2graph.Scalar{}
|
||||||
|
attrs.GridGapRows.Value = scalar.ScalarString()
|
||||||
|
attrs.GridGapRows.MapKey = f.LastPrimaryKey()
|
||||||
|
case "grid-gap-columns":
|
||||||
|
v, err := strconv.Atoi(scalar.ScalarString())
|
||||||
|
if err != nil {
|
||||||
|
c.errorf(scalar, "non-integer grid-gap-columns %#v: %s", scalar.ScalarString(), err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if v < 0 {
|
||||||
|
c.errorf(scalar, "grid-gap-columns must be a non-negative integer: %#v", scalar.ScalarString())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
attrs.GridGapColumns = &d2graph.Scalar{}
|
||||||
|
attrs.GridGapColumns.Value = scalar.ScalarString()
|
||||||
|
attrs.GridGapColumns.MapKey = f.LastPrimaryKey()
|
||||||
case "class":
|
case "class":
|
||||||
attrs.Classes = append(attrs.Classes, scalar.ScalarString())
|
attrs.Classes = append(attrs.Classes, scalar.ScalarString())
|
||||||
case "classes":
|
case "classes":
|
||||||
|
|
@ -757,7 +796,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 "grid-rows", "grid-columns":
|
case "grid-rows", "grid-columns", "grid-gap", "grid-gap-rows", "grid-gap-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(),
|
||||||
|
|
|
||||||
|
|
@ -136,8 +136,11 @@ type Attributes struct {
|
||||||
Direction Scalar `json:"direction"`
|
Direction Scalar `json:"direction"`
|
||||||
Constraint Scalar `json:"constraint"`
|
Constraint Scalar `json:"constraint"`
|
||||||
|
|
||||||
GridRows *Scalar `json:"gridRows,omitempty"`
|
GridRows *Scalar `json:"gridRows,omitempty"`
|
||||||
GridColumns *Scalar `json:"gridColumns,omitempty"`
|
GridColumns *Scalar `json:"gridColumns,omitempty"`
|
||||||
|
GridGap *Scalar `json:"gridGap,omitempty"`
|
||||||
|
GridGapRows *Scalar `json:"gridGapRows,omitempty"`
|
||||||
|
GridGapColumns *Scalar `json:"gridGapColumns,omitempty"`
|
||||||
|
|
||||||
// These names are attached to the rendered elements in SVG
|
// These names are attached to the rendered elements in SVG
|
||||||
// so that users can target them however they like outside of D2
|
// so that users can target them however they like outside of D2
|
||||||
|
|
@ -1588,23 +1591,26 @@ var ReservedKeywords2 map[string]struct{}
|
||||||
|
|
||||||
// Non Style/Holder keywords.
|
// Non Style/Holder keywords.
|
||||||
var SimpleReservedKeywords = map[string]struct{}{
|
var SimpleReservedKeywords = map[string]struct{}{
|
||||||
"label": {},
|
"label": {},
|
||||||
"desc": {},
|
"desc": {},
|
||||||
"shape": {},
|
"shape": {},
|
||||||
"icon": {},
|
"icon": {},
|
||||||
"constraint": {},
|
"constraint": {},
|
||||||
"tooltip": {},
|
"tooltip": {},
|
||||||
"link": {},
|
"link": {},
|
||||||
"near": {},
|
"near": {},
|
||||||
"width": {},
|
"width": {},
|
||||||
"height": {},
|
"height": {},
|
||||||
"direction": {},
|
"direction": {},
|
||||||
"top": {},
|
"top": {},
|
||||||
"left": {},
|
"left": {},
|
||||||
"grid-rows": {},
|
"grid-rows": {},
|
||||||
"grid-columns": {},
|
"grid-columns": {},
|
||||||
"class": {},
|
"grid-gap": {},
|
||||||
"classes": {},
|
"grid-gap-rows": {},
|
||||||
|
"grid-gap-columns": {},
|
||||||
|
"class": {},
|
||||||
|
"classes": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
|
|
||||||
|
|
@ -324,6 +324,21 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error {
|
||||||
attrs.GridColumns.MapKey.SetScalar(mk.Value.ScalarBox())
|
attrs.GridColumns.MapKey.SetScalar(mk.Value.ScalarBox())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
case "grid-gap":
|
||||||
|
if attrs.GridGap != nil && attrs.GridGap.MapKey != nil {
|
||||||
|
attrs.GridGap.MapKey.SetScalar(mk.Value.ScalarBox())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
case "grid-gap-rows":
|
||||||
|
if attrs.GridGapRows != nil && attrs.GridGapRows.MapKey != nil {
|
||||||
|
attrs.GridGapRows.MapKey.SetScalar(mk.Value.ScalarBox())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
case "grid-gap-columns":
|
||||||
|
if attrs.GridGapColumns != nil && attrs.GridGapColumns.MapKey != nil {
|
||||||
|
attrs.GridGapColumns.MapKey.SetScalar(mk.Value.ScalarBox())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
case "source-arrowhead", "target-arrowhead":
|
case "source-arrowhead", "target-arrowhead":
|
||||||
if reservedKey == "source-arrowhead" {
|
if reservedKey == "source-arrowhead" {
|
||||||
attrs = edge.SrcArrowhead
|
attrs = edge.SrcArrowhead
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue