Skip to content

Commit

Permalink
🐛 (scatter/marimekko) apply color/size tolerance early
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Dec 17, 2024
1 parent 2c1bc83 commit fd03b51
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
32 changes: 31 additions & 1 deletion packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,39 @@ export class Grapher
return table
}

// TODO: needs a better name (or no name at all)
@computed get tableAfterColorAndSizeToleranceApplied(): OwidTable {
let table = this.inputTable

if (this.isScatter || this.isMarimekko) {
if (this.sizeColumnSlug) {
const tolerance =
table.get(this.sizeColumnSlug)?.display?.tolerance ??
Infinity
table = table.interpolateColumnWithTolerance(
this.sizeColumnSlug,
tolerance
)
}

if (this.colorColumnSlug) {
const tolerance =
table.get(this.colorColumnSlug)?.display?.tolerance ??
Infinity
table = table.interpolateColumnWithTolerance(
this.colorColumnSlug,
tolerance
)
}
}

return table
}

// If an author sets a timeline filter run it early in the pipeline so to the charts it's as if the filtered times do not exist
@computed get tableAfterAuthorTimelineFilter(): OwidTable {
const table = this.inputTable
const table = this.tableAfterColorAndSizeToleranceApplied

if (
this.timelineMinTime === undefined &&
this.timelineMaxTime === undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,28 +171,8 @@ export class ScatterPlotChart
if (this.yScaleType === ScaleType.log && this.yColumnSlug)
table = table.replaceNonPositiveCellsForLogScale([this.yColumnSlug])

if (this.sizeColumnSlug) {
const tolerance =
table.get(this.sizeColumnSlug)?.display?.tolerance ?? Infinity
table = table.interpolateColumnWithTolerance(
this.sizeColumnSlug,
tolerance
)
}

if (this.colorColumnSlug) {
const tolerance =
table.get(this.colorColumnSlug)?.display?.tolerance ?? Infinity
table = table.interpolateColumnWithTolerance(
this.colorColumnSlug,
tolerance
)
if (this.manager.matchingEntitiesOnly) {
table = table.dropRowsWithErrorValuesForColumn(
this.colorColumnSlug
)
}
}
if (this.colorColumnSlug && this.manager.matchingEntitiesOnly)
table = table.dropRowsWithErrorValuesForColumn(this.colorColumnSlug)

// We want to "chop off" any rows outside the time domain for X and Y to avoid creating
// leading and trailing timeline times that don't really exist in the dataset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,9 @@ export class MarimekkoChart
if (xColumnSlug)
table = table.interpolateColumnWithTolerance(xColumnSlug)

if (colorColumnSlug) {
const tolerance =
table.get(colorColumnSlug)?.display?.tolerance ?? Infinity
table = table.interpolateColumnWithTolerance(
colorColumnSlug,
tolerance
)
if (manager.matchingEntitiesOnly) {
table = table.dropRowsWithErrorValuesForColumn(colorColumnSlug)
}
}
if (colorColumnSlug && manager.matchingEntitiesOnly)
table = table.dropRowsWithErrorValuesForColumn(colorColumnSlug)

if (!manager.showNoDataArea)
table = table.dropRowsWithErrorValuesForAllColumns(yColumnSlugs)

Expand Down

0 comments on commit fd03b51

Please sign in to comment.