From e2b510a1c8ab3b95639663e82f301f4b78b927e2 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Mon, 19 Dec 2022 20:48:01 -0800 Subject: [PATCH] improve label placement for shapes with icons --- d2layouts/d2dagrelayout/layout.go | 4 ++-- d2layouts/d2elklayout/layout.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go index b516e228a..3ae70e35a 100644 --- a/d2layouts/d2dagrelayout/layout.go +++ b/d2layouts/d2dagrelayout/layout.go @@ -93,7 +93,7 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) { height := obj.Height if obj.LabelWidth != nil && obj.LabelHeight != nil { - if obj.Attributes.Shape.Value == d2target.ShapeImage { + if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil { height += float64(*obj.LabelHeight) + label.PADDING } } @@ -163,7 +163,7 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) { // remove the extra height we added to the node when passing to dagre obj.Height -= float64(*obj.LabelHeight) + label.PADDING } else if obj.Attributes.Icon != nil { - obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter)) + obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) } else { obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) } diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go index 6f0d2c91b..fb364ceba 100644 --- a/d2layouts/d2elklayout/layout.go +++ b/d2layouts/d2elklayout/layout.go @@ -143,7 +143,7 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) { walk(g.Root, nil, func(obj, parent *d2graph.Object) { height := obj.Height - if obj.Attributes.Shape.Value == d2target.ShapeImage { + if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil { height += float64(*obj.LabelHeight) + label.PADDING } @@ -259,7 +259,7 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) { obj.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter)) obj.Height -= float64(*obj.LabelHeight) + label.PADDING } else if obj.Attributes.Icon != nil { - obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter)) + obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) } else { obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) }