From 107b556c20dcfdc151622920ed5dd1ea46d1321a Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Wed, 8 Nov 2023 14:06:15 -0800 Subject: [PATCH] don't overwrite grid label position --- d2layouts/d2grid/layout.go | 6 ++---- d2layouts/d2layouts.go | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/d2layouts/d2grid/layout.go b/d2layouts/d2grid/layout.go index f4e9201f1..cf6794d54 100644 --- a/d2layouts/d2grid/layout.go +++ b/d2layouts/d2grid/layout.go @@ -89,10 +89,10 @@ func Layout(ctx context.Context, g *d2graph.Graph) error { } } - if obj.HasLabel() { + if obj.HasLabel() && obj.LabelPosition == nil { obj.LabelPosition = go2.Pointer(label.InsideTopCenter.String()) } - if obj.Icon != nil { + if obj.Icon != nil && obj.IconPosition == nil { obj.IconPosition = go2.Pointer(label.InsideTopLeft.String()) } @@ -119,8 +119,6 @@ func Layout(ctx context.Context, g *d2graph.Graph) error { g.Root.TopLeft = geo.NewPoint(0, 0) } - obj.LabelPosition = go2.Pointer(label.InsideTopCenter.String()) - if g.RootLevel > 0 { horizontalPadding, verticalPadding := CONTAINER_PADDING, CONTAINER_PADDING if obj.GridGap != nil || obj.HorizontalGap != nil { diff --git a/d2layouts/d2layouts.go b/d2layouts/d2layouts.go index c29cb1e47..7a05f2533 100644 --- a/d2layouts/d2layouts.go +++ b/d2layouts/d2layouts.go @@ -305,6 +305,8 @@ func ExtractSubgraph(container *d2graph.Object, includeSelf bool) (nestedGraph * } nestedGraph.Root.Attributes = container.Attributes nestedGraph.Root.Box = &geo.Box{} + nestedGraph.Root.LabelPosition = container.LabelPosition + nestedGraph.Root.IconPosition = container.IconPosition isNestedObject := func(obj *d2graph.Object) bool { if includeSelf {