Skip to content

Commit

Permalink
✨ (scatter) add unit to axis labels
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Dec 18, 2024
1 parent c2f609e commit 1bb8883
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 6 additions & 0 deletions packages/@ourworldindata/core-table/src/CoreTableColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ export abstract class AbstractCoreColumn<JS_TYPE extends PrimitiveType> {
return undefined
}

@imemo get displayUnit(): string | undefined {
return this.unit && this.unit !== this.shortUnit
? this.unit.replace(/^\((.*)\)$/, "$1")
: undefined
}

// Returns a map where the key is a series slug such as "name" and the value is a set
// of all the unique values that this column has for that particular series.
getUniqueValuesGroupedBy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,10 @@ export class ScatterPlotChart
const axis = axisConfig.toVerticalAxis()
axis.formatColumn = this.yColumn
axis.scaleType = this.yScaleType
axis.label = this.currentVerticalAxisLabel

let label = this.currentVerticalAxisLabel
if (this.yColumn.displayUnit) label += ` (${this.yColumn.displayUnit})`
axis.label = label

if (
this.manager.isSingleTimeScatterAnimationActive &&
Expand Down Expand Up @@ -1345,8 +1348,12 @@ export class ScatterPlotChart
axis.formatColumn = this.xColumn
axis.scaleType = this.xScaleType

if (this.currentHorizontalAxisLabel)
axis.label = this.currentHorizontalAxisLabel
if (this.currentHorizontalAxisLabel) {
let label = this.currentHorizontalAxisLabel
if (this.xColumn.displayUnit)
label += ` (${this.xColumn.displayUnit})`
axis.label = label
}

if (
this.manager.isSingleTimeScatterAnimationActive &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ class Variable extends React.Component<{

if (column.isMissing || column.name === "time") return null

const { unit, shortUnit, displayName } = column,
displayUnit =
unit && unit !== shortUnit
? unit.replace(/^\((.*)\)$/, "$1")
: undefined,
const { displayUnit, displayName } = column,
displayNotice =
uniq((notice ?? []).filter((t) => t !== undefined))
.map((time) =>
Expand Down

0 comments on commit 1bb8883

Please sign in to comment.