From 1baac617117772d5eee63d2b6b2171ec45e4102b Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Thu, 21 Sep 2023 18:37:47 -0700 Subject: [PATCH] fix multiple sequence diagram inject order --- d2layouts/d2layouts.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/d2layouts/d2layouts.go b/d2layouts/d2layouts.go index a5783cf0e..cfdea0ce2 100644 --- a/d2layouts/d2layouts.go +++ b/d2layouts/d2layouts.go @@ -79,7 +79,7 @@ func LayoutNested(ctx context.Context, g *d2graph.Graph, graphInfo GraphInfo, co log.Warn(ctx, "ln info", slog.F("gi", graphInfo), slog.F("root level", g.RootLevel)) // Before we can layout these nodes, we need to handle all nested diagrams first. extracted := make(map[*d2graph.Object]*d2graph.Graph) - extractedInfo := make(map[*d2graph.Object]GraphInfo) + var extractedOrder []*d2graph.Object var constantNears []*d2graph.Graph restoreOrder := SaveOrder(g) @@ -125,8 +125,6 @@ func LayoutNested(ctx context.Context, g *d2graph.Graph, graphInfo GraphInfo, co continue } - extractedInfo[curr] = gi - // There is a nested diagram here, so extract its contents and process in the same way nestedGraph := ExtractSubgraph(curr, gi.IsConstantNear) @@ -157,6 +155,7 @@ func LayoutNested(ctx context.Context, g *d2graph.Graph, graphInfo GraphInfo, co } else { // We will restore the contents after running layout with child as the placeholder extracted[curr] = nestedGraph + extractedOrder = append(extractedOrder, curr) } } else if len(curr.ChildrenArray) > 0 { queue = append(queue, curr.ChildrenArray...) @@ -199,7 +198,8 @@ func LayoutNested(ctx context.Context, g *d2graph.Graph, graphInfo GraphInfo, co } // With the layout set, inject all the extracted graphs - for n, nestedGraph := range extracted { + for _, n := range extractedOrder { + nestedGraph := extracted[n] InjectNested(n, nestedGraph, true) PositionNested(n, nestedGraph) }