Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix object.Level during nested layout #1574

Merged
merged 8 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion d2graph/d2graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
Expand Down
1 change: 1 addition & 0 deletions d2graph/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (g *Graph) ExtractAsNestedGraph(obj *Object) *Graph {
descendantObjects, edges := pluckObjAndEdges(g, obj)

tempGraph := NewGraph()
tempGraph.RootLevel = int(obj.Level()) - 1
alixander marked this conversation as resolved.
Show resolved Hide resolved
tempGraph.Root.ChildrenArray = []*Object{obj}
tempGraph.Root.Children[strings.ToLower(obj.ID)] = obj

Expand Down
1 change: 1 addition & 0 deletions e2etests/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ cf many required: {
loadFromFile(t, "grid_with_latex"),
loadFromFile(t, "icons_on_top"),
loadFromFile(t, "dagre_disconnected_edge"),
loadFromFile(t, "outside_grid_label_position"),
}

runa(t, tcs)
Expand Down
23 changes: 23 additions & 0 deletions e2etests/testdata/files/outside_grid_label_position.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
container1: {
container2: {
container3: {
grid-rows: 1

first: {
label.near: outside-top-center
child: {
label.near: outside-bottom-center
}
}
second: {
label.near: outside-top-center
child: {
label.near: outside-bottom-center
}
}
third: {
label.near: outside-top-center
}
}
}
}
108 changes: 108 additions & 0 deletions e2etests/testdata/files/outside_grid_label_position.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading