hold icon properties in a struct in renderer
This commit is contained in:
parent
8c93ff8d26
commit
1f4aca9379
4 changed files with 25 additions and 23 deletions
|
|
@ -194,8 +194,11 @@ func applyStyles(shape *d2target.Shape, obj *d2graph.Object) {
|
||||||
if obj.Style.DoubleBorder != nil {
|
if obj.Style.DoubleBorder != nil {
|
||||||
shape.DoubleBorder, _ = strconv.ParseBool(obj.Style.DoubleBorder.Value)
|
shape.DoubleBorder, _ = strconv.ParseBool(obj.Style.DoubleBorder.Value)
|
||||||
}
|
}
|
||||||
|
if obj.IconStyle != (d2graph.Style{}) {
|
||||||
|
shape.IconStyle = &d2target.ShapeIconStyle{}
|
||||||
|
}
|
||||||
if obj.IconStyle.BorderRadius != nil {
|
if obj.IconStyle.BorderRadius != nil {
|
||||||
shape.IconBorderRadius, _ = strconv.Atoi(obj.IconStyle.BorderRadius.Value)
|
shape.IconStyle.BorderRadius, _ = strconv.Atoi(obj.IconStyle.BorderRadius.Value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1447,7 +1447,7 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
|
||||||
el.Fill = fill
|
el.Fill = fill
|
||||||
el.Stroke = stroke
|
el.Stroke = stroke
|
||||||
el.Style = style
|
el.Style = style
|
||||||
if targetShape.IconBorderRadius != 0 {
|
if targetShape.IconStyle != nil && targetShape.IconStyle.BorderRadius != 0 {
|
||||||
fmt.Fprint(writer, clipPathForIconBorderRadius(diagramHash, targetShape))
|
fmt.Fprint(writer, clipPathForIconBorderRadius(diagramHash, targetShape))
|
||||||
el.ClipPath = fmt.Sprintf("%v-%v-icon", diagramHash, targetShape.ID)
|
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))
|
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, `<image href="%s" x="%f" y="%f" width="%d" height="%d" clip-path="inset(0 round %dpx)" />`,
|
fmt.Fprintf(writer, `<image href="%s" x="%f" y="%f" width="%d" height="%d" clip-path="inset(0 round %dpx)" />`,
|
||||||
html.EscapeString(targetShape.Icon.String()),
|
html.EscapeString(targetShape.Icon.String()),
|
||||||
tl.X,
|
tl.X,
|
||||||
tl.Y,
|
tl.Y,
|
||||||
iconSize,
|
iconSize,
|
||||||
iconSize,
|
iconSize,
|
||||||
targetShape.IconBorderRadius,
|
targetShape.IconStyle.BorderRadius,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(writer, `<image href="%s" x="%f" y="%f" width="%d" height="%d" />`,
|
fmt.Fprintf(writer, `<image href="%s" x="%f" y="%f" width="%d" height="%d" />`,
|
||||||
|
|
|
||||||
|
|
@ -50,20 +50,15 @@ func clipPathForIconBorderRadius(diagramHash string, shape d2target.Shape) strin
|
||||||
topX, topY := box.TopLeft.X+box.Width, box.TopLeft.Y
|
topX, topY := box.TopLeft.X+box.Width, box.TopLeft.Y
|
||||||
|
|
||||||
out := fmt.Sprintf(`<clipPath id="%v-%v-icon">`, diagramHash, shape.ID)
|
out := fmt.Sprintf(`<clipPath id="%v-%v-icon">`, diagramHash, shape.ID)
|
||||||
out += fmt.Sprintf(`<path d="M %f %f L %f %f S %f %f %f %f `, box.TopLeft.X, box.TopLeft.Y+float64(shape.IconBorderRadius), box.TopLeft.X, box.TopLeft.Y+float64(shape.IconBorderRadius), box.TopLeft.X, box.TopLeft.Y, box.TopLeft.X+float64(shape.IconBorderRadius), box.TopLeft.Y)
|
out += fmt.Sprintf(`<path d="M %f %f L %f %f S %f %f %f %f `, box.TopLeft.X, box.TopLeft.Y+float64(shape.IconStyle.BorderRadius), box.TopLeft.X, box.TopLeft.Y+float64(shape.IconStyle.BorderRadius), box.TopLeft.X, box.TopLeft.Y, box.TopLeft.X+float64(shape.IconStyle.BorderRadius), box.TopLeft.Y)
|
||||||
out += fmt.Sprintf(`L %f %f L %f %f `, box.TopLeft.X+box.Width-float64(shape.IconBorderRadius), box.TopLeft.Y, topX-float64(shape.IconBorderRadius), topY)
|
out += fmt.Sprintf(`L %f %f L %f %f `, box.TopLeft.X+box.Width-float64(shape.IconStyle.BorderRadius), box.TopLeft.Y, topX-float64(shape.IconStyle.BorderRadius), topY)
|
||||||
|
|
||||||
out += fmt.Sprintf(`S %f %f %f %f `, topX, topY, topX, topY+float64(shape.IconBorderRadius))
|
out += fmt.Sprintf(`S %f %f %f %f `, topX, topY, topX, topY+float64(shape.IconStyle.BorderRadius))
|
||||||
out += fmt.Sprintf(`L %f %f `, topX, topY+box.Height-float64(shape.IconBorderRadius))
|
out += fmt.Sprintf(`L %f %f `, topX, topY+box.Height-float64(shape.IconStyle.BorderRadius))
|
||||||
|
out += fmt.Sprintf(`S %f % f %f %f `, topX, topY+box.Height, topX-float64(shape.IconStyle.BorderRadius), topY+box.Height)
|
||||||
if len(shape.Columns) != 0 {
|
out += fmt.Sprintf(`L %f %f `, box.TopLeft.X+float64(shape.IconStyle.BorderRadius), box.TopLeft.Y+box.Height)
|
||||||
out += fmt.Sprintf(`L %f %f L %f %f`, topX, topY+box.Height, box.TopLeft.X, box.TopLeft.Y+box.Height)
|
out += fmt.Sprintf(`S %f %f %f %f`, box.TopLeft.X, box.TopLeft.Y+box.Height, box.TopLeft.X, box.TopLeft.Y+box.Height-float64(shape.IconStyle.BorderRadius))
|
||||||
} else {
|
out += fmt.Sprintf(`L %f %f`, box.TopLeft.X, box.TopLeft.Y+float64(shape.IconStyle.BorderRadius))
|
||||||
out += fmt.Sprintf(`S %f % f %f %f `, topX, topY+box.Height, topX-float64(shape.IconBorderRadius), topY+box.Height)
|
|
||||||
out += fmt.Sprintf(`L %f %f `, box.TopLeft.X+float64(shape.IconBorderRadius), box.TopLeft.Y+box.Height)
|
|
||||||
out += fmt.Sprintf(`S %f %f %f %f`, box.TopLeft.X, box.TopLeft.Y+box.Height, box.TopLeft.X, box.TopLeft.Y+box.Height-float64(shape.IconBorderRadius))
|
|
||||||
out += fmt.Sprintf(`L %f %f`, box.TopLeft.X, box.TopLeft.Y+float64(shape.IconBorderRadius))
|
|
||||||
}
|
|
||||||
out += fmt.Sprintf(`Z %f %f" `, box.TopLeft.X, box.TopLeft.Y)
|
out += fmt.Sprintf(`Z %f %f" `, box.TopLeft.X, box.TopLeft.Y)
|
||||||
return out + `fill="none" /> </clipPath>`
|
return out + `fill="none" /> </clipPath>`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -503,12 +503,12 @@ type Shape struct {
|
||||||
Multiple bool `json:"multiple"`
|
Multiple bool `json:"multiple"`
|
||||||
DoubleBorder bool `json:"double-border"`
|
DoubleBorder bool `json:"double-border"`
|
||||||
|
|
||||||
Tooltip string `json:"tooltip"`
|
Tooltip string `json:"tooltip"`
|
||||||
Link string `json:"link"`
|
Link string `json:"link"`
|
||||||
PrettyLink string `json:"prettyLink,omitempty"`
|
PrettyLink string `json:"prettyLink,omitempty"`
|
||||||
Icon *url.URL `json:"icon"`
|
Icon *url.URL `json:"icon"`
|
||||||
IconBorderRadius int `json:"iconBorderRadius,omitempty"`
|
IconStyle *ShapeIconStyle `json:"iconStyle,omitempty"`
|
||||||
IconPosition string `json:"iconPosition"`
|
IconPosition string `json:"iconPosition"`
|
||||||
|
|
||||||
// Whether the shape should allow shapes behind it to bleed through
|
// Whether the shape should allow shapes behind it to bleed through
|
||||||
// Currently just used for sequence diagram groups
|
// Currently just used for sequence diagram groups
|
||||||
|
|
@ -532,6 +532,10 @@ type Shape struct {
|
||||||
NeutralAccentColor string `json:"neutralAccentColor,omitempty"`
|
NeutralAccentColor string `json:"neutralAccentColor,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ShapeIconStyle struct {
|
||||||
|
BorderRadius int `json:"borderRadius"`
|
||||||
|
}
|
||||||
|
|
||||||
func (s Shape) GetFontColor() string {
|
func (s Shape) GetFontColor() string {
|
||||||
if s.Type == ShapeClass || s.Type == ShapeSQLTable {
|
if s.Type == ShapeClass || s.Type == ShapeSQLTable {
|
||||||
if !color.IsThemeColor(s.Color) {
|
if !color.IsThemeColor(s.Color) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue