render unfilled triangle arrowhead

This commit is contained in:
Gavin Nishizawa 2023-11-07 17:46:26 -08:00
parent 9d9afcdfe3
commit 61f8e67454
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
4 changed files with 19 additions and 13 deletions

View file

@ -202,7 +202,7 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection
if edge.SrcArrow { if edge.SrcArrow {
connection.SrcArrow = d2target.DefaultArrowhead connection.SrcArrow = d2target.DefaultArrowhead
if edge.SrcArrowhead != nil && edge.SrcArrowhead.Shape.Value != "" { if edge.SrcArrowhead != nil {
connection.SrcArrow = edge.SrcArrowhead.ToArrowhead() connection.SrcArrow = edge.SrcArrowhead.ToArrowhead()
} }
} }
@ -220,7 +220,7 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection
} }
if edge.DstArrow { if edge.DstArrow {
connection.DstArrow = d2target.DefaultArrowhead connection.DstArrow = d2target.DefaultArrowhead
if edge.DstArrowhead != nil && edge.DstArrowhead.Shape.Value != "" { if edge.DstArrowhead != nil {
connection.DstArrow = edge.DstArrowhead.ToArrowhead() connection.DstArrow = edge.DstArrowhead.ToArrowhead()
} }
} }

View file

@ -177,10 +177,6 @@ func (a *Attributes) ApplyTextTransform() {
} }
func (a *Attributes) ToArrowhead() d2target.Arrowhead { func (a *Attributes) ToArrowhead() d2target.Arrowhead {
if a.Shape.Value == "" {
return d2target.NoArrowhead
}
var filled *bool var filled *bool
if a.Style.Filled != nil { if a.Style.Filled != nil {
v, _ := strconv.ParseBool(a.Style.Filled.Value) v, _ := strconv.ParseBool(a.Style.Filled.Value)

View file

@ -145,17 +145,18 @@ func arrowheadMarker(isTarget bool, id string, connection d2target.Connection) s
polygonEl.ClassName = "connection" polygonEl.ClassName = "connection"
polygonEl.Attributes = fmt.Sprintf(`stroke-width="%d"`, connection.StrokeWidth) polygonEl.Attributes = fmt.Sprintf(`stroke-width="%d"`, connection.StrokeWidth)
inset := strokeWidth / 2
if isTarget { if isTarget {
polygonEl.Points = fmt.Sprintf("%f,%f %f,%f %f,%f", polygonEl.Points = fmt.Sprintf("%f,%f %f,%f %f,%f",
0., 0., inset, inset,
width, height/2.0, width-inset, height/2.0,
0., height, inset, height-inset,
) )
} else { } else {
polygonEl.Points = fmt.Sprintf("%f,%f %f,%f %f,%f", polygonEl.Points = fmt.Sprintf("%f,%f %f,%f %f,%f",
width, 0., width-inset, inset,
0., height/2.0, inset, height/2.0,
width, height, width-inset, height-inset,
) )
} }
path = polygonEl.Render() path = polygonEl.Render()

View file

@ -784,6 +784,10 @@ func ToArrowhead(arrowheadType string, filled *bool) Arrowhead {
case string(CfManyRequired): case string(CfManyRequired):
return CfManyRequired return CfManyRequired
default: default:
if DefaultArrowhead == TriangleArrowhead &&
filled != nil && !(*filled) {
return UnfilledTriangleArrowhead
}
return DefaultArrowhead return DefaultArrowhead
} }
} }
@ -797,11 +801,16 @@ func (arrowhead Arrowhead) Dimensions(strokeWidth float64) (width, height float6
baseHeight = 4 baseHeight = 4
widthMultiplier = 4 widthMultiplier = 4
heightMultiplier = 4 heightMultiplier = 4
case TriangleArrowhead, UnfilledTriangleArrowhead: case TriangleArrowhead:
baseWidth = 4 baseWidth = 4
baseHeight = 4 baseHeight = 4
widthMultiplier = 3 widthMultiplier = 3
heightMultiplier = 4 heightMultiplier = 4
case UnfilledTriangleArrowhead:
baseWidth = 7
baseHeight = 7
widthMultiplier = 3
heightMultiplier = 4
case LineArrowhead: case LineArrowhead:
widthMultiplier = 5 widthMultiplier = 5
heightMultiplier = 8 heightMultiplier = 8