diff --git a/d2exporter/export.go b/d2exporter/export.go index fe9be6c46..fc3557c37 100644 --- a/d2exporter/export.go +++ b/d2exporter/export.go @@ -200,15 +200,9 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection text := edge.Text() if edge.SrcArrow { - connection.SrcArrow = d2target.TriangleArrowhead - if edge.SrcArrowhead != nil { - if edge.SrcArrowhead.Shape.Value != "" { - filled := false - if edge.SrcArrowhead.Style.Filled != nil { - filled, _ = strconv.ParseBool(edge.SrcArrowhead.Style.Filled.Value) - } - connection.SrcArrow = d2target.ToArrowhead(edge.SrcArrowhead.Shape.Value, filled) - } + connection.SrcArrow = d2target.DefaultArrowhead + if edge.SrcArrowhead != nil && edge.SrcArrowhead.Shape.Value != "" { + connection.SrcArrow = edge.SrcArrowhead.ToArrowhead() } } if edge.SrcArrowhead != nil { @@ -221,15 +215,9 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection } } if edge.DstArrow { - connection.DstArrow = d2target.TriangleArrowhead - if edge.DstArrowhead != nil { - if edge.DstArrowhead.Shape.Value != "" { - filled := false - if edge.DstArrowhead.Style.Filled != nil { - filled, _ = strconv.ParseBool(edge.DstArrowhead.Style.Filled.Value) - } - connection.DstArrow = d2target.ToArrowhead(edge.DstArrowhead.Shape.Value, filled) - } + connection.DstArrow = d2target.DefaultArrowhead + if edge.DstArrowhead != nil && edge.DstArrowhead.Shape.Value != "" { + connection.DstArrow = edge.DstArrowhead.ToArrowhead() } } if edge.DstArrowhead != nil { diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index f80a35b21..1bab9c273 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -164,6 +164,18 @@ func (a *Attributes) ApplyTextTransform() { } } +func (a *Attributes) ToArrowhead() d2target.Arrowhead { + if a.Shape.Value == "" { + return d2target.NoArrowhead + } + + filled := false + if a.Style.Filled != nil { + filled, _ = strconv.ParseBool(a.Style.Filled.Value) + } + return d2target.ToArrowhead(a.Shape.Value, filled) +} + // TODO references at the root scope should have their Scope set to root graph AST type Reference struct { Key *d2ast.KeyPath `json:"key"` diff --git a/d2target/d2target.go b/d2target/d2target.go index cb173cb2e..3206d251f 100644 --- a/d2target/d2target.go +++ b/d2target/d2target.go @@ -635,6 +635,8 @@ const ( CfMany Arrowhead = "cf-many" CfOneRequired Arrowhead = "cf-one-required" CfManyRequired Arrowhead = "cf-many-required" + + DefaultArrowhead Arrowhead = TriangleArrowhead ) var Arrowheads = map[string]struct{}{ @@ -663,8 +665,12 @@ func ToArrowhead(arrowheadType string, filled bool) Arrowhead { return FilledCircleArrowhead } return CircleArrowhead + case string(NoArrowhead): + return NoArrowhead case string(ArrowArrowhead): return ArrowArrowhead + case string(TriangleArrowhead): + return TriangleArrowhead case string(CfOne): return CfOne case string(CfMany): @@ -674,7 +680,7 @@ func ToArrowhead(arrowheadType string, filled bool) Arrowhead { case string(CfManyRequired): return CfManyRequired default: - return TriangleArrowhead + return DefaultArrowhead } }