Skip to content

Commit

Permalink
enhance(data-table): hide entities not displayed in a scatter plot
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Oct 10, 2023
1 parent 356ad1d commit bf6a0e2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface ChartInterface {
// Todo: should all charts additionally have a placedSeries: ChartPlacedSeries[] getter?

transformTable: ChartTableTransformer
transformTableForDisplay?: ChartTableTransformer

yAxis?: HorizontalAxis | VerticalAxis
xAxis?: HorizontalAxis | VerticalAxis
Expand Down
9 changes: 9 additions & 0 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,15 @@ export class Grapher
return this.xAxis.toObject()
}

// table that is used for display in the table tab
@computed get tableForDisplay(): OwidTable {
const table = this.table
if (!this.isReady || !this.isOnTableTab) return table
return this.chartInstance.transformTableForDisplay
? this.chartInstance.transformTableForDisplay(table)
: table
}

@computed get tableForSelection(): OwidTable {
// This table specifies which entities can be selected in the charts EntitySelectorModal.
// It should contain all entities that can be selected, and none more.
Expand Down
6 changes: 4 additions & 2 deletions packages/@ourworldindata/grapher/src/dataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ const inverseSortOrder = (order: SortOrder): SortOrder =>
order === SortOrder.asc ? SortOrder.desc : SortOrder.asc

export interface DataTableManager {
table: OwidTable
table: OwidTable // not used here, but required in type `ChartManager`
tableForDisplay: OwidTable
entityType?: string
endTime?: Time
startTime?: Time
Expand Down Expand Up @@ -131,7 +132,7 @@ export class DataTable extends React.Component<{
}

@computed get table(): OwidTable {
let table = this.manager.table
let table = this.manager.tableForDisplay
if (this.manager.showSelectionOnlyInDataTable) {
table = table.filterByEntityNames(
this.selectionArray.selectedEntityNames
Expand All @@ -144,6 +145,7 @@ export class DataTable extends React.Component<{
return (
this.props.manager ?? {
table: BlankOwidTable(),
tableForDisplay: BlankOwidTable(),
entityType: DEFAULT_GRAPHER_ENTITY_TYPE,
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,22 @@ export class ScatterPlotChart
return table
}

transformTableForDisplay(table: OwidTable): OwidTable {
// Drop any rows which have non-number values for X or Y.
table = table
.columnFilter(
this.xColumnSlug,
isNumber,
"Drop rows with non-number values in X column"
)
.columnFilter(
this.yColumnSlug,
isNumber,
"Drop rows with non-number values in Y column"
)
return table
}

@computed get inputTable(): OwidTable {
return this.manager.table
}
Expand Down

0 comments on commit bf6a0e2

Please sign in to comment.