Skip to content

Commit

Permalink
✨ add unit to axis labels
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Jan 13, 2025
1 parent acaf2d6 commit c3c7f1a
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions packages/@ourworldindata/grapher/src/axis/Axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,31 @@ abstract class AbstractAxis {
}

@computed get labelTextWrap(): MarkdownTextWrap | undefined {
const text = this.label
return text
? new MarkdownTextWrap({
maxWidth: this.labelMaxWidth,
fontSize: this.labelFontSize,
text,
lineHeight: 1,
detailsOrderedByReference:
this.axisManager?.detailsOrderedByReference,
})
: undefined
if (!this.label) return

const textWrapProps = {
maxWidth: this.labelMaxWidth,
fontSize: this.labelFontSize,
lineHeight: 1,
detailsOrderedByReference:
this.axisManager?.detailsOrderedByReference,
}

const displayUnit = this.formatColumn?.displayUnit
if (displayUnit) {
return MarkdownTextWrap.fromFragments({
main: { text: this.label, bold: true },
secondary: { text: `(${displayUnit})` },
newLine: "avoid-wrap",
textWrapProps,
})
} else {
return new MarkdownTextWrap({
text: this.label,
fontWeight: 700,
...textWrapProps,
})
}
}

@computed get labelHeight(): number {
Expand Down

0 comments on commit c3c7f1a

Please sign in to comment.