diff --git a/d2exporter/export.go b/d2exporter/export.go index f79e98af6..bf923c653 100644 --- a/d2exporter/export.go +++ b/d2exporter/export.go @@ -202,7 +202,7 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection if edge.SrcArrow { connection.SrcArrow = d2target.DefaultArrowhead - if edge.SrcArrowhead != nil && edge.SrcArrowhead.Shape.Value != "" { + if edge.SrcArrowhead != nil { connection.SrcArrow = edge.SrcArrowhead.ToArrowhead() } } @@ -220,7 +220,7 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection } if edge.DstArrow { connection.DstArrow = d2target.DefaultArrowhead - if edge.DstArrowhead != nil && edge.DstArrowhead.Shape.Value != "" { + if edge.DstArrowhead != nil { connection.DstArrow = edge.DstArrowhead.ToArrowhead() } } diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 0e3db323c..1dc0942e0 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -177,10 +177,6 @@ func (a *Attributes) ApplyTextTransform() { } func (a *Attributes) ToArrowhead() d2target.Arrowhead { - if a.Shape.Value == "" { - return d2target.NoArrowhead - } - var filled *bool if a.Style.Filled != nil { v, _ := strconv.ParseBool(a.Style.Filled.Value) diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index 69b439bac..67db074c9 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -145,17 +145,18 @@ func arrowheadMarker(isTarget bool, id string, connection d2target.Connection) s polygonEl.ClassName = "connection" polygonEl.Attributes = fmt.Sprintf(`stroke-width="%d"`, connection.StrokeWidth) + inset := strokeWidth / 2 if isTarget { polygonEl.Points = fmt.Sprintf("%f,%f %f,%f %f,%f", - 0., 0., - width, height/2.0, - 0., height, + inset, inset, + width-inset, height/2.0, + inset, height-inset, ) } else { polygonEl.Points = fmt.Sprintf("%f,%f %f,%f %f,%f", - width, 0., - 0., height/2.0, - width, height, + width-inset, inset, + inset, height/2.0, + width-inset, height-inset, ) } path = polygonEl.Render() diff --git a/d2target/d2target.go b/d2target/d2target.go index a20352bb7..3c468b81d 100644 --- a/d2target/d2target.go +++ b/d2target/d2target.go @@ -784,6 +784,10 @@ func ToArrowhead(arrowheadType string, filled *bool) Arrowhead { case string(CfManyRequired): return CfManyRequired default: + if DefaultArrowhead == TriangleArrowhead && + filled != nil && !(*filled) { + return UnfilledTriangleArrowhead + } return DefaultArrowhead } } @@ -797,11 +801,16 @@ func (arrowhead Arrowhead) Dimensions(strokeWidth float64) (width, height float6 baseHeight = 4 widthMultiplier = 4 heightMultiplier = 4 - case TriangleArrowhead, UnfilledTriangleArrowhead: + case TriangleArrowhead: baseWidth = 4 baseHeight = 4 widthMultiplier = 3 heightMultiplier = 4 + case UnfilledTriangleArrowhead: + baseWidth = 7 + baseHeight = 7 + widthMultiplier = 3 + heightMultiplier = 4 case LineArrowhead: widthMultiplier = 5 heightMultiplier = 8