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() text := edge.Text()
if edge.SrcArrow { if edge.SrcArrow {
connection.SrcArrow = d2target.TriangleArrowhead connection.SrcArrow = d2target.DefaultArrowhead
if edge.SrcArrowhead != nil { if edge.SrcArrowhead != nil && edge.SrcArrowhead.Shape.Value != "" {
if edge.SrcArrowhead.Shape.Value != "" { connection.SrcArrow = edge.SrcArrowhead.ToArrowhead()
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)
}
} }
} }
if edge.SrcArrowhead != nil { if edge.SrcArrowhead != nil {
@ -221,15 +215,9 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection
} }
} }
if edge.DstArrow { if edge.DstArrow {
connection.DstArrow = d2target.TriangleArrowhead connection.DstArrow = d2target.DefaultArrowhead
if edge.DstArrowhead != nil { if edge.DstArrowhead != nil && edge.DstArrowhead.Shape.Value != "" {
if edge.DstArrowhead.Shape.Value != "" { connection.DstArrow = edge.DstArrowhead.ToArrowhead()
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)
}
} }
} }
if edge.DstArrowhead != nil { 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 // TODO references at the root scope should have their Scope set to root graph AST
type Reference struct { type Reference struct {
Key *d2ast.KeyPath `json:"key"` Key *d2ast.KeyPath `json:"key"`

View file

@ -635,6 +635,8 @@ const (
CfMany Arrowhead = "cf-many" CfMany Arrowhead = "cf-many"
CfOneRequired Arrowhead = "cf-one-required" CfOneRequired Arrowhead = "cf-one-required"
CfManyRequired Arrowhead = "cf-many-required" CfManyRequired Arrowhead = "cf-many-required"
DefaultArrowhead Arrowhead = TriangleArrowhead
) )
var Arrowheads = map[string]struct{}{ var Arrowheads = map[string]struct{}{
@ -663,8 +665,12 @@ func ToArrowhead(arrowheadType string, filled bool) Arrowhead {
return FilledCircleArrowhead return FilledCircleArrowhead
} }
return CircleArrowhead return CircleArrowhead
case string(NoArrowhead):
return NoArrowhead
case string(ArrowArrowhead): case string(ArrowArrowhead):
return ArrowArrowhead return ArrowArrowhead
case string(TriangleArrowhead):
return TriangleArrowhead
case string(CfOne): case string(CfOne):
return CfOne return CfOne
case string(CfMany): case string(CfMany):
@ -674,7 +680,7 @@ func ToArrowhead(arrowheadType string, filled bool) Arrowhead {
case string(CfManyRequired): case string(CfManyRequired):
return CfManyRequired return CfManyRequired
default: default:
return TriangleArrowhead return DefaultArrowhead
} }
} }