diff --git a/d2exporter/export.go b/d2exporter/export.go
index 56f4b9146..99e8db2d0 100644
--- a/d2exporter/export.go
+++ b/d2exporter/export.go
@@ -194,8 +194,11 @@ func applyStyles(shape *d2target.Shape, obj *d2graph.Object) {
if obj.Style.DoubleBorder != nil {
shape.DoubleBorder, _ = strconv.ParseBool(obj.Style.DoubleBorder.Value)
}
+ if obj.IconStyle != (d2graph.Style{}) {
+ shape.IconStyle = &d2target.ShapeIconStyle{}
+ }
if obj.IconStyle.BorderRadius != nil {
- shape.IconBorderRadius, _ = strconv.Atoi(obj.IconStyle.BorderRadius.Value)
+ shape.IconStyle.BorderRadius, _ = strconv.Atoi(obj.IconStyle.BorderRadius.Value)
}
}
diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go
index 2c3cd30ea..88cac3083 100644
--- a/d2renderers/d2svg/d2svg.go
+++ b/d2renderers/d2svg/d2svg.go
@@ -1447,7 +1447,7 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
el.Fill = fill
el.Stroke = stroke
el.Style = style
- if targetShape.IconBorderRadius != 0 {
+ if targetShape.IconStyle != nil && targetShape.IconStyle.BorderRadius != 0 {
fmt.Fprint(writer, clipPathForIconBorderRadius(diagramHash, targetShape))
el.ClipPath = fmt.Sprintf("%v-%v-icon", diagramHash, targetShape.ID)
}
@@ -1643,14 +1643,14 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
tl := iconPosition.GetPointOnBox(box, label.PADDING, float64(iconSize), float64(iconSize))
- if targetShape.IconBorderRadius != 0 {
+ if targetShape.IconStyle != nil && targetShape.IconStyle.BorderRadius != 0 {
fmt.Fprintf(writer, ``,
html.EscapeString(targetShape.Icon.String()),
tl.X,
tl.Y,
iconSize,
iconSize,
- targetShape.IconBorderRadius,
+ targetShape.IconStyle.BorderRadius,
)
} else {
fmt.Fprintf(writer, ``,
diff --git a/d2renderers/d2svg/table.go b/d2renderers/d2svg/table.go
index 1fb2f15b4..2499836fc 100644
--- a/d2renderers/d2svg/table.go
+++ b/d2renderers/d2svg/table.go
@@ -50,20 +50,15 @@ func clipPathForIconBorderRadius(diagramHash string, shape d2target.Shape) strin
topX, topY := box.TopLeft.X+box.Width, box.TopLeft.Y
out := fmt.Sprintf(``, diagramHash, shape.ID)
- out += fmt.Sprintf(` `
}
diff --git a/d2target/d2target.go b/d2target/d2target.go
index 4880c2859..81518a966 100644
--- a/d2target/d2target.go
+++ b/d2target/d2target.go
@@ -503,12 +503,12 @@ type Shape struct {
Multiple bool `json:"multiple"`
DoubleBorder bool `json:"double-border"`
- Tooltip string `json:"tooltip"`
- Link string `json:"link"`
- PrettyLink string `json:"prettyLink,omitempty"`
- Icon *url.URL `json:"icon"`
- IconBorderRadius int `json:"iconBorderRadius,omitempty"`
- IconPosition string `json:"iconPosition"`
+ Tooltip string `json:"tooltip"`
+ Link string `json:"link"`
+ PrettyLink string `json:"prettyLink,omitempty"`
+ Icon *url.URL `json:"icon"`
+ IconStyle *ShapeIconStyle `json:"iconStyle,omitempty"`
+ IconPosition string `json:"iconPosition"`
// Whether the shape should allow shapes behind it to bleed through
// Currently just used for sequence diagram groups
@@ -532,6 +532,10 @@ type Shape struct {
NeutralAccentColor string `json:"neutralAccentColor,omitempty"`
}
+type ShapeIconStyle struct {
+ BorderRadius int `json:"borderRadius"`
+}
+
func (s Shape) GetFontColor() string {
if s.Type == ShapeClass || s.Type == ShapeSQLTable {
if !color.IsThemeColor(s.Color) {