use elk layout's edge label position
This commit is contained in:
parent
15a64b2333
commit
243df4b8e1
4 changed files with 12 additions and 3 deletions
|
|
@ -242,6 +242,9 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection
|
||||||
if edge.LabelPercentage != nil {
|
if edge.LabelPercentage != nil {
|
||||||
connection.LabelPercentage = *edge.LabelPercentage
|
connection.LabelPercentage = *edge.LabelPercentage
|
||||||
}
|
}
|
||||||
|
if edge.LabelTL != nil {
|
||||||
|
connection.LabelTL = edge.LabelTL.Copy()
|
||||||
|
}
|
||||||
connection.Route = edge.Route
|
connection.Route = edge.Route
|
||||||
connection.IsCurve = edge.IsCurve
|
connection.IsCurve = edge.IsCurve
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -664,6 +664,7 @@ type Edge struct {
|
||||||
LabelDimensions d2target.TextDimensions `json:"label_dimensions"`
|
LabelDimensions d2target.TextDimensions `json:"label_dimensions"`
|
||||||
LabelPosition *string `json:"labelPosition,omitempty"`
|
LabelPosition *string `json:"labelPosition,omitempty"`
|
||||||
LabelPercentage *float64 `json:"labelPercentage,omitempty"`
|
LabelPercentage *float64 `json:"labelPercentage,omitempty"`
|
||||||
|
LabelTL *geo.Point `json:"labelTL,omitempty"`
|
||||||
|
|
||||||
IsCurve bool `json:"isCurve"`
|
IsCurve bool `json:"isCurve"`
|
||||||
Route []*geo.Point `json:"route,omitempty"`
|
Route []*geo.Point `json:"route,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -308,7 +308,8 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
|
||||||
points[endIndex] = shape.TraceToShapeBorder(dstShape, points[endIndex], points[endIndex-1])
|
points[endIndex] = shape.TraceToShapeBorder(dstShape, points[endIndex], points[endIndex-1])
|
||||||
|
|
||||||
if edge.Attributes.Label.Value != "" {
|
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
|
edge.Route = points
|
||||||
|
|
|
||||||
|
|
@ -210,8 +210,9 @@ type Connection struct {
|
||||||
Fill string `json:"fill,omitempty"`
|
Fill string `json:"fill,omitempty"`
|
||||||
|
|
||||||
Text
|
Text
|
||||||
LabelPosition string `json:"labelPosition"`
|
LabelPosition string `json:"labelPosition"`
|
||||||
LabelPercentage float64 `json:"labelPercentage"`
|
LabelPercentage float64 `json:"labelPercentage"`
|
||||||
|
LabelTL *geo.Point `json:"labelTL,omitempty"`
|
||||||
|
|
||||||
Route []*geo.Point `json:"route"`
|
Route []*geo.Point `json:"route"`
|
||||||
IsCurve bool `json:"isCurve,omitempty"`
|
IsCurve bool `json:"isCurve,omitempty"`
|
||||||
|
|
@ -239,6 +240,9 @@ func BaseConnection() *Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Connection) GetLabelTopLeft() *geo.Point {
|
func (c *Connection) GetLabelTopLeft() *geo.Point {
|
||||||
|
if c.LabelTL != nil {
|
||||||
|
return c.LabelTL
|
||||||
|
}
|
||||||
return label.Position(c.LabelPosition).GetPointOnRoute(
|
return label.Position(c.LabelPosition).GetPointOnRoute(
|
||||||
c.Route,
|
c.Route,
|
||||||
float64(c.StrokeWidth),
|
float64(c.StrokeWidth),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue