This commit is contained in:
Gavin Nishizawa 2023-10-20 16:21:41 -07:00
parent 637048ad28
commit 40e8cc8530
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -202,22 +202,24 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
} }
walk(g.Root, nil, func(obj, parent *d2graph.Object) { walk(g.Root, nil, func(obj, parent *d2graph.Object) {
if obj.Attributes.WidthAttr == nil || obj.Attributes.HeightAttr == nil { incoming := 0.
incoming := 0. outgoing := 0.
outgoing := 0. for _, e := range g.Edges {
for _, e := range g.Edges { if e.Src == obj {
if e.Src == obj { outgoing++
outgoing++
}
if e.Dst == obj {
incoming++
}
} }
if incoming >= 2 || outgoing >= 2 { if e.Dst == obj {
switch g.Root.Direction.Value { incoming++
case "right", "left": }
}
if incoming >= 2 || outgoing >= 2 {
switch g.Root.Direction.Value {
case "right", "left":
if obj.Attributes.HeightAttr == nil {
obj.Height = math.Max(obj.Height, math.Max(incoming, outgoing)*port_spacing) obj.Height = math.Max(obj.Height, math.Max(incoming, outgoing)*port_spacing)
default: }
default:
if obj.Attributes.WidthAttr == nil {
obj.Width = math.Max(obj.Width, math.Max(incoming, outgoing)*port_spacing) obj.Width = math.Max(obj.Width, math.Max(incoming, outgoing)*port_spacing)
} }
} }