Skip to content

Commit

Permalink
Merge pull request #2859 from owid/fix-data-table-tolerance
Browse files Browse the repository at this point in the history
fix(data-table): respect tolerance
  • Loading branch information
sophiamersmann authored Oct 26, 2023
2 parents b528c1c + e3dc1a3 commit b824180
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import {
upperFirst,
valuesByEntityAtTimes,
es6mapValues,
valuesByEntityWithinTimes,
getStartEndValues,
sortBy,
countBy,
union,
Expand Down Expand Up @@ -675,7 +673,6 @@ export class DataTable extends React.Component<{
: TargetTimeMode.range

const prelimValuesByEntity = this.preliminaryDimensionValues(
targetTimeMode,
sourceColumn,
targetTimes
)
Expand Down Expand Up @@ -728,27 +725,14 @@ export class DataTable extends React.Component<{
}

private preliminaryDimensionValues(
targetTimeMode: TargetTimeMode,
sourceColumn: CoreColumn,
targetTimes: number[]
): Map<string, (DataValue | undefined)[]> {
return targetTimeMode === TargetTimeMode.range
? // In the "range" mode, we receive all data values within the range. But we

// only want to plot the start & end values in the table.
// getStartEndValues() extracts these two values.
es6mapValues(
valuesByEntityWithinTimes(
sourceColumn.valueByEntityNameAndOriginalTime,
targetTimes
),
getStartEndValues
)
: valuesByEntityAtTimes(
sourceColumn.valueByEntityNameAndOriginalTime,
targetTimes,
sourceColumn.tolerance
)
return valuesByEntityAtTimes(
sourceColumn.valueByEntityNameAndOriginalTime,
targetTimes,
sourceColumn.tolerance
)
}

private dataValuesFromPreliminaryValues(
Expand Down Expand Up @@ -784,7 +768,11 @@ export class DataTable extends React.Component<{
start !== undefined &&
end !== undefined &&
typeof start.value === "number" &&
typeof end.value === "number"
typeof end.value === "number" &&
// sanity check: start time should always be <= end time
start.time !== undefined &&
end.time !== undefined &&
start.time <= end.time
) {
const deltaValue = end.value - start.value
const deltaRatioValue = deltaValue / Math.abs(start.value)
Expand Down

0 comments on commit b824180

Please sign in to comment.