have elk place edge labels on the edge
This commit is contained in:
parent
6a064aa85c
commit
eed6eadd58
4 changed files with 26 additions and 36 deletions
|
|
@ -242,9 +242,6 @@ 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
|
||||
|
||||
|
|
|
|||
|
|
@ -664,7 +664,6 @@ 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"`
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ type ELKLabel struct {
|
|||
Y float64 `json:"y"`
|
||||
Width float64 `json:"width"`
|
||||
Height float64 `json:"height"`
|
||||
LayoutOptions *ELKLayoutOptions `json:"layoutOptions,omitempty"`
|
||||
}
|
||||
|
||||
type ELKPoint struct {
|
||||
|
|
@ -85,8 +86,7 @@ type ELKLayoutOptions struct {
|
|||
EdgeNodeSpacing float64 `json:"spacing.edgeNodeBetweenLayers,omitempty"`
|
||||
Direction string `json:"elk.direction"`
|
||||
SelfLoopSpacing float64 `json:"elk.spacing.nodeSelfLoop"`
|
||||
EdgeLabelSpacing float64 `json:"spacing.edgeLabel,omitempty"`
|
||||
LabelSideSelection string `json:"elk.layered.edgeLabels.sideSelection,omitempty"`
|
||||
InlineEdgeLabels bool `json:"elk.edgeLabels.inline,omitempty"`
|
||||
}
|
||||
|
||||
func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
|
||||
|
|
@ -114,8 +114,6 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
|
|||
NodeSpacing: 100.0,
|
||||
EdgeNodeSpacing: 50.0,
|
||||
SelfLoopSpacing: 50.0,
|
||||
EdgeLabelSpacing: 5.0,
|
||||
LabelSideSelection: "SMART_UP",
|
||||
},
|
||||
}
|
||||
switch g.Root.Attributes.Direction.Value {
|
||||
|
|
@ -160,8 +158,6 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
|
|||
if len(obj.ChildrenArray) > 0 {
|
||||
n.LayoutOptions = &ELKLayoutOptions{
|
||||
Padding: "[top=75,left=75,bottom=75,right=75]",
|
||||
EdgeLabelSpacing: 5.0,
|
||||
LabelSideSelection: "SMART_UP",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -192,6 +188,9 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
|
|||
Text: edge.Attributes.Label.Value,
|
||||
Width: float64(edge.LabelDimensions.Width),
|
||||
Height: float64(edge.LabelDimensions.Height),
|
||||
LayoutOptions: &ELKLayoutOptions{
|
||||
InlineEdgeLabels: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
elkGraph.Edges = append(elkGraph.Edges, e)
|
||||
|
|
@ -314,8 +313,7 @@ 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 != "" {
|
||||
// using the edge label position from elk layout
|
||||
edge.LabelTL = geo.NewPoint(e.Labels[0].X+parentX, e.Labels[0].Y+parentY)
|
||||
edge.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
|
||||
}
|
||||
|
||||
edge.Route = points
|
||||
|
|
|
|||
|
|
@ -212,7 +212,6 @@ type Connection struct {
|
|||
Text
|
||||
LabelPosition string `json:"labelPosition"`
|
||||
LabelPercentage float64 `json:"labelPercentage"`
|
||||
LabelTL *geo.Point `json:"labelTL,omitempty"`
|
||||
|
||||
Route []*geo.Point `json:"route"`
|
||||
IsCurve bool `json:"isCurve,omitempty"`
|
||||
|
|
@ -240,9 +239,6 @@ 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),
|
||||
|
|
|
|||
Loading…
Reference in a new issue