add icon-border-radius to connections
This commit is contained in:
parent
a2ce0c293e
commit
532d913309
4 changed files with 50 additions and 11 deletions
|
|
@ -938,6 +938,17 @@ func (c *compiler) compileEdgeField(edge *d2graph.Edge, f *d2ir.Field) {
|
|||
_, isReserved := d2ast.SimpleReservedKeywords[keyword]
|
||||
if isReserved {
|
||||
c.compileReserved(&edge.Attributes, f)
|
||||
if keyword == "icon" && f.Map() != nil {
|
||||
for _, ff := range f.Map().Fields {
|
||||
if ff.Name.ScalarString() == "style" && ff.Name.IsUnquoted() {
|
||||
if f.Map() == nil || len(f.Map().Fields) == 0 {
|
||||
c.errorf(f.LastRef().AST(), `"style" expected to be set to a map of key-values, or contain an additional keyword like "style.opacity: 0.4"`)
|
||||
return
|
||||
}
|
||||
c.compileIconStyle(&edge.Attributes, ff.Map())
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
} else if f.Name.ScalarString() == "style" {
|
||||
if f.Map() == nil {
|
||||
|
|
@ -977,6 +988,17 @@ func (c *compiler) compileArrowheads(edge *d2graph.Edge, f *d2ir.Field) {
|
|||
isReserved = isReserved && f2.Name.IsUnquoted()
|
||||
if isReserved {
|
||||
c.compileReserved(attrs, f2)
|
||||
if keyword == "icon" && f.Map() != nil {
|
||||
for _, ff := range f.Map().Fields {
|
||||
if ff.Name.ScalarString() == "style" && ff.Name.IsUnquoted() {
|
||||
if f.Map() == nil || len(f.Map().Fields) == 0 {
|
||||
c.errorf(f.LastRef().AST(), `"style" expected to be set to a map of key-values, or contain an additional keyword like "style.opacity: 0.4"`)
|
||||
return
|
||||
}
|
||||
c.compileIconStyle(attrs, ff.Map())
|
||||
}
|
||||
}
|
||||
}
|
||||
continue
|
||||
} else if f2.Name.ScalarString() == "style" && f2.Name.IsUnquoted() {
|
||||
if f2.Map() == nil {
|
||||
|
|
|
|||
|
|
@ -416,6 +416,10 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection
|
|||
}
|
||||
}
|
||||
|
||||
if edge.IconStyle.BorderRadius != nil {
|
||||
connection.IconBorderRadius, _ = strconv.ParseFloat(edge.IconStyle.BorderRadius.Value, 64)
|
||||
}
|
||||
|
||||
if edge.Style.Italic != nil {
|
||||
connection.Italic, _ = strconv.ParseBool(edge.Style.Italic.Value)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -590,13 +590,25 @@ func drawConnection(writer io.Writer, diagramHash string, connection d2target.Co
|
|||
if connection.Icon != nil {
|
||||
iconPos := connection.GetIconPosition()
|
||||
if iconPos != nil {
|
||||
fmt.Fprintf(writer, `<image href="%s" x="%f" y="%f" width="%d" height="%d" />`,
|
||||
html.EscapeString(connection.Icon.String()),
|
||||
iconPos.X,
|
||||
iconPos.Y,
|
||||
d2target.DEFAULT_ICON_SIZE,
|
||||
d2target.DEFAULT_ICON_SIZE,
|
||||
)
|
||||
if connection.IconBorderRadius != 0 {
|
||||
fmt.Fprintf(writer, `<image href="%s" x="%f" y="%f" width="%d" height="%d" clip-path="inset(0 round %fpx)" />`,
|
||||
html.EscapeString(connection.Icon.String()),
|
||||
iconPos.X,
|
||||
iconPos.Y,
|
||||
d2target.DEFAULT_ICON_SIZE,
|
||||
d2target.DEFAULT_ICON_SIZE,
|
||||
connection.IconBorderRadius,
|
||||
)
|
||||
} else {
|
||||
|
||||
fmt.Fprintf(writer, `<image href="%s" x="%f" y="%f" width="%d" height="%d" />`,
|
||||
html.EscapeString(connection.Icon.String()),
|
||||
iconPos.X,
|
||||
iconPos.Y,
|
||||
d2target.DEFAULT_ICON_SIZE,
|
||||
d2target.DEFAULT_ICON_SIZE,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -625,10 +625,11 @@ type Connection struct {
|
|||
Route []*geo.Point `json:"route"`
|
||||
IsCurve bool `json:"isCurve,omitempty"`
|
||||
|
||||
Animated bool `json:"animated"`
|
||||
Tooltip string `json:"tooltip"`
|
||||
Icon *url.URL `json:"icon"`
|
||||
IconPosition string `json:"iconPosition,omitempty"`
|
||||
Animated bool `json:"animated"`
|
||||
Tooltip string `json:"tooltip"`
|
||||
Icon *url.URL `json:"icon"`
|
||||
IconPosition string `json:"iconPosition,omitempty"`
|
||||
IconBorderRadius float64 `json:"iconBorderRadius,omitempty"`
|
||||
|
||||
ZIndex int `json:"zIndex"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue