use elk layout's edge label position

This commit is contained in:
Gavin Nishizawa 2022-12-20 14:03:40 -08:00
parent 15a64b2333
commit 243df4b8e1
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
4 changed files with 12 additions and 3 deletions

View file

@ -242,6 +242,9 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection
if edge.LabelPercentage != nil {
connection.LabelPercentage = *edge.LabelPercentage
}
if edge.LabelTL != nil {
connection.LabelTL = edge.LabelTL.Copy()
}
connection.Route = edge.Route
connection.IsCurve = edge.IsCurve

View file

@ -664,6 +664,7 @@ type Edge struct {
LabelDimensions d2target.TextDimensions `json:"label_dimensions"`
LabelPosition *string `json:"labelPosition,omitempty"`
LabelPercentage *float64 `json:"labelPercentage,omitempty"`
LabelTL *geo.Point `json:"labelTL,omitempty"`
IsCurve bool `json:"isCurve"`
Route []*geo.Point `json:"route,omitempty"`

View file

@ -308,7 +308,8 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
points[endIndex] = shape.TraceToShapeBorder(dstShape, points[endIndex], points[endIndex-1])
if edge.Attributes.Label.Value != "" {
edge.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
// using the edge label position from elk layout
edge.LabelTL = geo.NewPoint(e.Labels[0].X+parentX, e.Labels[0].Y+parentY)
}
edge.Route = points

View file

@ -210,8 +210,9 @@ type Connection struct {
Fill string `json:"fill,omitempty"`
Text
LabelPosition string `json:"labelPosition"`
LabelPercentage float64 `json:"labelPercentage"`
LabelPosition string `json:"labelPosition"`
LabelPercentage float64 `json:"labelPercentage"`
LabelTL *geo.Point `json:"labelTL,omitempty"`
Route []*geo.Point `json:"route"`
IsCurve bool `json:"isCurve,omitempty"`
@ -239,6 +240,9 @@ func BaseConnection() *Connection {
}
func (c *Connection) GetLabelTopLeft() *geo.Point {
if c.LabelTL != nil {
return c.LabelTL
}
return label.Position(c.LabelPosition).GetPointOnRoute(
c.Route,
float64(c.StrokeWidth),