Skip to content

Commit

Permalink
enhance(grapher): only run transforms for tableForSelection if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Oct 17, 2023
1 parent 8845200 commit 994659e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ export class DiscreteBarChart
}

transformTableForSelection(table: OwidTable): OwidTable {
table = table
.replaceNonNumericCellsWithErrorValues(this.yColumnSlugs)
.dropRowsWithErrorValuesForAllColumns(this.yColumnSlugs)

// if entities with partial data are not plotted,
// make sure they don't show up in the entity selector
if (this.missingDataStrategy === MissingDataStrategy.hide) {
table = table
.replaceNonNumericCellsWithErrorValues(this.yColumnSlugs)
.dropRowsWithErrorValuesForAllColumns(this.yColumnSlugs)

const groupedByEntity = table.groupBy("entityName").map((t) => {
if (t.hasAnyColumnNoValidValue(this.yColumnSlugs)) {
t = t.dropAllRows()
Expand Down
8 changes: 6 additions & 2 deletions packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,13 @@ export class LineChart
}

transformTableForSelection(table: OwidTable): OwidTable {
table = table.replaceNonNumericCellsWithErrorValues(this.yColumnSlugs)

// if entities with partial data are not plotted,
// make sure they don't show up in the entity selector
if (this.missingDataStrategy === MissingDataStrategy.hide) {
table = table.replaceNonNumericCellsWithErrorValues(
this.yColumnSlugs
)

const groupedByEntity = table.groupBy("entityName").map((t) => {
if (t.hasAnyColumnNoValidValue(this.yColumnSlugs)) {
t = t.dropAllRows()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,19 @@ export class AbstractStackedChart
}

transformTableForSelection(table: OwidTable): OwidTable {
table = table
.replaceNonNumericCellsWithErrorValues(this.yColumnSlugs)
.dropRowsWithErrorValuesForAllColumns(this.yColumnSlugs)
// if entities with partial data are not plotted,
// make sure they don't show up in the entity selector
if (this.missingDataStrategy !== MissingDataStrategy.show) {
table = table
.replaceNonNumericCellsWithErrorValues(this.yColumnSlugs)
.dropRowsWithErrorValuesForAllColumns(this.yColumnSlugs)

if (this.shouldRunLinearInterpolation) {
this.yColumnSlugs.forEach((slug) => {
table = table.interpolateColumnLinearly(slug)
})
}
if (this.shouldRunLinearInterpolation) {
this.yColumnSlugs.forEach((slug) => {
table = table.interpolateColumnLinearly(slug)
})
}

if (this.missingDataStrategy !== MissingDataStrategy.show) {
const groupedByEntity = table
.groupBy("entityName")
.map((t: OwidTable) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,17 @@ export class StackedDiscreteBarChart
}

transformTableForSelection(table: OwidTable): OwidTable {
table = table
.replaceNonNumericCellsWithErrorValues(this.yColumnSlugs)
.dropRowsWithErrorValuesForAllColumns(this.yColumnSlugs)
// if entities with partial data are not plotted,
// make sure they don't show up in the entity selector
if (this.missingDataStrategy === MissingDataStrategy.hide) {
table = table
.replaceNonNumericCellsWithErrorValues(this.yColumnSlugs)
.dropRowsWithErrorValuesForAllColumns(this.yColumnSlugs)

this.yColumnSlugs.forEach((slug) => {
table = table.interpolateColumnWithTolerance(slug)
})
this.yColumnSlugs.forEach((slug) => {
table = table.interpolateColumnWithTolerance(slug)
})

if (this.missingDataStrategy === MissingDataStrategy.hide) {
const groupedByEntity = table.groupBy("entityName").map((t) => {
if (t.hasAnyColumnNoValidValue(this.yColumnSlugs)) {
t = t.dropAllRows()
Expand Down

0 comments on commit 994659e

Please sign in to comment.