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 {
|
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,7 +664,6 @@ 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"`
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ type ELKLabel struct {
|
||||||
Y float64 `json:"y"`
|
Y float64 `json:"y"`
|
||||||
Width float64 `json:"width"`
|
Width float64 `json:"width"`
|
||||||
Height float64 `json:"height"`
|
Height float64 `json:"height"`
|
||||||
|
LayoutOptions *ELKLayoutOptions `json:"layoutOptions,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ELKPoint struct {
|
type ELKPoint struct {
|
||||||
|
|
@ -85,8 +86,7 @@ type ELKLayoutOptions struct {
|
||||||
EdgeNodeSpacing float64 `json:"spacing.edgeNodeBetweenLayers,omitempty"`
|
EdgeNodeSpacing float64 `json:"spacing.edgeNodeBetweenLayers,omitempty"`
|
||||||
Direction string `json:"elk.direction"`
|
Direction string `json:"elk.direction"`
|
||||||
SelfLoopSpacing float64 `json:"elk.spacing.nodeSelfLoop"`
|
SelfLoopSpacing float64 `json:"elk.spacing.nodeSelfLoop"`
|
||||||
EdgeLabelSpacing float64 `json:"spacing.edgeLabel,omitempty"`
|
InlineEdgeLabels bool `json:"elk.edgeLabels.inline,omitempty"`
|
||||||
LabelSideSelection string `json:"elk.layered.edgeLabels.sideSelection,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
|
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,
|
NodeSpacing: 100.0,
|
||||||
EdgeNodeSpacing: 50.0,
|
EdgeNodeSpacing: 50.0,
|
||||||
SelfLoopSpacing: 50.0,
|
SelfLoopSpacing: 50.0,
|
||||||
EdgeLabelSpacing: 5.0,
|
|
||||||
LabelSideSelection: "SMART_UP",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
switch g.Root.Attributes.Direction.Value {
|
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 {
|
if len(obj.ChildrenArray) > 0 {
|
||||||
n.LayoutOptions = &ELKLayoutOptions{
|
n.LayoutOptions = &ELKLayoutOptions{
|
||||||
Padding: "[top=75,left=75,bottom=75,right=75]",
|
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,
|
Text: edge.Attributes.Label.Value,
|
||||||
Width: float64(edge.LabelDimensions.Width),
|
Width: float64(edge.LabelDimensions.Width),
|
||||||
Height: float64(edge.LabelDimensions.Height),
|
Height: float64(edge.LabelDimensions.Height),
|
||||||
|
LayoutOptions: &ELKLayoutOptions{
|
||||||
|
InlineEdgeLabels: true,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
elkGraph.Edges = append(elkGraph.Edges, e)
|
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])
|
points[endIndex] = shape.TraceToShapeBorder(dstShape, points[endIndex], points[endIndex-1])
|
||||||
|
|
||||||
if edge.Attributes.Label.Value != "" {
|
if edge.Attributes.Label.Value != "" {
|
||||||
// using the edge label position from elk layout
|
edge.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
|
||||||
edge.LabelTL = geo.NewPoint(e.Labels[0].X+parentX, e.Labels[0].Y+parentY)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
edge.Route = points
|
edge.Route = points
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,6 @@ type Connection struct {
|
||||||
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"`
|
||||||
|
|
@ -240,9 +239,6 @@ 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