diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 8379d184b..df9d12a9a 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -57,6 +57,9 @@ type Graph struct { Steps []*Graph `json:"steps,omitempty"` Theme *d2themes.Theme `json:"theme,omitempty"` + + // Object.Level uses the location of a nested graph + RootLevel int `json:"rootLevel,omitempty"` } func NewGraph() *Graph { @@ -529,7 +532,7 @@ func (obj *Object) GetStroke(dashGapSize interface{}) string { func (obj *Object) Level() ContainerLevel { if obj.Parent == nil { - return 0 + return ContainerLevel(obj.Graph.RootLevel) } return 1 + obj.Parent.Level() } diff --git a/d2graph/layout.go b/d2graph/layout.go index 4d50efc1d..51b3206b9 100644 --- a/d2graph/layout.go +++ b/d2graph/layout.go @@ -41,6 +41,7 @@ func (g *Graph) ExtractAsNestedGraph(obj *Object) *Graph { descendantObjects, edges := pluckObjAndEdges(g, obj) tempGraph := NewGraph() + tempGraph.RootLevel = int(obj.Level()) - 1 tempGraph.Root.ChildrenArray = []*Object{obj} tempGraph.Root.Children[strings.ToLower(obj.ID)] = obj