From 90e2fcf4e20adb9948b675aa589a3907daed0f14 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Thu, 22 Jun 2023 19:26:47 -0700 Subject: [PATCH] cleanup --- d2layouts/d2dagrelayout/layout.go | 24 +++++++++++------------- d2layouts/d2elklayout/layout.go | 23 +++++++++++------------ 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go index ba9a92bf3..fa2072896 100644 --- a/d2layouts/d2dagrelayout/layout.go +++ b/d2layouts/d2dagrelayout/layout.go @@ -236,8 +236,17 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err obj.Width = math.Ceil(dn.Width) obj.Height = math.Ceil(dn.Height) - hasLabelPosition := obj.LabelPosition != nil - if obj.HasLabel() && !hasLabelPosition { + if obj.Icon != nil && obj.IconPosition == nil { + if len(obj.ChildrenArray) > 0 { + obj.IconPosition = go2.Pointer(string(label.OutsideTopLeft)) + if obj.LabelPosition == nil { + obj.LabelPosition = go2.Pointer(string(label.OutsideTopRight)) + } + } else { + obj.IconPosition = go2.Pointer(string(label.InsideMiddleCenter)) + } + } + if obj.HasLabel() && obj.LabelPosition == nil { if len(obj.ChildrenArray) > 0 { obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter)) } else if obj.HasOutsideBottomLabel() { @@ -250,17 +259,6 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) } } - if obj.Icon != nil && obj.IconPosition == nil { - if len(obj.ChildrenArray) > 0 { - obj.IconPosition = go2.Pointer(string(label.OutsideTopLeft)) - if !hasLabelPosition { - // overwrite LabelPosition if we just set it above - obj.LabelPosition = go2.Pointer(string(label.OutsideTopRight)) - } - } else { - obj.IconPosition = go2.Pointer(string(label.InsideMiddleCenter)) - } - } } for i, edge := range g.Edges { diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go index 738bb8b1d..5ece1c0dc 100644 --- a/d2layouts/d2elklayout/layout.go +++ b/d2layouts/d2elklayout/layout.go @@ -407,8 +407,17 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err obj.Width = math.Ceil(n.Width) obj.Height = math.Ceil(n.Height) - hasLabelPosition := obj.LabelPosition != nil - if obj.HasLabel() && !hasLabelPosition { + if obj.Icon != nil && obj.IconPosition == nil { + if len(obj.ChildrenArray) > 0 { + obj.IconPosition = go2.Pointer(string(label.InsideTopLeft)) + if obj.LabelPosition == nil { + obj.LabelPosition = go2.Pointer(string(label.InsideTopRight)) + } + } else { + obj.IconPosition = go2.Pointer(string(label.InsideMiddleCenter)) + } + } + if obj.HasLabel() && obj.LabelPosition == nil { if len(obj.ChildrenArray) > 0 { obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) } else if obj.HasOutsideBottomLabel() { @@ -420,16 +429,6 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) } } - if obj.Icon != nil && obj.IconPosition == nil { - if len(obj.ChildrenArray) > 0 { - obj.IconPosition = go2.Pointer(string(label.InsideTopLeft)) - if !hasLabelPosition { - obj.LabelPosition = go2.Pointer(string(label.InsideTopRight)) - } - } else { - obj.IconPosition = go2.Pointer(string(label.InsideMiddleCenter)) - } - } byID[obj.AbsID()] = obj })