basic fix

This commit is contained in:
Gavin Nishizawa 2023-03-03 22:08:33 -08:00
parent a85ccf2f4a
commit 13a3edc4ba
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -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
}