diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go index 95bb3305c..9159bac9a 100644 --- a/d2layouts/d2elklayout/layout.go +++ b/d2layouts/d2elklayout/layout.go @@ -202,22 +202,24 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err } walk(g.Root, nil, func(obj, parent *d2graph.Object) { - incoming := 0. - outgoing := 0. - for _, e := range g.Edges { - if e.Src == obj { - outgoing++ + if obj.Attributes.WidthAttr == nil || obj.Attributes.HeightAttr == nil { + incoming := 0. + outgoing := 0. + for _, e := range g.Edges { + if e.Src == obj { + outgoing++ + } + if e.Dst == obj { + incoming++ + } } - if e.Dst == obj { - incoming++ - } - } - if incoming >= 2 || outgoing >= 2 { - switch g.Root.Direction.Value { - 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) + if incoming >= 2 || outgoing >= 2 { + switch g.Root.Direction.Value { + 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) + } } }