diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go index 91aef8dc9..be2f69998 100644 --- a/d2layouts/d2dagrelayout/layout.go +++ b/d2layouts/d2dagrelayout/layout.go @@ -127,27 +127,24 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err } } - maxLabelSize := 0 + maxLabelWidth := 0 + maxLabelHeight := 0 for _, edge := range g.Edges { - size := edge.LabelDimensions.Width - if !isHorizontal { - size = edge.LabelDimensions.Height - } - maxLabelSize = go2.Max(maxLabelSize, size) + width := edge.LabelDimensions.Width + height := edge.LabelDimensions.Height + maxLabelWidth = go2.Max(maxLabelWidth, width) + maxLabelHeight = go2.Max(maxLabelHeight, height) } - rootAttrs.ranksep = go2.Max(100, maxLabelSize+40) - vSep := go2.Max(rootAttrs.ranksep, maxContainerLabelHeight) - // var nonContainerVSep int if !isHorizontal { - rootAttrs.ranksep = vSep + rootAttrs.ranksep = go2.Max(go2.Max(100, maxLabelHeight+40), maxContainerLabelHeight) } else { + rootAttrs.ranksep = go2.Max(100, maxLabelWidth+40) // 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 + rootAttrs.EdgeSep = go2.Max(maxLabelHeight+40, maxContainerLabelHeight) + // Note: non-containers have both of these as padding (rootAttrs.NodeSep + rootAttrs.EdgeSep) } configJS := setGraphAttrs(rootAttrs)