From 8a0204fa54380f79cafba373faaf0822fe5575b8 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Tue, 5 Sep 2023 19:00:07 -0700 Subject: [PATCH] update label dimensions alonside font size --- d2layouts/d2grid/layout.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/d2layouts/d2grid/layout.go b/d2layouts/d2grid/layout.go index 3bef6a423..7fae3d674 100644 --- a/d2layouts/d2grid/layout.go +++ b/d2layouts/d2grid/layout.go @@ -65,6 +65,7 @@ func withoutGridDiagrams(ctx context.Context, g *d2graph.Graph, layout d2graph.L return err } } else if len(child.ChildrenArray) > 0 { + originalFontSize := child.Text().FontSize tempGraph := g.ExtractAsNestedGraph(child) // emulating setting font size with layout fontSize := child.Text().FontSize @@ -72,6 +73,12 @@ func withoutGridDiagrams(ctx context.Context, g *d2graph.Graph, layout d2graph.L child.Style.FontSize = &d2graph.Scalar{} } child.Style.FontSize.Value = strconv.Itoa(fontSize) + + // update label dimensions + ratio := float64(fontSize) / float64(originalFontSize) + child.LabelDimensions.Height = int(math.Ceil(float64(child.LabelDimensions.Height) * ratio)) + child.LabelDimensions.Width = int(math.Ceil(float64(child.LabelDimensions.Width) * ratio)) + if err := layout(ctx, tempGraph); err != nil { return err }