From 994659ebd315f2c104133716408909f57c22e110 Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Tue, 17 Oct 2023 16:40:22 +0000 Subject: [PATCH] enhance(grapher): only run transforms for tableForSelection if necessary --- .../src/barCharts/DiscreteBarChart.tsx | 10 ++++++---- .../grapher/src/lineCharts/LineChart.tsx | 8 ++++++-- .../stackedCharts/AbstractStackedChart.tsx | 20 ++++++++++--------- .../stackedCharts/StackedDiscreteBarChart.tsx | 16 ++++++++------- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/barCharts/DiscreteBarChart.tsx b/packages/@ourworldindata/grapher/src/barCharts/DiscreteBarChart.tsx index fd3183fde78..2d988183e24 100644 --- a/packages/@ourworldindata/grapher/src/barCharts/DiscreteBarChart.tsx +++ b/packages/@ourworldindata/grapher/src/barCharts/DiscreteBarChart.tsx @@ -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() diff --git a/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx b/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx index 92b61700f68..1ac1822e4d5 100644 --- a/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx +++ b/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx @@ -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() diff --git a/packages/@ourworldindata/grapher/src/stackedCharts/AbstractStackedChart.tsx b/packages/@ourworldindata/grapher/src/stackedCharts/AbstractStackedChart.tsx index cfc48a56257..dc82f986683 100644 --- a/packages/@ourworldindata/grapher/src/stackedCharts/AbstractStackedChart.tsx +++ b/packages/@ourworldindata/grapher/src/stackedCharts/AbstractStackedChart.tsx @@ -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) => diff --git a/packages/@ourworldindata/grapher/src/stackedCharts/StackedDiscreteBarChart.tsx b/packages/@ourworldindata/grapher/src/stackedCharts/StackedDiscreteBarChart.tsx index 04e97827615..9bb0fa21af9 100644 --- a/packages/@ourworldindata/grapher/src/stackedCharts/StackedDiscreteBarChart.tsx +++ b/packages/@ourworldindata/grapher/src/stackedCharts/StackedDiscreteBarChart.tsx @@ -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()