a bit refactoring on icom style field init

This commit is contained in:
melsonic 2025-03-18 23:34:43 +05:30
parent eb4f36102a
commit a2ce0c293e
No known key found for this signature in database
GPG key ID: DFA426742F621CD7
7 changed files with 11 additions and 17 deletions

View file

@ -790,7 +790,7 @@ func (c *compiler) compileIconStyleField(attrs *d2graph.Attributes, f *d2ir.Fiel
if f.Primary() == nil { if f.Primary() == nil {
return return
} }
compileStyleFieldInit(attrs, f) compileIconStyleFieldInit(attrs, f)
scalar := f.Primary().Value scalar := f.Primary().Value
err := attrs.IconStyle.Apply(f.Name.ScalarString(), scalar.ScalarString()) err := attrs.IconStyle.Apply(f.Name.ScalarString(), scalar.ScalarString())
@ -815,12 +815,7 @@ func compileStyleFieldInit(attrs *d2graph.Attributes, f *d2ir.Field) {
case "stroke-dash": case "stroke-dash":
attrs.Style.StrokeDash = &d2graph.Scalar{MapKey: f.LastPrimaryKey()} attrs.Style.StrokeDash = &d2graph.Scalar{MapKey: f.LastPrimaryKey()}
case "border-radius": case "border-radius":
if attrs.Style.BorderRadius == nil { attrs.Style.BorderRadius = &d2graph.Scalar{MapKey: f.LastPrimaryKey()}
attrs.Style.BorderRadius = &d2graph.Scalar{MapKey: f.LastPrimaryKey()}
}
if attrs.IconStyle.BorderRadius == nil {
attrs.IconStyle.BorderRadius = &d2graph.Scalar{MapKey: f.LastPrimaryKey()}
}
case "shadow": case "shadow":
attrs.Style.Shadow = &d2graph.Scalar{MapKey: f.LastPrimaryKey()} attrs.Style.Shadow = &d2graph.Scalar{MapKey: f.LastPrimaryKey()}
case "3d": case "3d":
@ -858,6 +853,13 @@ func compileStyleFieldInit(attrs *d2graph.Attributes, f *d2ir.Field) {
} }
} }
func compileIconStyleFieldInit(attrs *d2graph.Attributes, f *d2ir.Field) {
switch f.Name.ScalarString() {
case "border-radius":
attrs.IconStyle.BorderRadius = &d2graph.Scalar{MapKey: f.LastPrimaryKey()}
}
}
func (c *compiler) compileEdge(obj *d2graph.Object, e *d2ir.Edge) { func (c *compiler) compileEdge(obj *d2graph.Object, e *d2ir.Edge) {
edge, err := obj.Connect(e.ID.SrcPath, e.ID.DstPath, e.ID.SrcArrow, e.ID.DstArrow, "") edge, err := obj.Connect(e.ID.SrcPath, e.ID.DstPath, e.ID.SrcArrow, e.ID.DstArrow, "")
if err != nil { if err != nil {

View file

@ -351,11 +351,7 @@
"value": "5" "value": "5"
} }
}, },
"iconStyle": { "iconStyle": {},
"borderRadius": {
"value": ""
}
},
"near_key": null, "near_key": null,
"shape": { "shape": {
"value": "rectangle" "value": "rectangle"

View file

@ -163,11 +163,7 @@
"value": "5" "value": "5"
} }
}, },
"iconStyle": { "iconStyle": {},
"borderRadius": {
"value": ""
}
},
"near_key": null, "near_key": null,
"shape": { "shape": {
"value": "rectangle" "value": "rectangle"