From 40e8cc8530053217d093e73b823328e92581f8f2 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Fri, 20 Oct 2023 16:21:41 -0700 Subject: [PATCH] cleanup --- d2layouts/d2elklayout/layout.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go index 9159bac9a..6fbe5268f 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) { - 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++ - } + incoming := 0. + outgoing := 0. + for _, e := range g.Edges { + if e.Src == obj { + outgoing++ } - if incoming >= 2 || outgoing >= 2 { - switch g.Root.Direction.Value { - case "right", "left": + if e.Dst == obj { + incoming++ + } + } + 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) - default: + } + default: + if obj.Attributes.WidthAttr == nil { obj.Width = math.Max(obj.Width, math.Max(incoming, outgoing)*port_spacing) } }