From 13a3edc4ba49a52ad6661f89e06eef9835b50077 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Fri, 3 Mar 2023 22:08:33 -0800 Subject: [PATCH] basic fix --- d2layouts/d2dagrelayout/layout.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go index 1c4793928..91aef8dc9 100644 --- a/d2layouts/d2dagrelayout/layout.go +++ b/d2layouts/d2dagrelayout/layout.go @@ -109,6 +109,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err maxContainerLabelHeight := 0 for _, obj := range g.Objects { + // TODO count root level container label sizes for ranksep if len(obj.ChildrenArray) == 0 || obj.Parent == g.Root { continue } @@ -134,7 +135,20 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err } maxLabelSize = go2.Max(maxLabelSize, size) } - rootAttrs.ranksep = go2.Max(go2.Max(100, maxLabelSize+40), maxContainerLabelHeight) + + rootAttrs.ranksep = go2.Max(100, maxLabelSize+40) + vSep := go2.Max(rootAttrs.ranksep, maxContainerLabelHeight) + // var nonContainerVSep int + if !isHorizontal { + rootAttrs.ranksep = vSep + } else { + // use existing config + rootAttrs.NodeSep = rootAttrs.EdgeSep + // configure vertical padding + rootAttrs.EdgeSep = vSep + // non-containers have both of this as padding + // nonContainerVSep = rootAttrs.NodeSep + rootAttrs.EdgeSep + } configJS := setGraphAttrs(rootAttrs) if _, err := vm.RunString(configJS); err != nil { @@ -286,7 +300,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err } for _, obj := range g.Objects { - if obj.LabelHeight == nil || len(obj.ChildrenArray) <= 0 { + if obj.LabelHeight == nil || len(obj.ChildrenArray) == 0 { continue }