Skip to content

Commit

Permalink
✨ (grapher) update font sizes of exports
Browse files Browse the repository at this point in the history
For better consisten with static charts created in Figma
  • Loading branch information
sophiamersmann committed Jan 9, 2025
1 parent a017567 commit bbf29a9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 39 deletions.
2 changes: 1 addition & 1 deletion packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3124,7 +3124,7 @@ export class Grapher
if (this.isStaticAndSmall) {
return this.computeBaseFontSizeFromHeight(this.staticBounds)
}
if (this.isStatic) return 18
if (this.isStatic) return 16
return this._baseFontSize
}

Expand Down
34 changes: 4 additions & 30 deletions packages/@ourworldindata/grapher/src/footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -688,36 +688,10 @@ export class StaticFooter extends Footer<StaticFooterProps> {
}

@computed protected get fontSize(): number {
if (this.useBaseFontSize) {
let fontSize = (12 / BASE_FONT_SIZE) * this.baseFontSize

// for small charts, reduce the font size if the footer text is long
if (this.manager.isStaticAndSmall) {
const sources = new MarkdownTextWrap({
text: this.sourcesText,
maxWidth: this.sourcesMaxWidth,
lineHeight: this.lineHeight,
fontSize,
})
const note = new MarkdownTextWrap({
text: this.markdownNoteText,
maxWidth: this.noteMaxWidth,
lineHeight: this.lineHeight,
fontSize,
})

const lineCount =
sources.svgLines.length +
(this.showNote ? note.svgLines.length : 0)
if (lineCount > 2) {
fontSize = (10 / BASE_FONT_SIZE) * this.baseFontSize
}
}

return fontSize
}

return 13
if (this.manager.isStaticAndSmall) return 14
return this.useBaseFontSize
? (13 / BASE_FONT_SIZE) * this.baseFontSize
: 13
}

@computed protected get sourcesFontSize(): number {
Expand Down
19 changes: 11 additions & 8 deletions packages/@ourworldindata/grapher/src/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ export class Header<
fontSize,
})

const initialFontSize = this.useBaseFontSize
? (22 / BASE_FONT_SIZE) * this.baseFontSize
: this.manager.isNarrow
? 18
: this.manager.isMedium
? 20
: 24
const initialFontSize = this.manager.isStaticAndSmall
? 25
: this.useBaseFontSize
? (25 / BASE_FONT_SIZE) * this.baseFontSize
: this.manager.isNarrow
? 18
: this.manager.isMedium
? 20
: 24

let title = makeTitle(initialFontSize)

Expand Down Expand Up @@ -178,8 +180,9 @@ export class Header<
}

@computed get subtitleFontSize(): number {
if (this.manager.isStaticAndSmall) return 16
if (this.useBaseFontSize) {
return (13 / BASE_FONT_SIZE) * this.baseFontSize
return (15 / BASE_FONT_SIZE) * this.baseFontSize
}
return this.manager.isSmall ? 12 : this.manager.isMedium ? 13 : 14
}
Expand Down

0 comments on commit bbf29a9

Please sign in to comment.