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

fix(data-table): respect tolerance #2859

Merged
merged 4 commits into from
Oct 26, 2023
Merged
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
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arguably, this could also be <

) {
const deltaValue = end.value - start.value
const deltaRatioValue = deltaValue / Math.abs(start.value)
Expand Down
Loading