Skip to content

Commit

Permalink
Merge pull request #1594 from gavin-ts/fix-nested-empty-grid
Browse files Browse the repository at this point in the history
Fix nested empty grid
  • Loading branch information
gavin-ts authored Sep 20, 2023
2 parents 833843a + 185b9d4 commit 68901fa
Show file tree
Hide file tree
Showing 8 changed files with 482 additions and 10 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
- Fixes Markdown cropping last element in mixed-element blocks (e.g. em and strong) [#1543](https://github.com/terrastruct/d2/issues/1543)
- Fixes missing compile error for non-blockstring empty labels [#1590](https://github.com/terrastruct/d2/issues/1590)
- Fixes multiple constant nears overlapping in some cases [#1591](https://github.com/terrastruct/d2/issues/1591)
- Fixes error with an empty nested grid [#1594](https://github.com/terrastruct/d2/issues/1594)
17 changes: 7 additions & 10 deletions d2layouts/d2grid/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ func withoutGridDiagrams(ctx context.Context, g *d2graph.Graph, layout d2graph.L
var processGrid func(obj *d2graph.Object) error
processGrid = func(obj *d2graph.Object) error {
for _, child := range obj.ChildrenArray {
if len(child.ChildrenArray) == 0 {
continue
}
if child.IsGridDiagram() {
if err := processGrid(child); err != nil {
return err
}
} else if len(child.ChildrenArray) > 0 {
} else {
tempGraph := g.ExtractAsNestedGraph(child)
if err := layout(ctx, tempGraph); err != nil {
return err
Expand Down Expand Up @@ -701,20 +704,14 @@ func (gd *gridDiagram) getBestLayout(targetSize float64, columns bool) [][]*d2gr
// if multiple nodes are too big, it isn't ok. but a single node can't shrink so only check here
if rowSize > okThreshold*targetSize {
skipCount++
if skipCount >= SKIP_LIMIT {
// there may even be too many to skip
return true
}
return false
// there may even be too many to skip
return skipCount >= SKIP_LIMIT
}
}
// row is too small to be good overall
if rowSize < targetSize/okThreshold {
skipCount++
if skipCount >= SKIP_LIMIT {
return true
}
return false
return skipCount >= SKIP_LIMIT
}
return true
}
Expand Down
1 change: 1 addition & 0 deletions e2etests/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ cf many required: {
loadFromFile(t, "outside_grid_label_position"),
loadFromFile(t, "arrowhead_font_color"),
loadFromFile(t, "multiple_constant_nears"),
loadFromFile(t, "empty_nested_grid"),
}

runa(t, tcs)
Expand Down
7 changes: 7 additions & 0 deletions e2etests/testdata/files/empty_nested_grid.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
outer: {
grid-rows: 1
inner: {
grid-rows: 1
# empty
}
}
130 changes: 130 additions & 0 deletions e2etests/testdata/regression/empty_nested_grid/dagre/board.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 103 additions & 0 deletions e2etests/testdata/regression/empty_nested_grid/dagre/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 68901fa

Please sign in to comment.