Skip to content

Commit

Permalink
🐛 (download) fix mobx issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Dec 1, 2023
1 parent 147fb0b commit 167d121
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
8 changes: 8 additions & 0 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,14 @@ export class Grapher
return this.generateStaticSvg()
}

get staticSVGLandscape(): string {
return this.staticSVG
}

get staticSVGPortrait(): string {
return this.generateStaticSvg(this.portraitBounds)
}

@computed get disableIntroAnimation(): boolean {
return this.isExportingToSvgOrPng
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ it("correctly passes non-redistributable flag", () => {
const tableFalse = getTable({ nonRedistributable: false })
const viewFalse = new DownloadModal({
manager: {
generateStaticSvg: () => "",
staticSVGLandscape: "",
staticSVGPortrait: "",
displaySlug: "",
table: tableFalse,
detailRenderers: [],
Expand All @@ -44,7 +45,8 @@ it("correctly passes non-redistributable flag", () => {
const tableTrue = getTable({ nonRedistributable: true })
const viewTrue = new DownloadModal({
manager: {
generateStaticSvg: () => "",
staticSVGLandscape: "",
staticSVGPortrait: "",
displaySlug: "",
table: tableTrue,
detailRenderers: [],
Expand Down
13 changes: 7 additions & 6 deletions packages/@ourworldindata/grapher/src/modal/DownloadModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import { StaticChartRasterizer } from "../captionedChart/StaticChartRasterizer"

export interface DownloadModalManager {
displaySlug: string
generateStaticSvg: (bounds?: Bounds) => string
staticSVGLandscape: string
staticSVGPortrait: string
staticBounds?: Bounds
baseUrl?: string
queryStr?: string
Expand Down Expand Up @@ -100,10 +101,6 @@ export class DownloadModal extends React.Component<DownloadModalProps> {
return this.staticBounds.height
}

@computed private get staticSVG(): string {
return this.manager.generateStaticSvg(this.staticBounds)
}

@computed private get manager(): DownloadModalManager {
return this.props.manager
}
Expand All @@ -117,7 +114,11 @@ export class DownloadModal extends React.Component<DownloadModalProps> {
@observable private isReady: boolean = false

@action.bound private export(): void {
const { staticSVG, targetWidth, targetHeight } = this
const { targetWidth, targetHeight } = this

const staticSVG = this.isExportingPortrait
? this.manager.staticSVGPortrait
: this.manager.staticSVGLandscape

// render the graphic then cache data-urls for display & blobs for downloads
new StaticChartRasterizer(staticSVG, targetWidth, targetHeight)
Expand Down

0 comments on commit 167d121

Please sign in to comment.