From 6bb39115d4c206700a7d8240bf74b3cce1fbf616 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Tue, 20 Dec 2022 14:51:59 -0800 Subject: [PATCH] place elk edge labels on right with more padding --- d2layouts/d2elklayout/layout.go | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go index 75ada9428..bbdf55878 100644 --- a/d2layouts/d2elklayout/layout.go +++ b/d2layouts/d2elklayout/layout.go @@ -78,13 +78,15 @@ type ELKGraph struct { } type ELKLayoutOptions struct { - Algorithm string `json:"elk.algorithm,omitempty"` - HierarchyHandling string `json:"elk.hierarchyHandling,omitempty"` - NodeSpacing float64 `json:"spacing.nodeNodeBetweenLayers,omitempty"` - Padding string `json:"elk.padding,omitempty"` - EdgeNodeSpacing float64 `json:"spacing.edgeNodeBetweenLayers,omitempty"` - Direction string `json:"elk.direction"` - SelfLoopSpacing float64 `json:"elk.spacing.nodeSelfLoop"` + Algorithm string `json:"elk.algorithm,omitempty"` + HierarchyHandling string `json:"elk.hierarchyHandling,omitempty"` + NodeSpacing float64 `json:"spacing.nodeNodeBetweenLayers,omitempty"` + Padding string `json:"elk.padding,omitempty"` + 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"` } func Layout(ctx context.Context, g *d2graph.Graph) (err error) { @@ -107,11 +109,13 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) { elkGraph := &ELKGraph{ ID: "root", LayoutOptions: &ELKLayoutOptions{ - Algorithm: "layered", - HierarchyHandling: "INCLUDE_CHILDREN", - NodeSpacing: 100.0, - EdgeNodeSpacing: 50.0, - SelfLoopSpacing: 50.0, + Algorithm: "layered", + HierarchyHandling: "INCLUDE_CHILDREN", + NodeSpacing: 100.0, + EdgeNodeSpacing: 50.0, + SelfLoopSpacing: 50.0, + EdgeLabelSpacing: 5.0, + LabelSideSelection: "SMART_UP", }, } switch g.Root.Attributes.Direction.Value { @@ -155,7 +159,9 @@ 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]", + Padding: "[top=75,left=75,bottom=75,right=75]", + EdgeLabelSpacing: 5.0, + LabelSideSelection: "SMART_UP", } }