elk: don't grow node if there is a width/height input

This commit is contained in:
Gavin Nishizawa 2023-10-20 16:13:19 -07:00
parent ca754aefdc
commit 9ab1971d54
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) {
incoming := 0. if obj.Attributes.WidthAttr == nil || obj.Attributes.HeightAttr == nil {
outgoing := 0. incoming := 0.
for _, e := range g.Edges { outgoing := 0.
if e.Src == obj { for _, e := range g.Edges {
outgoing++ if e.Src == obj {
outgoing++
}
if e.Dst == obj {
incoming++
}
} }
if e.Dst == obj { if incoming >= 2 || outgoing >= 2 {
incoming++ switch g.Root.Direction.Value {
} case "right", "left":
} obj.Height = math.Max(obj.Height, math.Max(incoming, outgoing)*port_spacing)
if incoming >= 2 || outgoing >= 2 { default:
switch g.Root.Direction.Value { obj.Width = math.Max(obj.Width, math.Max(incoming, outgoing)*port_spacing)
case "right", "left": }
obj.Height = math.Max(obj.Height, math.Max(incoming, outgoing)*port_spacing)
default:
obj.Width = math.Max(obj.Width, math.Max(incoming, outgoing)*port_spacing)
} }
} }