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 {
return
}
compileStyleFieldInit(attrs, f)
compileIconStyleFieldInit(attrs, f)
scalar := f.Primary().Value
err := attrs.IconStyle.Apply(f.Name.ScalarString(), scalar.ScalarString())
@ -815,12 +815,7 @@ func compileStyleFieldInit(attrs *d2graph.Attributes, f *d2ir.Field) {
case "stroke-dash":
attrs.Style.StrokeDash = &d2graph.Scalar{MapKey: f.LastPrimaryKey()}
case "border-radius":
if attrs.Style.BorderRadius == nil {
attrs.Style.BorderRadius = &d2graph.Scalar{MapKey: f.LastPrimaryKey()}
}
if attrs.IconStyle.BorderRadius == nil {
attrs.IconStyle.BorderRadius = &d2graph.Scalar{MapKey: f.LastPrimaryKey()}
}
attrs.Style.BorderRadius = &d2graph.Scalar{MapKey: f.LastPrimaryKey()}
case "shadow":
attrs.Style.Shadow = &d2graph.Scalar{MapKey: f.LastPrimaryKey()}
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) {
edge, err := obj.Connect(e.ID.SrcPath, e.ID.DstPath, e.ID.SrcArrow, e.ID.DstArrow, "")
if err != nil {

View file

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

View file

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