consider root level of extracted subgraph

This commit is contained in:
Gavin Nishizawa 2023-09-05 15:01:22 -07:00
parent fab9f79039
commit 3e08f51c66
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
2 changed files with 5 additions and 1 deletions

View file

@ -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()
}

View file

@ -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