From 4385e63eddd1b78c8b28888b8cb36cd81fa81f14 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Thu, 21 Sep 2023 14:16:07 -0700 Subject: [PATCH] fix containers in grid layout --- d2layouts/d2layouts.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/d2layouts/d2layouts.go b/d2layouts/d2layouts.go index a1508fdc9..92eb3c4de 100644 --- a/d2layouts/d2layouts.go +++ b/d2layouts/d2layouts.go @@ -48,14 +48,18 @@ func LayoutNested(ctx context.Context, g *d2graph.Graph, graphInfo GraphInfo, co queue = append(queue, g.Root.ChildrenArray...) for _, child := range queue { - if gi := NestedGraphInfo(child); !gi.isDefault() { + isGridCellContainer := (graphInfo.DiagramType == GridDiagram && child.IsContainer()) + gi := NestedGraphInfo(child) + // if we are in a grid diagram, and our children have descendants + // we need to run layout on them first, even if they are not special diagram types + if isGridCellContainer || !gi.isDefault() { extractedInfo[child] = gi // There is a nested diagram here, so extract its contents and process in the same way nestedGraph := ExtractDescendants(child) // Layout of nestedGraph is completed - // log.Error(ctx, "recurse", slog.F("child", child.AbsID()), slog.F("level", child.Level())) + log.Info(ctx, "layout nested", slog.F("level", child.Level()), slog.F("child", child.AbsID())) spacing := LayoutNested(ctx, nestedGraph, gi, coreLayout) log.Warn(ctx, "fitting child", slog.F("child", child.AbsID())) // Fit child to size of nested layout @@ -65,9 +69,9 @@ func LayoutNested(ctx context.Context, g *d2graph.Graph, graphInfo GraphInfo, co // main layout is run, then near positions child, then descendants are injected with all others if gi.IsConstantNear { nearGraph := ExtractSelf(child) - child.TopLeft = geo.NewPoint(0, 0) constantNears = append(constantNears, nearGraph) } + child.TopLeft = geo.NewPoint(0, 0) // We will restore the contents after running layout with child as the placeholder extracted[child] = nestedGraph