render connection label background according to style.fill

This commit is contained in:
Gavin Nishizawa 2022-12-16 15:44:26 -08:00
parent 65dc45c119
commit 412713e2b7
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
3 changed files with 10 additions and 0 deletions

View file

@ -200,6 +200,10 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection
connection.StrokeWidth, _ = strconv.Atoi(edge.Attributes.Style.StrokeWidth.Value) connection.StrokeWidth, _ = strconv.Atoi(edge.Attributes.Style.StrokeWidth.Value)
} }
if edge.Attributes.Style.Fill != nil {
connection.Fill = edge.Attributes.Style.Fill.Value
}
connection.FontSize = text.FontSize connection.FontSize = text.FontSize
if edge.Attributes.Style.FontSize != nil { if edge.Attributes.Style.FontSize != nil {
connection.FontSize, _ = strconv.Atoi(edge.Attributes.Style.FontSize.Value) connection.FontSize, _ = strconv.Atoi(edge.Attributes.Style.FontSize.Value)

View file

@ -432,6 +432,11 @@ func drawConnection(writer io.Writer, labelMaskID string, connection d2target.Co
if connection.Color != "" { if connection.Color != "" {
fontColor = connection.Color fontColor = connection.Color
} }
if connection.Fill != "" {
fmt.Fprintf(writer, `<rect x="%f" y="%f" width="%d" height="%d" style="fill:%s" />`,
labelTL.X, labelTL.Y, connection.LabelWidth, connection.LabelHeight, connection.Fill)
}
textStyle := fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "middle", connection.FontSize, fontColor) textStyle := fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "middle", connection.FontSize, fontColor)
x := labelTL.X + float64(connection.LabelWidth)/2 x := labelTL.X + float64(connection.LabelWidth)/2
y := labelTL.Y + float64(connection.FontSize) y := labelTL.Y + float64(connection.FontSize)

View file

@ -207,6 +207,7 @@ type Connection struct {
StrokeDash float64 `json:"strokeDash"` StrokeDash float64 `json:"strokeDash"`
StrokeWidth int `json:"strokeWidth"` StrokeWidth int `json:"strokeWidth"`
Stroke string `json:"stroke"` Stroke string `json:"stroke"`
Fill string `json:"fill,omitempty"`
Text Text
LabelPosition string `json:"labelPosition"` LabelPosition string `json:"labelPosition"`