Skip to content

Commit

Permalink
Merge pull request #555 from gavin-ts/fix-elk-panic
Browse files Browse the repository at this point in the history
elk: fix panic with empty label on image/icon
  • Loading branch information
gavin-ts authored Dec 29, 2022
2 parents 07500f4 + e44662a commit 1c958ea
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 2 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
#### Bugfixes ⛑️

- Restricts where `near` key constant values can be used, with good error messages, instead of erroring (e.g. setting `near: top-center` on a container would cause bad layouts or error). [#538](https://github.com/terrastruct/d2/pull/538)
- Fixes an error during ELK layout when images had empty labels. [#555](https://github.com/terrastruct/d2/pull/555)
- Fixes rendering classes and tables with empty headers. [#498](https://github.com/terrastruct/d2/pull/498)
6 changes: 4 additions & 2 deletions d2layouts/d2elklayout/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {

walk(g.Root, nil, func(obj, parent *d2graph.Object) {
height := obj.Height
if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil {
height += float64(*obj.LabelHeight) + label.PADDING
if obj.LabelWidth != nil && obj.LabelHeight != nil {
if obj.Attributes.Shape.Value == d2target.ShapeImage || obj.Attributes.Icon != nil {
height += float64(*obj.LabelHeight) + label.PADDING
}
}

n := &ELKNode{
Expand Down
14 changes: 14 additions & 0 deletions e2etests/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,20 @@ code: |go
b := a + 7
fmt.Printf("%d", b)
|
`,
},
{
name: "elk_img_empty_label_panic",
script: `
img: {
label: ""
shape: image
icon: https://icons.terrastruct.com/infra/019-network.svg
}
ico: {
label: ""
icon: https://icons.terrastruct.com/infra/019-network.svg
}
`,
},
}
Expand Down

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1c958ea

Please sign in to comment.