update strategy for nested grid cell layout

This commit is contained in:
Gavin Nishizawa 2023-09-27 16:54:15 -07:00
parent c9d5003343
commit 7b28c9290c
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -106,6 +106,7 @@ func LayoutNested(ctx context.Context, g *d2graph.Graph, graphInfo GraphInfo, co
if err != nil { if err != nil {
return err return err
} }
InjectNested(g.Root, nestedGraph, false) InjectNested(g.Root, nestedGraph, false)
restoreOrder() restoreOrder()
@ -135,6 +136,12 @@ func LayoutNested(ctx context.Context, g *d2graph.Graph, graphInfo GraphInfo, co
for _, e := range nestedGraph.Edges { for _, e := range nestedGraph.Edges {
e.Move(dx, dy) e.Move(dx, dy)
} }
// now we keep the descendants out until after grid layout
nestedGraph = ExtractSubgraph(curr, false)
extracted[id] = nestedGraph
extractedOrder = append(extractedOrder, id)
continue continue
} }
@ -330,7 +337,6 @@ func ExtractSubgraph(container *d2graph.Object, includeSelf bool) *d2graph.Graph
} }
func InjectNested(container *d2graph.Object, nestedGraph *d2graph.Graph, isRoot bool) { func InjectNested(container *d2graph.Object, nestedGraph *d2graph.Graph, isRoot bool) {
// TODO restore order of objects
g := container.Graph g := container.Graph
for _, obj := range nestedGraph.Root.ChildrenArray { for _, obj := range nestedGraph.Root.ChildrenArray {
obj.Parent = container obj.Parent = container