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

code shape: apply font-size to render #1614

Merged
merged 5 commits into from
Sep 25, 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
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
- Fixes error with an empty nested grid [#1594](https://github.com/terrastruct/d2/issues/1594)
- Fixes incorrect `d2fmt` with variable substitution mid-string [#1611](https://github.com/terrastruct/d2/issues/1611)
- Fixes dagre error with child named id [#1610](https://github.com/terrastruct/d2/issues/1610)
- Fixes font-size missing from rendered code shape [#1614](https://github.com/terrastruct/d2/issues/1614)
8 changes: 7 additions & 1 deletion d2renderers/d2svg/d2svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,13 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
if !isLight {
class = "dark-code"
}
fmt.Fprintf(writer, `<g transform="translate(%f %f)" class="%s">`, box.TopLeft.X, box.TopLeft.Y, class)
var fontSize string
if targetShape.FontSize != d2fonts.FONT_SIZE_M {
fontSize = fmt.Sprintf(` style="font-size:%v"`, targetShape.FontSize)
}
fmt.Fprintf(writer, `<g transform="translate(%f %f)" class="%s"%s>`,
box.TopLeft.X, box.TopLeft.Y, class, fontSize,
)
rectEl := d2themes.NewThemableElement("rect")
rectEl.Width = float64(targetShape.Width)
rectEl.Height = float64(targetShape.Height)
Expand Down
1 change: 1 addition & 0 deletions e2etests/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ cf many required: {
loadFromFile(t, "arrowhead_font_color"),
loadFromFile(t, "multiple_constant_nears"),
loadFromFile(t, "empty_nested_grid"),
loadFromFile(t, "code_font_size"),
}

runa(t, tcs)
Expand Down
25 changes: 25 additions & 0 deletions e2etests/testdata/files/code_font_size.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'Data' -- y
x -- 'Data'
'Data': {
style.fill: "#c8e9ad"
style.stroke: "#c8e9ad"
style.stroke-width: 15
ex: |go
Testing 001: AAA
Testing 002: BBB
Testing 003: CCC
Testing 004: DDD
Testing 005: EEE
Testing 006: FFF
Testing 007: GGG
Testing 008: HHH
Testing 009: III
Testing 010: JJJ
Testing 011: KKK
Testing 012: LLL
Testing 013: MMM
Testing 014: NNN
Testing 015: OOO
|
ex.style.font-size: 10
}
306 changes: 306 additions & 0 deletions e2etests/testdata/regression/code_font_size/dagre/board.exp.json

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

Loading