Skip to content

Commit

Permalink
Merge pull request #2071 from alixander/fix-theme-flag
Browse files Browse the repository at this point in the history
d2cli: fix theme passing to gif, fix scale on animated svg
  • Loading branch information
alixander authored Aug 25, 2024
2 parents 105e525 + 569da7b commit 9cc7a04
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
2 changes: 2 additions & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
- Vars: Spread variables are inserted in place instead of appending to end of scope [#2062](https://github.com/terrastruct/d2/pull/2062)
- Imports: fix local icon imports from files that are imported [#2066](https://github.com/terrastruct/d2/pull/2066)
- CLI: fixes edge case of watch mode links to nested board that had more nested boards not working [#2070](https://github.com/terrastruct/d2/pull/2070)
- CLI: fixes theme flag not being passed to GIF outputs [#2071](https://github.com/terrastruct/d2/pull/2071)
- CLI: fixes scale flag not being passed to animated SVG outputs [#2071](https://github.com/terrastruct/d2/pull/2071)
2 changes: 1 addition & 1 deletion ci/release/template/man/d2.1
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Path to .ttf file to use for the bold font. If none provided, Source Sans Pro Bo
Pixels padded around the rendered diagram
.Ns .
.It Fl -animate-interval Ar 0
If given, multiple boards are packaged as 1 SVG which transitions through each board at the interval (in milliseconds). Can only be used with SVG exports
If given, multiple boards are packaged as 1 SVG which transitions through each board at the interval (in milliseconds). Can only be used with SVG and GIF exports
.Ns .
.It Fl -browser Ar true
Browser executable that watch opens. Setting to 0 opens no browser
Expand Down
27 changes: 17 additions & 10 deletions d2cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,9 @@ func _render(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, opts
Pad: opts.Pad,
Sketch: opts.Sketch,
Center: opts.Center,
MasterID: opts.MasterID,
ThemeID: opts.ThemeID,
DarkThemeID: opts.DarkThemeID,
MasterID: opts.MasterID,
ThemeOverrides: opts.ThemeOverrides,
DarkThemeOverrides: opts.DarkThemeOverrides,
Scale: scale,
Expand Down Expand Up @@ -936,11 +936,14 @@ func renderPDF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, opt
}

svg, err = d2svg.Render(diagram, &d2svg.RenderOpts{
Pad: opts.Pad,
Sketch: opts.Sketch,
Center: opts.Center,
Scale: scale,
ThemeID: opts.ThemeID,
Pad: opts.Pad,
Sketch: opts.Sketch,
Center: opts.Center,
Scale: scale,
ThemeID: opts.ThemeID,
DarkThemeID: opts.DarkThemeID,
ThemeOverrides: opts.ThemeOverrides,
DarkThemeOverrides: opts.DarkThemeOverrides,
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -1286,10 +1289,14 @@ func renderPNGsForGIF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plug
scale = go2.Pointer(1.)
}
svg, err = d2svg.Render(diagram, &d2svg.RenderOpts{
Pad: opts.Pad,
Sketch: opts.Sketch,
Center: opts.Center,
Scale: scale,
Pad: opts.Pad,
Sketch: opts.Sketch,
Center: opts.Center,
Scale: scale,
ThemeID: opts.ThemeID,
DarkThemeID: opts.DarkThemeID,
ThemeOverrides: opts.ThemeOverrides,
DarkThemeOverrides: opts.DarkThemeOverrides,
})
if err != nil {
return nil, nil, err
Expand Down
12 changes: 10 additions & 2 deletions d2renderers/d2animate/d2animate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,17 @@ func Wrap(rootDiagram *d2target.Diagram, svgs [][]byte, renderOpts d2svg.RenderO
width := br.X - tl.X + int(*renderOpts.Pad)*2
height := br.Y - tl.Y + int(*renderOpts.Pad)*2

fitToScreenWrapperOpening := fmt.Sprintf(`<?xml version="1.0" encoding="utf-8"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" d2Version="%s" preserveAspectRatio="xMinYMin meet" viewBox="0 0 %d %d">`,
var dimensions string
if renderOpts.Scale != nil {
dimensions = fmt.Sprintf(` width="%d" height="%d"`,
int(math.Ceil((*renderOpts.Scale)*float64(width))),
int(math.Ceil((*renderOpts.Scale)*float64(height))),
)
}

fitToScreenWrapperOpening := fmt.Sprintf(`<?xml version="1.0" encoding="utf-8"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" d2Version="%s" preserveAspectRatio="xMinYMin meet" viewBox="0 0 %d %d"%s>`,
version.Version,
width, height,
width, height, dimensions,
)
fmt.Fprint(buf, fitToScreenWrapperOpening)

Expand Down

0 comments on commit 9cc7a04

Please sign in to comment.