arrowhead refactor

This commit is contained in:
Gavin Nishizawa 2023-04-24 18:32:24 -07:00
parent acba0733db
commit e6e9673ddd
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
3 changed files with 25 additions and 19 deletions

View file

@ -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 {

View file

@ -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"`

View file

@ -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
}
}