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

render: sql table with only header #553

Merged
merged 4 commits into from
Dec 29, 2022
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
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
- 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)
- Fixes rendering sql tables with no columns. [#553](https://github.com/terrastruct/d2/pull/553)
4 changes: 3 additions & 1 deletion d2graph/d2graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,9 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R

// The rows get padded a little due to header font being larger than row font
dims.Height = labelDims.Height * (len(obj.SQLTable.Columns) + 1)
dims.Width = d2target.NamePadding + maxNameWidth + d2target.TypePadding + maxTypeWidth + d2target.TypePadding + constraintWidth
headerWidth := d2target.HeaderPadding + labelDims.Width + d2target.HeaderPadding
rowsWidth := d2target.NamePadding + maxNameWidth + d2target.TypePadding + maxTypeWidth + d2target.TypePadding + constraintWidth
dims.Width = go2.Max(headerWidth, rowsWidth)
}

return &dims, nil
Expand Down
4 changes: 2 additions & 2 deletions d2renderers/d2svg/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func tableHeader(shape d2target.Shape, box *geo.Box, text string, textWidth, tex
if text != "" {
tl := label.InsideMiddleLeft.GetPointOnBox(
box,
20,
textWidth,
float64(d2target.HeaderPadding),
float64(shape.Width),
textHeight,
)

Expand Down
5 changes: 3 additions & 2 deletions d2target/sqltable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package d2target
import "oss.terrastruct.com/d2/d2renderers/d2fonts"

const (
NamePadding = 10
TypePadding = 20
NamePadding = 10
TypePadding = 20
HeaderPadding = 20
)

type SQLTable struct {
Expand Down
20 changes: 20 additions & 0 deletions e2etests/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,26 @@ ico: {
label: ""
icon: https://icons.terrastruct.com/infra/019-network.svg
}
`,
},
{
name: "only_header_class_table",
script: `

class: RefreshAuthorizationPolicyProtocolServerSideTranslatorProtocolBuffer {
shape: class
}

table: RefreshAuthorizationPolicyCache {
shape: sql_table
}

table with short col: RefreshAuthorizationPolicyCache {
shape: sql_table
ok
}

class -> table -> table with short col
`,
},
}
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.
Loading