Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 (data table) small improvements #3888

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/@ourworldindata/core-table/src/CoreTableColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ export abstract class AbstractCoreColumn<JS_TYPE extends PrimitiveType> {
}

@imemo get unit(): string | undefined {
return this.display?.unit ?? this.def.unit
const unit = this.display?.unit ?? this.def.unit
return unit?.trim()
}

@imemo get shortUnit(): string | undefined {
Expand Down
19 changes: 11 additions & 8 deletions packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -789,15 +789,18 @@ export class DataTable extends React.Component<{
targetTimes: number[]
targetTimeMode: TargetTimeMode
}): DimensionColumn[] {
// Inject delta columns if we have start & end values to compare in the table.
// One column for absolute difference, another for % difference.
// Inject delta columns if the data is numerical and we have start & end
// values to compare in the table. One column for absolute difference,
// another for % difference.
const deltaColumns: DimensionColumn[] = []
if (targetTimeMode === TargetTimeMode.range) {
const { tableDisplay = {} } = sourceColumn.display ?? {}
if (!tableDisplay.hideAbsoluteChange)
deltaColumns.push({ key: RangeValueKey.delta })
if (!tableDisplay.hideRelativeChange)
deltaColumns.push({ key: RangeValueKey.deltaRatio })
if (sourceColumn.hasNumberFormatting) {
if (targetTimeMode === TargetTimeMode.range) {
const { tableDisplay = {} } = sourceColumn.display ?? {}
if (!tableDisplay.hideAbsoluteChange)
deltaColumns.push({ key: RangeValueKey.delta })
if (!tableDisplay.hideRelativeChange)
deltaColumns.push({ key: RangeValueKey.deltaRatio })
}
}

const valueColumns = targetTimes.map((targetTime, index) => ({
Expand Down