From 211ccdfdcd9fcf3ab79511a9322c55461845144d Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Thu, 29 Oct 2026 14:44:28 -0700 Subject: [PATCH 01/17] fix: Fix types, renamed setFilteredValues to clarify its function --- src/containers/ColorByMenu/index.tsx | 14 ++++++++------ src/state/selection/actions.ts | 7 ++++--- src/state/selection/constants.ts | 4 +--- src/state/selection/reducer.ts | 11 ++++++----- src/state/selection/types.ts | 6 ++++++ 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/containers/ColorByMenu/index.tsx b/src/containers/ColorByMenu/index.tsx index d699b9549..aac55de68 100644 --- a/src/containers/ColorByMenu/index.tsx +++ b/src/containers/ColorByMenu/index.tsx @@ -22,8 +22,8 @@ import { getFeatureDefTooltip, getDownloadRoot } from "../../state/selection/sel import { BoolToggleAction, ChangeDownloadConfigAction, + ChangeFilterSelectionAction, ChangeGroupByCategory, - ChangeSelectionAction, ColorForPlot, DeselectGroupOfPointsAction, DownloadConfig, @@ -74,7 +74,7 @@ interface DispatchProps { handleChangeAxis: ActionCreator; handleChangeGroupByCategory: ActionCreator; handleCloseSelectionSet: ActionCreator; - handleFilterByCategoryName: ActionCreator; + handleSetFilteredValues: ActionCreator; handleChangeDownloadSettings: ActionCreator; handleSetColorOverride: ActionCreator; } @@ -108,8 +108,9 @@ class ColorByMenu extends React.Component { } public onBarClicked({ target }: CheckboxChangeEvent) { - const { handleFilterByCategoryName, filtersToExclude } = this.props; - const newFilterList = includes(filtersToExclude, target.value) + const { handleSetFilteredValues: handleFilterByCategoryName, filtersToExclude } = + this.props; + const newFilterList: string[] = includes(filtersToExclude, target.value) ? filter(filtersToExclude, (e) => e !== target.value) : [...filtersToExclude, target.value]; handleFilterByCategoryName(newFilterList); @@ -132,7 +133,8 @@ class ColorByMenu extends React.Component { } public allOnOff({ target }: CheckboxChangeEvent) { - const { handleFilterByCategoryName, interactivePanelData } = this.props; + const { handleSetFilteredValues: handleFilterByCategoryName, interactivePanelData } = + this.props; if (target.checked) { return handleFilterByCategoryName([]); } @@ -367,7 +369,7 @@ const dispatchToPropsMap: DispatchProps = { handleChangeGroupByCategory: selectionStateBranch.actions.changeGroupByCategory, handleChangeDownloadSettings: selectionStateBranch.actions.changeDownloadSettings, handleCloseSelectionSet: selectionStateBranch.actions.deselectGroupOfPoints, - handleFilterByCategoryName: selectionStateBranch.actions.toggleFilterByCategoryName, + handleSetFilteredValues: selectionStateBranch.actions.setFilteredValues, handleSetColorOverride: selectionStateBranch.actions.setColorOverride, }; export default connect( diff --git a/src/state/selection/actions.ts b/src/state/selection/actions.ts index 34a2616aa..a0a21aa5d 100755 --- a/src/state/selection/actions.ts +++ b/src/state/selection/actions.ts @@ -16,7 +16,7 @@ import { SET_MOUSE_POSITION, SYNC_STATE_WITH_URL, TOGGLE_APPLY_SELECTION_SET_COLOR, - TOGGLE_FILTER_BY_CATEGORY_NAME, + SET_FILTERED_VALUES, TOGGLE_GALLERY_OPEN_CLOSE, CHANGE_DATASET, RECEIVE_FILE_INFO, @@ -41,6 +41,7 @@ import { import { BoolToggleAction, ChangeDownloadConfigAction, + ChangeFilterSelectionAction, ChangeGroupByCategory, ChangeHoveredPointAction, ChangeMousePositionAction, @@ -204,10 +205,10 @@ export function setPointOpacity(payload: number): SetPointOpacityAction { }; } -export function toggleFilterByCategoryName(payload: string): ChangeSelectionAction { +export function setFilteredValues(payload: string[]): ChangeFilterSelectionAction { return { payload, - type: TOGGLE_FILTER_BY_CATEGORY_NAME, + type: SET_FILTERED_VALUES, }; } diff --git a/src/state/selection/constants.ts b/src/state/selection/constants.ts index 75347fc40..0118575ea 100755 --- a/src/state/selection/constants.ts +++ b/src/state/selection/constants.ts @@ -25,9 +25,7 @@ export const SET_COLOR_OVERRIDE = makeSelectionConstant("set-color-override"); export const SET_COLOR_OVERRIDES = makeSelectionConstant("set-color-overrides"); export const SET_POINT_RADIUS = makeSelectionConstant("set-point-radius"); export const SET_POINT_OPACITY = makeSelectionConstant("set-point-opacity"); -export const TOGGLE_FILTER_BY_CATEGORY_NAME = makeSelectionConstant( - "toggle-filter-by-category-name" -); +export const SET_FILTERED_VALUES = makeSelectionConstant("set-filtered-values"); export const OPEN_CELL_IN_3D = makeSelectionConstant("open-cell-in-3d"); export const TOGGLE_APPLY_SELECTION_SET_COLOR = makeSelectionConstant("apply-selection-set-color"); export const DESELECT_GROUP_OF_POINTS = makeSelectionConstant("deselect-group"); diff --git a/src/state/selection/reducer.ts b/src/state/selection/reducer.ts index d5dfa3b65..01382a23b 100755 --- a/src/state/selection/reducer.ts +++ b/src/state/selection/reducer.ts @@ -23,7 +23,7 @@ import { SET_DOWNLOAD_CONFIG, SET_MOUSE_POSITION, TOGGLE_APPLY_SELECTION_SET_COLOR, - TOGGLE_FILTER_BY_CATEGORY_NAME, + SET_FILTERED_VALUES, TOGGLE_GALLERY_OPEN_CLOSE, SET_DATASET, RECEIVE_FILE_INFO_FOR_ALBUM_CELLS, @@ -50,6 +50,7 @@ import { ChangeConnectByCategory, ChangeConnectByFeature, ChangeDownloadConfigAction, + ChangeFilterSelectionAction, ChangeGroupByCategory, ChangeHoveredPointAction, ChangeMousePositionAction, @@ -349,10 +350,10 @@ const actionToConfigMap: TypeToDescriptionMap = { colorOverrides: action.payload, }), }, - [TOGGLE_FILTER_BY_CATEGORY_NAME]: { - accepts: (action: Action): action is ChangeSelectionAction => - action.type === TOGGLE_FILTER_BY_CATEGORY_NAME, - perform: (state: SelectionStateBranch, action: ChangeSelectionAction) => ({ + [SET_FILTERED_VALUES]: { + accepts: (action: Action): action is ChangeFilterSelectionAction => + action.type === SET_FILTERED_VALUES, + perform: (state: SelectionStateBranch, action: ChangeFilterSelectionAction) => ({ ...state, filterExclude: action.payload, }), diff --git a/src/state/selection/types.ts b/src/state/selection/types.ts index e17d260cc..019b04c22 100755 --- a/src/state/selection/types.ts +++ b/src/state/selection/types.ts @@ -107,6 +107,12 @@ export interface ChangeSelectionAction { type: string; } +export interface ChangeFilterSelectionAction { + payload: string[]; + type: string; +} + + export interface ChangeDownloadConfigAction { payload: DownloadConfig; type: string; From 7e8a637735cc686551bbebf3daaf2e4fd7ce4e7e Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Thu, 29 Oct 2026 16:09:02 -0700 Subject: [PATCH 02/17] feat: Initial stored filter data --- src/containers/ColorByMenu/index.tsx | 61 ++++++++++++---- src/containers/ColorByMenu/selectors.ts | 26 ++++--- src/state/selection/actions.ts | 25 +++++++ src/state/selection/constants.ts | 2 + src/state/selection/reducer.ts | 47 ++++++++++++ src/state/selection/selectors.ts | 96 ++++++++++++++++++++++++- src/state/selection/types.ts | 36 ++++++++++ 7 files changed, 269 insertions(+), 24 deletions(-) diff --git a/src/containers/ColorByMenu/index.tsx b/src/containers/ColorByMenu/index.tsx index aac55de68..4a8f7d1a4 100644 --- a/src/containers/ColorByMenu/index.tsx +++ b/src/containers/ColorByMenu/index.tsx @@ -1,6 +1,6 @@ import { Checkbox, Col, Collapse, Row } from "antd"; import { CheckboxChangeEvent } from "antd/es/checkbox"; -import { filter, includes } from "lodash"; +import { filter, groupBy, includes } from "lodash"; import React from "react"; import { connect } from "react-redux"; import type { ActionCreator } from "redux"; @@ -26,9 +26,12 @@ import { ChangeGroupByCategory, ColorForPlot, DeselectGroupOfPointsAction, + DiscreteFilterData, DownloadConfig, + FilterData, SelectAxisAction, SetColorOverrideAction, + SetFilterByFeatureAction, } from "../../state/selection/types"; import { State } from "../../state/types"; import { getColorByDisplayOptions, getGroupByDisplayOptions } from "../MainPlotContainer/selectors"; @@ -58,6 +61,8 @@ interface PropsFromState { downloadConfig: DownloadConfig; downloadRoot: string; filtersToExclude: string[]; + filters: Map; + groupByFilter: DiscreteFilterData | undefined; interactivePanelData: PanelData[]; selectionSetsPanelData: PanelData[]; isInIndeterminateState: boolean; @@ -75,6 +80,7 @@ interface DispatchProps { handleChangeGroupByCategory: ActionCreator; handleCloseSelectionSet: ActionCreator; handleSetFilteredValues: ActionCreator; + handleSetFeatureFilter: ActionCreator; handleChangeDownloadSettings: ActionCreator; handleSetColorOverride: ActionCreator; } @@ -108,12 +114,28 @@ class ColorByMenu extends React.Component { } public onBarClicked({ target }: CheckboxChangeEvent) { - const { handleSetFilteredValues: handleFilterByCategoryName, filtersToExclude } = - this.props; - const newFilterList: string[] = includes(filtersToExclude, target.value) - ? filter(filtersToExclude, (e) => e !== target.value) - : [...filtersToExclude, target.value]; - handleFilterByCategoryName(newFilterList); + const { groupByFilter, groupBy, handleSetFeatureFilter } = this.props; + let filter = groupByFilter; + if (!filter) { + filter = { discrete: true, excluded: new Set() }; + } else { + filter = { ...filter, excluded: new Set(filter.excluded) }; + } + if (filter.discrete) { + if (target.checked) { + filter.excluded.delete(target.value); + } else { + filter.excluded.add(target.value); + } + } + console.log("Setting filter for groupBy:", groupByFilter, "with filter:", filter); + handleSetFeatureFilter(groupBy.toString(), filter); + // const { handleSetFilteredValues: handleFilterByCategoryName, filtersToExclude } = + // this.props; + // const newFilterList: string[] = includes(filtersToExclude, target.value) + // ? filter(filtersToExclude, (e) => e !== target.value) + // : [...filtersToExclude, target.value]; + // handleFilterByCategoryName(newFilterList); } public onCategorySetDownloadButtonClicked(categoryName: string) { @@ -133,13 +155,21 @@ class ColorByMenu extends React.Component { } public allOnOff({ target }: CheckboxChangeEvent) { - const { handleSetFilteredValues: handleFilterByCategoryName, interactivePanelData } = - this.props; - if (target.checked) { - return handleFilterByCategoryName([]); + const { groupByFilter, groupBy, handleSetFeatureFilter, interactivePanelData } = this.props; + let filter = groupByFilter; + if (!filter) { + filter = { discrete: true, excluded: new Set() }; + } + if (filter.discrete) { + filter = { ...filter, excluded: new Set(filter.excluded) }; + if (target.checked) { + filter.excluded.clear(); + } else { + const keys = interactivePanelData.map((ele: PanelData) => ele.id); + keys.forEach((key) => filter?.excluded.add(key)); + } } - const keys = interactivePanelData.map((ele: PanelData) => ele.id); - handleFilterByCategoryName(keys); + handleSetFeatureFilter(groupBy.toString(), filter); } public onActivePanelChange(value: string | string[]) { @@ -264,7 +294,7 @@ class ColorByMenu extends React.Component {
Show/Hide all @@ -356,6 +386,8 @@ function mapStateToProps(state: State): PropsFromState { downloadUrls: createUrlFromListOfIds(state), downloadRoot: getDownloadRoot(state), filtersToExclude: selectionStateBranch.selectors.getFiltersToExclude(state), + filters: selectionStateBranch.selectors.getFilters(state), + groupByFilter: selectionStateBranch.selectors.getGroupByFilter(state), groupByTitle: getGroupByTitle(state), interactivePanelData: getInteractivePanelData(state), selectionSetsPanelData: getSelectionPanelData(state), @@ -370,6 +402,7 @@ const dispatchToPropsMap: DispatchProps = { handleChangeDownloadSettings: selectionStateBranch.actions.changeDownloadSettings, handleCloseSelectionSet: selectionStateBranch.actions.deselectGroupOfPoints, handleSetFilteredValues: selectionStateBranch.actions.setFilteredValues, + handleSetFeatureFilter: selectionStateBranch.actions.setFeatureFilter, handleSetColorOverride: selectionStateBranch.actions.setColorOverride, }; export default connect( diff --git a/src/containers/ColorByMenu/selectors.ts b/src/containers/ColorByMenu/selectors.ts index 4bb0a6403..48d5af6be 100644 --- a/src/containers/ColorByMenu/selectors.ts +++ b/src/containers/ColorByMenu/selectors.ts @@ -37,8 +37,13 @@ import { getYValues, getXValues, getColorOverrides, + getGroupByFilter, } from "../../state/selection/selectors"; -import { ColorForPlot, LassoOrBoxSelectPointData } from "../../state/selection/types"; +import { + ColorForPlot, + DiscreteFilterData, + LassoOrBoxSelectPointData, +} from "../../state/selection/types"; import { convertSingleImageIdToDownloadId } from "../../state/util"; import { PanelData } from "./types"; @@ -65,9 +70,12 @@ export const getGroupByTitle = createSelector( ); export const getCheckAllCheckboxIsIntermediate = createSelector( - [getFiltersToExclude, getGroupingCategoryNames], - (filtersToExclude, categoryNames: string[]): boolean => { - return filtersToExclude.length > 0 && filtersToExclude.length !== categoryNames.length; + [getGroupByFilter, getGroupingCategoryNames], + (groupByFilter, categoryNames: string[]): boolean => { + const excluded = groupByFilter?.excluded; + return ( + excluded !== undefined && excluded.size > 0 && excluded.size !== categoryNames.length + ); } ); @@ -126,7 +134,7 @@ export const getInteractivePanelData = createSelector( getGroupByCategory, getColorBySelection, getGroupByFeatureOptionsAsList, - getFiltersToExclude, + getGroupByFilter, getDisplayableGroups, getGroupingCategoryNamesAsArray, getColorOverrides, @@ -135,7 +143,7 @@ export const getInteractivePanelData = createSelector( categoryToGroupBy: keyof MappingOfMeasuredValuesArrays, categoryToColorBy: keyof MappingOfMeasuredValuesArrays, categories: MeasuredFeaturesOption[], - filtersToExclude: string[], + groupByFilter: DiscreteFilterData | undefined, displayableGroups: string[], categoryNamesArray: string[], colorOverrides: (string | undefined)[] @@ -168,15 +176,17 @@ export const getInteractivePanelData = createSelector( const id = category.key ?? category.name; const total: number = countsByCategory[id] || category.count || 0; const disabled = !displayableGroups.includes(id); + const excluded = groupByFilter?.excluded.has(id) ?? false; + console.log("Groupbyfilter:", groupByFilter, "excluded: ", excluded); const color = getColorForCategory( categoryToColorBy === categoryToGroupBy, - includes(filtersToExclude, id), + excluded, disabled, category.color, colorOverrides[index] ); return { - checked: !includes(filtersToExclude, id), + checked: !excluded, color: color, id: id, name: names[index], diff --git a/src/state/selection/actions.ts b/src/state/selection/actions.ts index a0a21aa5d..bd1c95b26 100755 --- a/src/state/selection/actions.ts +++ b/src/state/selection/actions.ts @@ -37,6 +37,8 @@ import { SET_CONNECT_LINE_WIDTH, SET_CONNECT_LINE_DEFAULT_COLOR, SET_CONNECT_LINE_OPACITY, + SET_FILTER_ACTIVE, + SET_FEATURE_FILTER, } from "./constants"; import { BoolToggleAction, @@ -50,6 +52,7 @@ import { DeselectGroupOfPointsAction, DeselectPointAction, DownloadConfig, + FilterData, LassoOrBoxSelectAction, LassoOrBoxSelectPointData, MousePosition, @@ -63,6 +66,8 @@ import { SetColorOverrideAction, SetColorOverridesAction, SetCsvUrlAction, + SetFilterActiveAction, + SetFilterByFeatureAction, SetLineAverageWindowAction, SetLineDefaultColorAction, SetLineOpacityAction, @@ -212,6 +217,26 @@ export function setFilteredValues(payload: string[]): ChangeFilterSelectionActio }; } +export function setFeatureFilter( + feature: string, + filter: FilterData | null +): SetFilterByFeatureAction { + return { + payload: { feature, filter }, + type: SET_FEATURE_FILTER, + }; +} + +export function setFilterActive(payload: { + feature: string; + active: boolean; +}): SetFilterActiveAction { + return { + payload, + type: SET_FILTER_ACTIVE, + }; +} + export function selectCellFor3DViewer(payload: { id: string }): SelectPointAction { return { payload, diff --git a/src/state/selection/constants.ts b/src/state/selection/constants.ts index 0118575ea..b160f458f 100755 --- a/src/state/selection/constants.ts +++ b/src/state/selection/constants.ts @@ -26,6 +26,8 @@ export const SET_COLOR_OVERRIDES = makeSelectionConstant("set-color-overrides"); export const SET_POINT_RADIUS = makeSelectionConstant("set-point-radius"); export const SET_POINT_OPACITY = makeSelectionConstant("set-point-opacity"); export const SET_FILTERED_VALUES = makeSelectionConstant("set-filtered-values"); +export const SET_FEATURE_FILTER = makeSelectionConstant("set-feature-filter"); +export const SET_FILTER_ACTIVE = makeSelectionConstant("set-filter-active"); export const OPEN_CELL_IN_3D = makeSelectionConstant("open-cell-in-3d"); export const TOGGLE_APPLY_SELECTION_SET_COLOR = makeSelectionConstant("apply-selection-set-color"); export const DESELECT_GROUP_OF_POINTS = makeSelectionConstant("deselect-group"); diff --git a/src/state/selection/reducer.ts b/src/state/selection/reducer.ts index 01382a23b..68b0bd0b8 100755 --- a/src/state/selection/reducer.ts +++ b/src/state/selection/reducer.ts @@ -44,6 +44,8 @@ import { SET_CONNECT_LINE_WIDTH, SET_CONNECT_LINE_DEFAULT_COLOR, SET_CONNECT_LINE_OPACITY, + SET_FEATURE_FILTER, + SET_FILTER_ACTIVE, } from "./constants"; import { BoolToggleAction, @@ -70,6 +72,8 @@ import { SetColorOverrideAction, SetColorOverridesAction, SetCsvUrlAction, + SetFilterActiveAction, + SetFilterByFeatureAction, SetLineAverageWindowAction, SetLineDefaultColorAction, SetLineOpacityAction, @@ -90,6 +94,8 @@ export const initialState: SelectionStateBranch = { type: "", }, filterExclude: [] as string[], + filters: new Map(), + activeFilters: new Set(), galleryCollapsed: true, hoveredCardId: "", hoveredPointData: null, @@ -358,6 +364,47 @@ const actionToConfigMap: TypeToDescriptionMap = { filterExclude: action.payload, }), }, + [SET_FEATURE_FILTER]: { + accepts: (action: Action): action is SetFilterByFeatureAction => + action.type === SET_FEATURE_FILTER, + perform: (state: SelectionStateBranch, action: SetFilterByFeatureAction) => { + const newFilters = new Map(state.filters); + if (action.payload.filter === null) { + newFilters.delete(action.payload.feature); + } else { + newFilters.set(action.payload.feature, action.payload.filter); + } + console.log( + "Setting filter for feature:", + action.payload.feature, + "with filter:", + action.payload.filter, + "from action", + action + ); + console.log("New filters map:", newFilters); + return { + ...state, + filters: newFilters, + }; + }, + }, + [SET_FILTER_ACTIVE]: { + accepts: (action: Action): action is SetFilterActiveAction => + action.type === SET_FILTER_ACTIVE, + perform: (state: SelectionStateBranch, action: SetFilterActiveAction) => { + const newActiveFilters = new Set(state.activeFilters); + if (action.payload.active) { + newActiveFilters.add(action.payload.feature); + } else { + newActiveFilters.delete(action.payload.feature); + } + return { + ...state, + activeFilters: newActiveFilters, + }; + }, + }, [TOGGLE_APPLY_SELECTION_SET_COLOR]: { accepts: (action: Action): action is BoolToggleAction => action.type === TOGGLE_APPLY_SELECTION_SET_COLOR, diff --git a/src/state/selection/selectors.ts b/src/state/selection/selectors.ts index d8d0afa2f..89535384c 100755 --- a/src/state/selection/selectors.ts +++ b/src/state/selection/selectors.ts @@ -30,10 +30,13 @@ import { findFeature, getCategoryString, getFileInfoDatumFromCellId, sortNumeric import { MISSING_CATEGORY_COLOR, MISSING_CATEGORY_LABEL } from "./constants"; import { ColorForPlot, + DiscreteFilterData, DownloadConfig, + FilterData, LassoOrBoxSelectPointData, MainPlotSettings, MousePosition, + NumericFilter, SelectedPointData, } from "./types"; @@ -65,6 +68,8 @@ export const getPointOpacity = (state: State): number => state.selection.pointOp export const getSelectionSetColors = (state: State): { [key: string]: string } => state.selection.selectedGroupColors; export const getFiltersToExclude = (state: State): string[] => state.selection.filterExclude; +export const getActiveFilters = (state: State): Set => state.selection.activeFilters; +export const getFilters = (state: State): Map => state.selection.filters; export const getSelected3DCell = (state: State): string => state.selection.cellSelectedFor3D; export const getApplyColorToSelections = (state: State): boolean => state.selection.applySelectionSetColoring; @@ -373,6 +378,70 @@ export const getColorByCategoryCounts = createSelector( // FILTERED DATA // ============= +const getNumericFilterFromFeature = ( + featureDef: MeasuredFeatureDef, + filter: FilterData | undefined +): NumericFilter | undefined => { + if (!filter) { + return undefined; + } + if (featureDef.discrete && filter.discrete) { + const orderedValues = Object.values(featureDef.options).map( + (option) => option.key ?? option.name + ); + const excludedLUT = orderedValues.map((value) => filter.excluded.has(value)); + return { + featureKey: featureDef.key, + excludedLUT, + }; + } else if (!featureDef.discrete && !filter.discrete) { + return { + featureKey: featureDef.key, + range: [filter.min, filter.max], + }; + } else { + console.error( + `Feature '${featureDef.displayName} (${featureDef.key})' type and filter type are mismatched.`, + featureDef, + filter + ); + return undefined; + } +}; + +export const getGroupByFilter = createSelector( + [getFilters, getGroupByCategory], + (filters, groupByCategory): DiscreteFilterData | undefined => { + return filters.get(groupByCategory) as DiscreteFilterData; + } +); + +export const getNumericFilters = createSelector( + [getActiveFilters, getFilters, getMeasuredFeaturesDefs, getGroupByCategory], + ( + activeFilters, + filters, + featureDefs, + groupByCategory + ): Map => { + // Add the group by category to the set of active filters. + activeFilters = new Set(activeFilters); + activeFilters.add(groupByCategory); + + const numericFilters: Map = new Map(); + for (const featureDef of featureDefs) { + if (activeFilters.has(featureDef.key)) { + const numericFilter = getNumericFilterFromFeature( + featureDef, + filters.get(featureDef.key) + ); + numericFilters.set(featureDef.key, numericFilter); + } + } + return numericFilters; + } +); + export const getFilteredCellData = createSelector( /** * Takes the full data and filters it based on the selected checkboxes and @@ -384,14 +453,17 @@ export const getFilteredCellData = createSelector( getPerCellDataForPlot, getGroupByCategory, getGroupingCategoryNamesAsArray, + getNumericFilters, ], ( measuredFeatureKeys, filtersToExclude, perCellDataForPlot: DataForPlot, categoryKey: string, - groupingNames + groupingNames, + numericFilters ): DataForPlot => { + console.log(numericFilters); if (!filtersToExclude.length) { return { ...perCellDataForPlot, @@ -408,8 +480,28 @@ export const getFilteredCellData = createSelector( const srcPaths: string[] = []; const indices: number[] = []; for (let i = 0; i < perCellDataForPlot.labels.cellIds.length; i++) { + let isExcluded = false; + for (const [featureKey, numericFilter] of numericFilters) { + const value = perCellDataForPlot.values[featureKey][i]; + if (numericFilter && value !== null) { + if (numericFilter.range !== undefined) { + if (value < numericFilter.range[0] || value > numericFilter.range[1]) { + isExcluded = true; + break; + } + } else if (numericFilter.excludedLUT) { + if (numericFilter.excludedLUT[value]) { + isExcluded = true; + break; + } + } + } + } + if (isExcluded) { + continue; + } const categoryName: string = groupingNames[i]; - if (!includes(filtersToExclude, categoryName)) { + if (true) { const cellId = perCellDataForPlot.labels.cellIds[i]; cellIds.push(cellId); categoryNameArray.push(categoryName); diff --git a/src/state/selection/types.ts b/src/state/selection/types.ts index 019b04c22..6205c6b78 100755 --- a/src/state/selection/types.ts +++ b/src/state/selection/types.ts @@ -3,6 +3,25 @@ import { CELL_ID_KEY, GENERAL_PLOT_SETTINGS } from "../../constants"; import type { URLSearchParamMap } from "../../util/UrlState"; import type { FileInfo } from "../metadata/types"; +export type DiscreteFilterData = { + discrete: true; + excluded: Set; +}; + +export type ContinuousFilterData = { + discrete: false; + min: number; + max: number; +}; + +export type FilterData = DiscreteFilterData | ContinuousFilterData; + +export type NumericFilter = { + featureKey: string; + excludedLUT?: boolean[]; + range?: [number, number]; +}; + export interface SelectionStateBranch { applySelectionSetColoring: boolean; cellSelectedFor3D: string; @@ -12,6 +31,8 @@ export interface SelectionStateBranch { csvUrl: string; downloadConfig: DownloadConfig; filterExclude: string[]; + filters: Map; + activeFilters: Set; galleryCollapsed: boolean; hoveredCardId: string; hoveredPointData: SelectedPointData | null; @@ -112,6 +133,21 @@ export interface ChangeFilterSelectionAction { type: string; } +export interface SetFilterByFeatureAction { + payload: { + feature: string; + filter: FilterData | null; + }; + type: string; +} + +export interface SetFilterActiveAction { + payload: { + feature: string; + active: boolean; + }; + type: string; +} export interface ChangeDownloadConfigAction { payload: DownloadConfig; From 821d1be37af5f8738cd960c0fb501eaef709586f Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Fri, 30 Oct 2026 12:48:43 -0700 Subject: [PATCH 03/17] fix: Applied filters to main plot view and annotations --- src/containers/MainPlotContainer/index.tsx | 9 +-- src/containers/MainPlotContainer/selectors.ts | 11 ++-- src/state/selection/selectors.ts | 63 ++++++++++--------- 3 files changed, 39 insertions(+), 44 deletions(-) diff --git a/src/containers/MainPlotContainer/index.tsx b/src/containers/MainPlotContainer/index.tsx index d4d965f6f..11da4499c 100644 --- a/src/containers/MainPlotContainer/index.tsx +++ b/src/containers/MainPlotContainer/index.tsx @@ -63,7 +63,6 @@ interface PropsFromState { annotations: PlotlyAnnotation[]; categoricalFeatures: string[]; clickedPoints: string[]; - filtersToExclude: string[]; galleryCollapsed: boolean; hoveredPointData: SelectedPointData | null; hoveredXValue: string; @@ -188,17 +187,14 @@ class MainPlotContainer extends React.Component { - if ( - point.data.name === SCATTER_PLOT_NAME && - !includes(filtersToExclude, point.fullData.name) - ) { + if (point.data.name === SCATTER_PLOT_NAME) { window.clearTimeout(this.thumbnailTimeout); changeHoveredPoint({ [CELL_ID_KEY]: point.id, @@ -382,7 +378,6 @@ function mapStateToProps(state: State): PropsFromState { annotations: getAnnotations(state), clickedPoints: selectionStateBranch.selectors.getClickedScatterPoints(state), categoricalFeatures: metadataStateBranch.selectors.getCategoricalFeatureKeys(state), - filtersToExclude: selectionStateBranch.selectors.getFiltersToExclude(state), galleryCollapsed: selectionStateBranch.selectors.getGalleryCollapsed(state), hoveredPointData: getDataForOverlayCard(state), hoveredXValue: getFormattedHoveredXValue(state), diff --git a/src/containers/MainPlotContainer/selectors.ts b/src/containers/MainPlotContainer/selectors.ts index 477d73e2a..c684adc7b 100644 --- a/src/containers/MainPlotContainer/selectors.ts +++ b/src/containers/MainPlotContainer/selectors.ts @@ -51,6 +51,8 @@ import { getConnectByFeature, getConnectByCategory, getFiltersToExclude, + getNumericFilters, + isValueExcludedByFilters, } from "../../state/selection/selectors"; import { ColorForPlot, @@ -296,19 +298,17 @@ const getAnnotationData = createSelector( [ getPerCellDataForPlot, getClickedCellsFileInfo, - getFiltersToExclude, + getNumericFilters, getPlotByOnX, getPlotByOnY, - getGroupingCategoryNamesAsArray, getHoveredCardId, ], ( allCellData: DataForPlot, clickedCellsFileInfo: FileInfo[], - filtersToExclude: string[], + numericFilters, xAxis, yAxis, - groupByCategoryNames, currentHoveredCellId ): AnnotationData[] => { if (isEmpty(allCellData.values) || isEmpty(allCellData.labels)) { @@ -332,8 +332,7 @@ const getAnnotationData = createSelector( const y = allCellData.values[yAxis][pointIndex] ?? null; // Apply filtering - const groupName = groupByCategoryNames[pointIndex] ?? null; - if (filtersToExclude.includes(groupName)) { + if (isValueExcludedByFilters(pointIndex, allCellData, numericFilters)) { return acc; } diff --git a/src/state/selection/selectors.ts b/src/state/selection/selectors.ts index 89535384c..fc465e0b8 100755 --- a/src/state/selection/selectors.ts +++ b/src/state/selection/selectors.ts @@ -442,6 +442,31 @@ export const getNumericFilters = createSelector( } ); +export function isValueExcludedByFilters( + id: number, + cellData: DataForPlot, + numericFilters: Map +): boolean { + let isExcluded = false; + for (const [featureKey, numericFilter] of numericFilters) { + const value = cellData.values[featureKey][id]; + if (numericFilter && value !== null) { + if (numericFilter.range !== undefined) { + if (value < numericFilter.range[0] || value > numericFilter.range[1]) { + isExcluded = true; + break; + } + } else if (numericFilter.excludedLUT) { + if (numericFilter.excludedLUT[value]) { + isExcluded = true; + break; + } + } + } + } + return isExcluded; +} + export const getFilteredCellData = createSelector( /** * Takes the full data and filters it based on the selected checkboxes and @@ -449,7 +474,6 @@ export const getFilteredCellData = createSelector( */ [ getMeasuredFeaturesKeys, - getFiltersToExclude, getPerCellDataForPlot, getGroupByCategory, getGroupingCategoryNamesAsArray, @@ -457,47 +481,23 @@ export const getFilteredCellData = createSelector( ], ( measuredFeatureKeys, - filtersToExclude, - perCellDataForPlot: DataForPlot, + perCellDataForPlot, categoryKey: string, groupingNames, numericFilters ): DataForPlot => { - console.log(numericFilters); - if (!filtersToExclude.length) { - return { - ...perCellDataForPlot, - labels: { - ...perCellDataForPlot.labels, - [categoryKey]: groupingNames, - }, - }; - } const categoryNameArray: string[] = []; const dataToReturn: MappingOfMeasuredValuesArrays = {}; const cellIds: string[] = []; const thumbnails: string[] = []; const srcPaths: string[] = []; const indices: number[] = []; - for (let i = 0; i < perCellDataForPlot.labels.cellIds.length; i++) { - let isExcluded = false; - for (const [featureKey, numericFilter] of numericFilters) { - const value = perCellDataForPlot.values[featureKey][i]; - if (numericFilter && value !== null) { - if (numericFilter.range !== undefined) { - if (value < numericFilter.range[0] || value > numericFilter.range[1]) { - isExcluded = true; - break; - } - } else if (numericFilter.excludedLUT) { - if (numericFilter.excludedLUT[value]) { - isExcluded = true; - break; - } - } - } - } + let excludedValues = 0; + const numValues = perCellDataForPlot.labels?.cellIds?.length; + for (let i = 0; i < (numValues ?? 0); i++) { + const isExcluded = isValueExcludedByFilters(i, perCellDataForPlot, numericFilters); if (isExcluded) { + excludedValues++; continue; } const categoryName: string = groupingNames[i]; @@ -520,6 +520,7 @@ export const getFilteredCellData = createSelector( }); } } + console.log("getFilteredCellData - excluded values:", excludedValues); return { indices: indices, values: dataToReturn, From 4046c0d2f76789aee787a8c0d02ee5eb956bf743 Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Fri, 30 Oct 2026 13:32:07 -0700 Subject: [PATCH 04/17] refactor: Renamed variables, added method comments, removed old filterExclude state, linting --- src/containers/ColorByMenu/index.tsx | 35 ++++----------- src/containers/ColorByMenu/selectors.ts | 4 +- src/containers/ColorByMenu/style.module.css | 9 +++- src/containers/MainPlotContainer/selectors.ts | 1 - .../MainPlotContainer/test/selectors.test.ts | 12 ++++- src/state/selection/actions.ts | 44 ++++++++++--------- src/state/selection/constants.ts | 3 +- src/state/selection/logics.ts | 1 + src/state/selection/reducer.ts | 32 +++----------- src/state/selection/selectors.ts | 2 - src/state/selection/types.ts | 8 +--- src/state/test/mocks.ts | 3 +- 12 files changed, 60 insertions(+), 94 deletions(-) diff --git a/src/containers/ColorByMenu/index.tsx b/src/containers/ColorByMenu/index.tsx index 4a8f7d1a4..b60b5b73d 100644 --- a/src/containers/ColorByMenu/index.tsx +++ b/src/containers/ColorByMenu/index.tsx @@ -1,6 +1,6 @@ import { Checkbox, Col, Collapse, Row } from "antd"; import { CheckboxChangeEvent } from "antd/es/checkbox"; -import { filter, groupBy, includes } from "lodash"; +import { includes } from "lodash"; import React from "react"; import { connect } from "react-redux"; import type { ActionCreator } from "redux"; @@ -22,7 +22,6 @@ import { getFeatureDefTooltip, getDownloadRoot } from "../../state/selection/sel import { BoolToggleAction, ChangeDownloadConfigAction, - ChangeFilterSelectionAction, ChangeGroupByCategory, ColorForPlot, DeselectGroupOfPointsAction, @@ -31,7 +30,7 @@ import { FilterData, SelectAxisAction, SetColorOverrideAction, - SetFilterByFeatureAction, + SetFilterAction, } from "../../state/selection/types"; import { State } from "../../state/types"; import { getColorByDisplayOptions, getGroupByDisplayOptions } from "../MainPlotContainer/selectors"; @@ -60,7 +59,6 @@ interface PropsFromState { downloadUrls: string[]; downloadConfig: DownloadConfig; downloadRoot: string; - filtersToExclude: string[]; filters: Map; groupByFilter: DiscreteFilterData | undefined; interactivePanelData: PanelData[]; @@ -79,8 +77,7 @@ interface DispatchProps { handleChangeAxis: ActionCreator; handleChangeGroupByCategory: ActionCreator; handleCloseSelectionSet: ActionCreator; - handleSetFilteredValues: ActionCreator; - handleSetFeatureFilter: ActionCreator; + handleSetFeatureFilter: ActionCreator; handleChangeDownloadSettings: ActionCreator; handleSetColorOverride: ActionCreator; } @@ -115,27 +112,17 @@ class ColorByMenu extends React.Component { public onBarClicked({ target }: CheckboxChangeEvent) { const { groupByFilter, groupBy, handleSetFeatureFilter } = this.props; - let filter = groupByFilter; - if (!filter) { - filter = { discrete: true, excluded: new Set() }; - } else { - filter = { ...filter, excluded: new Set(filter.excluded) }; - } + let filter = groupByFilter ?? { discrete: true, excluded: new Set() }; + // Toggle whether the category is excluded from the filter if (filter.discrete) { + filter = { ...filter, excluded: new Set(filter.excluded) }; if (target.checked) { filter.excluded.delete(target.value); } else { filter.excluded.add(target.value); } } - console.log("Setting filter for groupBy:", groupByFilter, "with filter:", filter); handleSetFeatureFilter(groupBy.toString(), filter); - // const { handleSetFilteredValues: handleFilterByCategoryName, filtersToExclude } = - // this.props; - // const newFilterList: string[] = includes(filtersToExclude, target.value) - // ? filter(filtersToExclude, (e) => e !== target.value) - // : [...filtersToExclude, target.value]; - // handleFilterByCategoryName(newFilterList); } public onCategorySetDownloadButtonClicked(categoryName: string) { @@ -156,10 +143,7 @@ class ColorByMenu extends React.Component { public allOnOff({ target }: CheckboxChangeEvent) { const { groupByFilter, groupBy, handleSetFeatureFilter, interactivePanelData } = this.props; - let filter = groupByFilter; - if (!filter) { - filter = { discrete: true, excluded: new Set() }; - } + let filter = groupByFilter ?? { discrete: true, excluded: new Set() }; if (filter.discrete) { filter = { ...filter, excluded: new Set(filter.excluded) }; if (target.checked) { @@ -237,7 +221,6 @@ class ColorByMenu extends React.Component { public renderTaggedStructuresPanel() { const { - filtersToExclude, isInIndeterminateState, interactivePanelData, downloadUrls, @@ -294,7 +277,7 @@ class ColorByMenu extends React.Component {
Show/Hide all @@ -385,7 +368,6 @@ function mapStateToProps(state: State): PropsFromState { downloadConfig: selectionStateBranch.selectors.getDownloadConfig(state), downloadUrls: createUrlFromListOfIds(state), downloadRoot: getDownloadRoot(state), - filtersToExclude: selectionStateBranch.selectors.getFiltersToExclude(state), filters: selectionStateBranch.selectors.getFilters(state), groupByFilter: selectionStateBranch.selectors.getGroupByFilter(state), groupByTitle: getGroupByTitle(state), @@ -401,7 +383,6 @@ const dispatchToPropsMap: DispatchProps = { handleChangeGroupByCategory: selectionStateBranch.actions.changeGroupByCategory, handleChangeDownloadSettings: selectionStateBranch.actions.changeDownloadSettings, handleCloseSelectionSet: selectionStateBranch.actions.deselectGroupOfPoints, - handleSetFilteredValues: selectionStateBranch.actions.setFilteredValues, handleSetFeatureFilter: selectionStateBranch.actions.setFeatureFilter, handleSetColorOverride: selectionStateBranch.actions.setColorOverride, }; diff --git a/src/containers/ColorByMenu/selectors.ts b/src/containers/ColorByMenu/selectors.ts index 48d5af6be..bd453455c 100644 --- a/src/containers/ColorByMenu/selectors.ts +++ b/src/containers/ColorByMenu/selectors.ts @@ -1,4 +1,4 @@ -import { chunk, includes, map, reduce, values } from "lodash"; +import { chunk, map, reduce, values } from "lodash"; import { createSelector } from "reselect"; import { @@ -23,7 +23,6 @@ import { getColorBySelection, getDownloadConfig, getDownloadRoot, - getFiltersToExclude, getSelectedGroupKeys, getSelectedGroups, getSelectedSetTotals, @@ -177,7 +176,6 @@ export const getInteractivePanelData = createSelector( const total: number = countsByCategory[id] || category.count || 0; const disabled = !displayableGroups.includes(id); const excluded = groupByFilter?.excluded.has(id) ?? false; - console.log("Groupbyfilter:", groupByFilter, "excluded: ", excluded); const color = getColorForCategory( categoryToColorBy === categoryToGroupBy, excluded, diff --git a/src/containers/ColorByMenu/style.module.css b/src/containers/ColorByMenu/style.module.css index 4a8752aad..bbd58a27e 100644 --- a/src/containers/ColorByMenu/style.module.css +++ b/src/containers/ColorByMenu/style.module.css @@ -34,4 +34,11 @@ .feature-select-row :global(.ant-select) { width: 100%; -} \ No newline at end of file +} + +/* Make intermediate checkbox visible */ +.interactive-legend-container + :global(.ant-checkbox.ant-checkbox-indeterminate) + > :global(.ant-checkbox-inner)::after { + background-color: var(--dimgray); +} diff --git a/src/containers/MainPlotContainer/selectors.ts b/src/containers/MainPlotContainer/selectors.ts index c684adc7b..3a4bd9dbd 100644 --- a/src/containers/MainPlotContainer/selectors.ts +++ b/src/containers/MainPlotContainer/selectors.ts @@ -50,7 +50,6 @@ import { getLineMovingAverageWindow, getConnectByFeature, getConnectByCategory, - getFiltersToExclude, getNumericFilters, isValueExcludedByFilters, } from "../../state/selection/selectors"; diff --git a/src/containers/MainPlotContainer/test/selectors.test.ts b/src/containers/MainPlotContainer/test/selectors.test.ts index 7dcf22993..5d65aff33 100644 --- a/src/containers/MainPlotContainer/test/selectors.test.ts +++ b/src/containers/MainPlotContainer/test/selectors.test.ts @@ -14,7 +14,7 @@ import { } from "../selectors"; import type { PlotlyAnnotation } from "../../../components/MainPlot"; import { CELL_ID_KEY, PALETTE } from "../../../constants"; -import type { ColorForPlot } from "../../../state/selection/types"; +import type { ColorForPlot, FilterData } from "../../../state/selection/types"; describe("MainPlotContainer selectors", () => { const newMockState = mockState; @@ -76,7 +76,15 @@ describe("MainPlotContainer selectors", () => { // 2 cells are selected, but the first (cell ID 1) will be // excluded by filtering selectedPoints: selectedCellFileInfo, - filterExclude: ["Paxillin"], + filters: new Map([ + [ + newMockState.selection.groupBy, + { + discrete: true, + excluded: new Set(["Paxillin"]), + }, + ], + ]), }, }; const result: PlotlyAnnotation[] = getAnnotations(state); diff --git a/src/state/selection/actions.ts b/src/state/selection/actions.ts index bd1c95b26..32b022ecb 100755 --- a/src/state/selection/actions.ts +++ b/src/state/selection/actions.ts @@ -16,7 +16,6 @@ import { SET_MOUSE_POSITION, SYNC_STATE_WITH_URL, TOGGLE_APPLY_SELECTION_SET_COLOR, - SET_FILTERED_VALUES, TOGGLE_GALLERY_OPEN_CLOSE, CHANGE_DATASET, RECEIVE_FILE_INFO, @@ -38,12 +37,11 @@ import { SET_CONNECT_LINE_DEFAULT_COLOR, SET_CONNECT_LINE_OPACITY, SET_FILTER_ACTIVE, - SET_FEATURE_FILTER, + SET_FILTER, } from "./constants"; import { BoolToggleAction, ChangeDownloadConfigAction, - ChangeFilterSelectionAction, ChangeGroupByCategory, ChangeHoveredPointAction, ChangeMousePositionAction, @@ -67,7 +65,7 @@ import { SetColorOverridesAction, SetCsvUrlAction, SetFilterActiveAction, - SetFilterByFeatureAction, + SetFilterAction, SetLineAverageWindowAction, SetLineDefaultColorAction, SetLineOpacityAction, @@ -210,29 +208,33 @@ export function setPointOpacity(payload: number): SetPointOpacityAction { }; } -export function setFilteredValues(payload: string[]): ChangeFilterSelectionAction { - return { - payload, - type: SET_FILTERED_VALUES, - }; -} - -export function setFeatureFilter( - feature: string, - filter: FilterData | null -): SetFilterByFeatureAction { +/** + * Sets a filter for the specified feature. If the feature is selected as the + * groupBy feature, or if the feature is marked as active for filtering (see + * `setFilterActive`), points that are filtered out by this filter will be + * excluded from the plot. + * @param feature The key of the feature to set the filter for. + * @param filter The filter data to apply to the feature. + */ +export function setFilter(feature: string, filter: FilterData | null): SetFilterAction { return { payload: { feature, filter }, - type: SET_FEATURE_FILTER, + type: SET_FILTER, }; } -export function setFilterActive(payload: { - feature: string; - active: boolean; -}): SetFilterActiveAction { +/** + * Sets whether the specified feature's filter should be applied to points in + * the plot. + * @param feature The key of the feature to set the filter active state for. + * @param active Whether the filter should be applied to points in the plot. + */ +export function setFilterActive(feature: string, active: boolean): SetFilterActiveAction { return { - payload, + payload: { + feature, + active, + }, type: SET_FILTER_ACTIVE, }; } diff --git a/src/state/selection/constants.ts b/src/state/selection/constants.ts index b160f458f..5260740fe 100755 --- a/src/state/selection/constants.ts +++ b/src/state/selection/constants.ts @@ -25,8 +25,7 @@ export const SET_COLOR_OVERRIDE = makeSelectionConstant("set-color-override"); export const SET_COLOR_OVERRIDES = makeSelectionConstant("set-color-overrides"); export const SET_POINT_RADIUS = makeSelectionConstant("set-point-radius"); export const SET_POINT_OPACITY = makeSelectionConstant("set-point-opacity"); -export const SET_FILTERED_VALUES = makeSelectionConstant("set-filtered-values"); -export const SET_FEATURE_FILTER = makeSelectionConstant("set-feature-filter"); +export const SET_FILTER = makeSelectionConstant("set-filter"); export const SET_FILTER_ACTIVE = makeSelectionConstant("set-filter-active"); export const OPEN_CELL_IN_3D = makeSelectionConstant("open-cell-in-3d"); export const TOGGLE_APPLY_SELECTION_SET_COLOR = makeSelectionConstant("apply-selection-set-color"); diff --git a/src/state/selection/logics.ts b/src/state/selection/logics.ts index fa0225d47..cf656a8aa 100755 --- a/src/state/selection/logics.ts +++ b/src/state/selection/logics.ts @@ -106,6 +106,7 @@ const changeDatasetLogic = createLogic({ if (!featureKeys.has(state.selection.groupBy)) { actions.push(changeGroupByCategory(selections.defaultGroupBy)); } + // TODO: Clear filtering and annotations if ( !featureKeys.has(state.selection.connectByFeature) && selections.defaultConnectBy diff --git a/src/state/selection/reducer.ts b/src/state/selection/reducer.ts index 68b0bd0b8..9637a02af 100755 --- a/src/state/selection/reducer.ts +++ b/src/state/selection/reducer.ts @@ -23,7 +23,6 @@ import { SET_DOWNLOAD_CONFIG, SET_MOUSE_POSITION, TOGGLE_APPLY_SELECTION_SET_COLOR, - SET_FILTERED_VALUES, TOGGLE_GALLERY_OPEN_CLOSE, SET_DATASET, RECEIVE_FILE_INFO_FOR_ALBUM_CELLS, @@ -44,7 +43,7 @@ import { SET_CONNECT_LINE_WIDTH, SET_CONNECT_LINE_DEFAULT_COLOR, SET_CONNECT_LINE_OPACITY, - SET_FEATURE_FILTER, + SET_FILTER, SET_FILTER_ACTIVE, } from "./constants"; import { @@ -52,12 +51,10 @@ import { ChangeConnectByCategory, ChangeConnectByFeature, ChangeDownloadConfigAction, - ChangeFilterSelectionAction, ChangeGroupByCategory, ChangeHoveredPointAction, ChangeMousePositionAction, ChangeSelectedDatasetAction, - ChangeSelectionAction, ClearDatasetAction, DeselectGroupOfPointsAction, DeselectPointAction, @@ -73,7 +70,7 @@ import { SetColorOverridesAction, SetCsvUrlAction, SetFilterActiveAction, - SetFilterByFeatureAction, + SetFilterAction, SetLineAverageWindowAction, SetLineDefaultColorAction, SetLineOpacityAction, @@ -93,7 +90,6 @@ export const initialState: SelectionStateBranch = { key: "", type: "", }, - filterExclude: [] as string[], filters: new Map(), activeFilters: new Set(), galleryCollapsed: true, @@ -356,33 +352,15 @@ const actionToConfigMap: TypeToDescriptionMap = { colorOverrides: action.payload, }), }, - [SET_FILTERED_VALUES]: { - accepts: (action: Action): action is ChangeFilterSelectionAction => - action.type === SET_FILTERED_VALUES, - perform: (state: SelectionStateBranch, action: ChangeFilterSelectionAction) => ({ - ...state, - filterExclude: action.payload, - }), - }, - [SET_FEATURE_FILTER]: { - accepts: (action: Action): action is SetFilterByFeatureAction => - action.type === SET_FEATURE_FILTER, - perform: (state: SelectionStateBranch, action: SetFilterByFeatureAction) => { + [SET_FILTER]: { + accepts: (action: Action): action is SetFilterAction => action.type === SET_FILTER, + perform: (state: SelectionStateBranch, action: SetFilterAction) => { const newFilters = new Map(state.filters); if (action.payload.filter === null) { newFilters.delete(action.payload.feature); } else { newFilters.set(action.payload.feature, action.payload.filter); } - console.log( - "Setting filter for feature:", - action.payload.feature, - "with filter:", - action.payload.filter, - "from action", - action - ); - console.log("New filters map:", newFilters); return { ...state, filters: newFilters, diff --git a/src/state/selection/selectors.ts b/src/state/selection/selectors.ts index fc465e0b8..205d5f9e7 100755 --- a/src/state/selection/selectors.ts +++ b/src/state/selection/selectors.ts @@ -67,7 +67,6 @@ export const getPointRadius = (state: State): number => state.selection.pointRad export const getPointOpacity = (state: State): number => state.selection.pointOpacity; export const getSelectionSetColors = (state: State): { [key: string]: string } => state.selection.selectedGroupColors; -export const getFiltersToExclude = (state: State): string[] => state.selection.filterExclude; export const getActiveFilters = (state: State): Set => state.selection.activeFilters; export const getFilters = (state: State): Map => state.selection.filters; export const getSelected3DCell = (state: State): string => state.selection.cellSelectedFor3D; @@ -520,7 +519,6 @@ export const getFilteredCellData = createSelector( }); } } - console.log("getFilteredCellData - excluded values:", excludedValues); return { indices: indices, values: dataToReturn, diff --git a/src/state/selection/types.ts b/src/state/selection/types.ts index 6205c6b78..734653aaf 100755 --- a/src/state/selection/types.ts +++ b/src/state/selection/types.ts @@ -30,7 +30,6 @@ export interface SelectionStateBranch { /** Source of the URL for a CSV file. */ csvUrl: string; downloadConfig: DownloadConfig; - filterExclude: string[]; filters: Map; activeFilters: Set; galleryCollapsed: boolean; @@ -128,12 +127,7 @@ export interface ChangeSelectionAction { type: string; } -export interface ChangeFilterSelectionAction { - payload: string[]; - type: string; -} - -export interface SetFilterByFeatureAction { +export interface SetFilterAction { payload: { feature: string; filter: FilterData | null; diff --git a/src/state/test/mocks.ts b/src/state/test/mocks.ts index 7af97804f..499f6ec3c 100644 --- a/src/state/test/mocks.ts +++ b/src/state/test/mocks.ts @@ -13,6 +13,7 @@ import { initialState as initialMetaData } from "../metadata/reducer"; import { DataForPlot, FileInfo, MeasuredFeatureDef } from "../metadata/types"; import { INITIAL_COLORS } from "../selection/constants"; import { initialState as initialSelectionState } from "../selection/reducer"; +import type { FilterData } from "../selection/types"; export const selectedCellFileInfo: FileInfo[] = [ { @@ -177,7 +178,6 @@ export const mockState = { }, downloadRoot: "dlurl/", groupBy: INITIAL_COLOR_AND_GROUP_BY, - filterExclude: [], plotByOnX: "apical-proximity", plotByOnY: "anaphase-segmentation-complete", defaultColors: INITIAL_COLORS, @@ -186,5 +186,6 @@ export const mockState = { selectedGroups: {}, selectedPoints: selectedCellFileInfo, displayableGroups: displayableGroups, + filters: new Map(), }, }; From 95cc96d705f05e311415ee56200ffc754e3e04da Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Fri, 30 Oct 2026 13:34:41 -0700 Subject: [PATCH 05/17] feat: Reset filters on dataset change --- src/state/selection/actions.ts | 8 ++++++++ src/state/selection/constants.ts | 1 + src/state/selection/logics.ts | 4 +++- src/state/selection/reducer.ts | 10 ++++++++++ src/state/selection/types.ts | 4 ++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/state/selection/actions.ts b/src/state/selection/actions.ts index 32b022ecb..d97d3094b 100755 --- a/src/state/selection/actions.ts +++ b/src/state/selection/actions.ts @@ -38,6 +38,7 @@ import { SET_CONNECT_LINE_OPACITY, SET_FILTER_ACTIVE, SET_FILTER, + CLEAR_FILTERS, } from "./constants"; import { BoolToggleAction, @@ -73,6 +74,7 @@ import { SetPointOpacityAction, SetPointRadiusAction, SyncStateWithURLAction, + ClearFiltersAction, } from "./types"; export function changeAxis(axisId: string, payload: string): SelectAxisAction { @@ -239,6 +241,12 @@ export function setFilterActive(feature: string, active: boolean): SetFilterActi }; } +export function clearFilters(): ClearFiltersAction { + return { + type: CLEAR_FILTERS, + }; +} + export function selectCellFor3DViewer(payload: { id: string }): SelectPointAction { return { payload, diff --git a/src/state/selection/constants.ts b/src/state/selection/constants.ts index 5260740fe..d7d62b8ab 100755 --- a/src/state/selection/constants.ts +++ b/src/state/selection/constants.ts @@ -26,6 +26,7 @@ export const SET_COLOR_OVERRIDES = makeSelectionConstant("set-color-overrides"); export const SET_POINT_RADIUS = makeSelectionConstant("set-point-radius"); export const SET_POINT_OPACITY = makeSelectionConstant("set-point-opacity"); export const SET_FILTER = makeSelectionConstant("set-filter"); +export const CLEAR_FILTERS = makeSelectionConstant("clear-filters"); export const SET_FILTER_ACTIVE = makeSelectionConstant("set-filter-active"); export const OPEN_CELL_IN_3D = makeSelectionConstant("open-cell-in-3d"); export const TOGGLE_APPLY_SELECTION_SET_COLOR = makeSelectionConstant("apply-selection-set-color"); diff --git a/src/state/selection/logics.ts b/src/state/selection/logics.ts index cf656a8aa..e6a8bbaaf 100755 --- a/src/state/selection/logics.ts +++ b/src/state/selection/logics.ts @@ -26,6 +26,7 @@ import { changeConnectByCategory, changeConnectByFeature, changeGroupByCategory, + clearFilters, } from "./actions"; import { FileInfo } from "../metadata/types"; import { DatasetMetaData } from "../image-dataset/types"; @@ -37,6 +38,7 @@ import { SelectPointAction, SyncStateWithURLAction, } from "./types"; +import { makeAnnotations } from "../../containers/MainPlotContainer/selectors"; const syncStateWithUrl = createLogic({ type: SYNC_STATE_WITH_URL, @@ -106,7 +108,6 @@ const changeDatasetLogic = createLogic({ if (!featureKeys.has(state.selection.groupBy)) { actions.push(changeGroupByCategory(selections.defaultGroupBy)); } - // TODO: Clear filtering and annotations if ( !featureKeys.has(state.selection.connectByFeature) && selections.defaultConnectBy @@ -120,6 +121,7 @@ const changeDatasetLogic = createLogic({ if (!featureKeys.has(state.selection.colorBy) && selections.defaultColorBy) { actions.push(changeAxis(COLOR_BY_SELECTOR, selections.defaultColorBy)); } + actions.push(clearFilters()); dispatch(batchActions(actions)); dispatch({ type: SET_DATASET, diff --git a/src/state/selection/reducer.ts b/src/state/selection/reducer.ts index 9637a02af..33b0eea78 100755 --- a/src/state/selection/reducer.ts +++ b/src/state/selection/reducer.ts @@ -45,6 +45,7 @@ import { SET_CONNECT_LINE_OPACITY, SET_FILTER, SET_FILTER_ACTIVE, + CLEAR_FILTERS, } from "./constants"; import { BoolToggleAction, @@ -78,6 +79,7 @@ import { SetPointOpacityAction, SetPointRadiusAction, SetShowConnectLines, + ClearFiltersAction, } from "./types"; export const initialState: SelectionStateBranch = { @@ -383,6 +385,14 @@ const actionToConfigMap: TypeToDescriptionMap = { }; }, }, + [CLEAR_FILTERS]: { + accepts: (action: Action): action is ClearFiltersAction => action.type === CLEAR_FILTERS, + perform: (state: SelectionStateBranch, action: ClearFiltersAction) => ({ + ...state, + filters: new Map(), + activeFilters: new Set(), + }), + }, [TOGGLE_APPLY_SELECTION_SET_COLOR]: { accepts: (action: Action): action is BoolToggleAction => action.type === TOGGLE_APPLY_SELECTION_SET_COLOR, diff --git a/src/state/selection/types.ts b/src/state/selection/types.ts index 734653aaf..28751f86a 100755 --- a/src/state/selection/types.ts +++ b/src/state/selection/types.ts @@ -127,6 +127,10 @@ export interface ChangeSelectionAction { type: string; } +export interface ClearFiltersAction { + type: string; +} + export interface SetFilterAction { payload: { feature: string; From 8488d2edbcd1ff02feebc2a5e6665e8b5d3779d8 Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Fri, 30 Oct 2026 13:57:37 -0700 Subject: [PATCH 06/17] refactor: Updated comments, moved utility functions out of selectors file --- src/containers/ColorByMenu/index.tsx | 13 ++- src/containers/MainPlotContainer/selectors.ts | 4 +- src/state/selection/actions.ts | 4 +- src/state/selection/selectors.ts | 99 +++++-------------- src/state/selection/types.ts | 18 ++++ src/state/util.ts | 81 ++++++++++++++- 6 files changed, 133 insertions(+), 86 deletions(-) diff --git a/src/containers/ColorByMenu/index.tsx b/src/containers/ColorByMenu/index.tsx index b60b5b73d..7db46daad 100644 --- a/src/containers/ColorByMenu/index.tsx +++ b/src/containers/ColorByMenu/index.tsx @@ -77,7 +77,7 @@ interface DispatchProps { handleChangeAxis: ActionCreator; handleChangeGroupByCategory: ActionCreator; handleCloseSelectionSet: ActionCreator; - handleSetFeatureFilter: ActionCreator; + handleSetFilter: ActionCreator; handleChangeDownloadSettings: ActionCreator; handleSetColorOverride: ActionCreator; } @@ -111,7 +111,7 @@ class ColorByMenu extends React.Component { } public onBarClicked({ target }: CheckboxChangeEvent) { - const { groupByFilter, groupBy, handleSetFeatureFilter } = this.props; + const { groupByFilter, groupBy, handleSetFilter: handleSetFeatureFilter } = this.props; let filter = groupByFilter ?? { discrete: true, excluded: new Set() }; // Toggle whether the category is excluded from the filter if (filter.discrete) { @@ -142,7 +142,12 @@ class ColorByMenu extends React.Component { } public allOnOff({ target }: CheckboxChangeEvent) { - const { groupByFilter, groupBy, handleSetFeatureFilter, interactivePanelData } = this.props; + const { + groupByFilter, + groupBy, + handleSetFilter: handleSetFeatureFilter, + interactivePanelData, + } = this.props; let filter = groupByFilter ?? { discrete: true, excluded: new Set() }; if (filter.discrete) { filter = { ...filter, excluded: new Set(filter.excluded) }; @@ -383,7 +388,7 @@ const dispatchToPropsMap: DispatchProps = { handleChangeGroupByCategory: selectionStateBranch.actions.changeGroupByCategory, handleChangeDownloadSettings: selectionStateBranch.actions.changeDownloadSettings, handleCloseSelectionSet: selectionStateBranch.actions.deselectGroupOfPoints, - handleSetFeatureFilter: selectionStateBranch.actions.setFeatureFilter, + handleSetFilter: selectionStateBranch.actions.setFilter, handleSetColorOverride: selectionStateBranch.actions.setColorOverride, }; export default connect( diff --git a/src/containers/MainPlotContainer/selectors.ts b/src/containers/MainPlotContainer/selectors.ts index 3a4bd9dbd..c521a5486 100644 --- a/src/containers/MainPlotContainer/selectors.ts +++ b/src/containers/MainPlotContainer/selectors.ts @@ -51,8 +51,8 @@ import { getConnectByFeature, getConnectByCategory, getNumericFilters, - isValueExcludedByFilters, } from "../../state/selection/selectors"; +import { isIdExcludedByFilters } from "../../state/util"; import { ColorForPlot, MainPlotSettings, @@ -331,7 +331,7 @@ const getAnnotationData = createSelector( const y = allCellData.values[yAxis][pointIndex] ?? null; // Apply filtering - if (isValueExcludedByFilters(pointIndex, allCellData, numericFilters)) { + if (isIdExcludedByFilters(pointIndex, allCellData, numericFilters)) { return acc; } diff --git a/src/state/selection/actions.ts b/src/state/selection/actions.ts index d97d3094b..89cb3643b 100755 --- a/src/state/selection/actions.ts +++ b/src/state/selection/actions.ts @@ -213,8 +213,8 @@ export function setPointOpacity(payload: number): SetPointOpacityAction { /** * Sets a filter for the specified feature. If the feature is selected as the * groupBy feature, or if the feature is marked as active for filtering (see - * `setFilterActive`), points that are filtered out by this filter will be - * excluded from the plot. + * `setFilterActive`), points that are excluded by/not in range of this filter + * will be excluded from the plot. * @param feature The key of the feature to set the filter for. * @param filter The filter data to apply to the feature. */ diff --git a/src/state/selection/selectors.ts b/src/state/selection/selectors.ts index 205d5f9e7..113c927c3 100755 --- a/src/state/selection/selectors.ts +++ b/src/state/selection/selectors.ts @@ -25,7 +25,14 @@ import { PerCellLabels, } from "../metadata/types"; import { NumberOrString, SelectedGroups, State } from "../types"; -import { findFeature, getCategoryString, getFileInfoDatumFromCellId, sortNumeric } from "../util"; +import { + findFeature, + getCategoryString, + getFileInfoDatumFromCellId, + getNumericFilterFromFeature, + isIdExcludedByFilters, + sortNumeric, +} from "../util"; import { MISSING_CATEGORY_COLOR, MISSING_CATEGORY_LABEL } from "./constants"; import { @@ -377,37 +384,6 @@ export const getColorByCategoryCounts = createSelector( // FILTERED DATA // ============= -const getNumericFilterFromFeature = ( - featureDef: MeasuredFeatureDef, - filter: FilterData | undefined -): NumericFilter | undefined => { - if (!filter) { - return undefined; - } - if (featureDef.discrete && filter.discrete) { - const orderedValues = Object.values(featureDef.options).map( - (option) => option.key ?? option.name - ); - const excludedLUT = orderedValues.map((value) => filter.excluded.has(value)); - return { - featureKey: featureDef.key, - excludedLUT, - }; - } else if (!featureDef.discrete && !filter.discrete) { - return { - featureKey: featureDef.key, - range: [filter.min, filter.max], - }; - } else { - console.error( - `Feature '${featureDef.displayName} (${featureDef.key})' type and filter type are mismatched.`, - featureDef, - filter - ); - return undefined; - } -}; - export const getGroupByFilter = createSelector( [getFilters, getGroupByCategory], (filters, groupByCategory): DiscreteFilterData | undefined => { @@ -441,31 +417,6 @@ export const getNumericFilters = createSelector( } ); -export function isValueExcludedByFilters( - id: number, - cellData: DataForPlot, - numericFilters: Map -): boolean { - let isExcluded = false; - for (const [featureKey, numericFilter] of numericFilters) { - const value = cellData.values[featureKey][id]; - if (numericFilter && value !== null) { - if (numericFilter.range !== undefined) { - if (value < numericFilter.range[0] || value > numericFilter.range[1]) { - isExcluded = true; - break; - } - } else if (numericFilter.excludedLUT) { - if (numericFilter.excludedLUT[value]) { - isExcluded = true; - break; - } - } - } - } - return isExcluded; -} - export const getFilteredCellData = createSelector( /** * Takes the full data and filters it based on the selected checkboxes and @@ -491,33 +442,27 @@ export const getFilteredCellData = createSelector( const thumbnails: string[] = []; const srcPaths: string[] = []; const indices: number[] = []; - let excludedValues = 0; const numValues = perCellDataForPlot.labels?.cellIds?.length; for (let i = 0; i < (numValues ?? 0); i++) { - const isExcluded = isValueExcludedByFilters(i, perCellDataForPlot, numericFilters); + const isExcluded = isIdExcludedByFilters(i, perCellDataForPlot, numericFilters); if (isExcluded) { - excludedValues++; continue; } const categoryName: string = groupingNames[i]; - if (true) { - const cellId = perCellDataForPlot.labels.cellIds[i]; - cellIds.push(cellId); - categoryNameArray.push(categoryName); - thumbnails.push(perCellDataForPlot.labels.thumbnailPaths[i]); - srcPaths.push(perCellDataForPlot.labels.sourcePaths?.[i] ?? ""); - indices.push(perCellDataForPlot.indices[i]); - - measuredFeatureKeys.forEach((featureKey) => { - if (!dataToReturn[featureKey]) { - dataToReturn[featureKey] = []; - } + const cellId = perCellDataForPlot.labels.cellIds[i]; + cellIds.push(cellId); + categoryNameArray.push(categoryName); + thumbnails.push(perCellDataForPlot.labels.thumbnailPaths[i]); + srcPaths.push(perCellDataForPlot.labels.sourcePaths?.[i] ?? ""); + indices.push(perCellDataForPlot.indices[i]); + + measuredFeatureKeys.forEach((featureKey) => { + if (!dataToReturn[featureKey]) { + dataToReturn[featureKey] = []; + } - dataToReturn[featureKey].push( - perCellDataForPlot.values[featureKey][i] as never - ); - }); - } + dataToReturn[featureKey].push(perCellDataForPlot.values[featureKey][i] as never); + }); } return { indices: indices, diff --git a/src/state/selection/types.ts b/src/state/selection/types.ts index 28751f86a..ab8e85d1f 100755 --- a/src/state/selection/types.ts +++ b/src/state/selection/types.ts @@ -10,15 +10,33 @@ export type DiscreteFilterData = { export type ContinuousFilterData = { discrete: false; + /** Min bound of the filter range, inclusive. */ min: number; + /** Max bound of the filter range, inclusive. */ max: number; }; +/** + * A user-selected filter, which excludes using string values for discrete data + * or with an (inclusive) range for continuous data. + */ export type FilterData = DiscreteFilterData | ContinuousFilterData; +/** + * A precomputed filter that can be applied directly to raw numeric feature + * values. + */ export type NumericFilter = { featureKey: string; + /** + * For some discrete feature data `data`, the ID `i` is excluded by the + * filter if `excludedLUT[data[i]] === true`. + */ excludedLUT?: boolean[]; + /** + * For some continuous feature data `data`, the ID `i` is excluded by the + * filter if `data[i] < range[0]` or `range[1] < data[i]`. + */ range?: [number, number]; }; diff --git a/src/state/util.ts b/src/state/util.ts index 11fcef1e8..de8570f85 100755 --- a/src/state/util.ts +++ b/src/state/util.ts @@ -3,8 +3,14 @@ import type { Action, Reducer } from "redux"; import { APP_ID, CELL_ID_KEY } from "../constants"; -import { DiscreteMeasuredFeatureDef, FileInfo, MeasuredFeatureDef } from "./metadata/types"; +import { + DataForPlot, + DiscreteMeasuredFeatureDef, + FileInfo, + MeasuredFeatureDef, +} from "./metadata/types"; import { BatchedAction, TypeToDescriptionMap } from "./types"; +import { FilterData, NumericFilter } from "./selection/types"; const HTTP_REGEX = /^https?:\/\//; @@ -137,3 +143,76 @@ export function sortNumeric(arr: T[], toString: (item: T) => string): T[] { arr.sort((a, b) => collator.compare(toString(a), toString(b))); return arr; } + +/** + * Transforms a FilterData object into a NumericFilter object based on the + * feature definition, which can be compared against raw (numeric) feature + * values. + */ +export const getNumericFilterFromFeature = ( + featureDef: MeasuredFeatureDef, + filter: FilterData | undefined +): NumericFilter | undefined => { + if (!filter) { + return undefined; + } + if (featureDef.discrete && filter.discrete) { + // For discrete features, values are marked as excluded based on the + // string value, but the actual feature data is stored as an integer. + // Precompute a lookup table using the string options, so we can + // directly look up values by their integer index. + const orderedValues = Object.values(featureDef.options).map( + (option) => option.key ?? option.name + ); + const excludedLUT = orderedValues.map((value) => filter.excluded.has(value)); + return { + featureKey: featureDef.key, + excludedLUT, + }; + } else if (!featureDef.discrete && !filter.discrete) { + return { + featureKey: featureDef.key, + range: [filter.min, filter.max], + }; + } else { + console.error( + `Feature '${featureDef.displayName}' (key: '${featureDef.key}') type and filter type are mismatched and will be skipped.`, + featureDef, + filter + ); + return undefined; + } +}; + +/** + * Returns whether the specified cell index is excluded by the provided filters, + * using the current feature data. + * @param id The cell index to check for exclusion. + * @param cellData The current feature data for all cells. + * @param numericFilters The set of numeric filters to apply. + * @returns whether the cell is excluded by the provided filters. + */ +export function isIdExcludedByFilters( + id: number, + cellData: DataForPlot, + numericFilters: Map +): boolean { + let isExcluded = false; + for (const [featureKey, numericFilter] of numericFilters) { + const value = cellData.values[featureKey][id]; + if (numericFilter && value !== null) { + if (numericFilter.range !== undefined) { + if (value < numericFilter.range[0] || value > numericFilter.range[1]) { + isExcluded = true; + break; + } + } else if (numericFilter.excludedLUT) { + if (numericFilter.excludedLUT[value]) { + isExcluded = true; + break; + } + } + } + } + return isExcluded; +} From 6617c56773efff9272c2d8dd89ee041144134051 Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Fri, 30 Oct 2026 15:45:59 -0700 Subject: [PATCH 07/17] fix: Fix bug where indices were not being mapped correctly for numeric filters --- src/state/selection/types.ts | 4 ++-- src/state/util.ts | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/state/selection/types.ts b/src/state/selection/types.ts index ab8e85d1f..fbf598568 100755 --- a/src/state/selection/types.ts +++ b/src/state/selection/types.ts @@ -30,9 +30,9 @@ export type NumericFilter = { featureKey: string; /** * For some discrete feature data `data`, the ID `i` is excluded by the - * filter if `excludedLUT[data[i]] === true`. + * filter if `excludedIndices.has(data[i]) === true`. */ - excludedLUT?: boolean[]; + excludedIndices?: Set; /** * For some continuous feature data `data`, the ID `i` is excluded by the * filter if `data[i] < range[0]` or `range[1] < data[i]`. diff --git a/src/state/util.ts b/src/state/util.ts index de8570f85..b5a58501d 100755 --- a/src/state/util.ts +++ b/src/state/util.ts @@ -159,15 +159,21 @@ export const getNumericFilterFromFeature = ( if (featureDef.discrete && filter.discrete) { // For discrete features, values are marked as excluded based on the // string value, but the actual feature data is stored as an integer. - // Precompute a lookup table using the string options, so we can - // directly look up values by their integer index. - const orderedValues = Object.values(featureDef.options).map( + // Map the excluded string values to their corresponding integer + // indices. + const optionKeys = Object.keys(featureDef.options).map(Number); + const optionValues = Object.values(featureDef.options).map( (option) => option.key ?? option.name ); - const excludedLUT = orderedValues.map((value) => filter.excluded.has(value)); + const excludedIndices = new Set(); + for (let i = 0; i < optionKeys.length; i++) { + if (filter.excluded.has(optionValues[i])) { + excludedIndices.add(optionKeys[i]); + } + } return { featureKey: featureDef.key, - excludedLUT, + excludedIndices: excludedIndices, }; } else if (!featureDef.discrete && !filter.discrete) { return { @@ -206,8 +212,8 @@ export function isIdExcludedByFilters( isExcluded = true; break; } - } else if (numericFilter.excludedLUT) { - if (numericFilter.excludedLUT[value]) { + } else if (numericFilter.excludedIndices) { + if (numericFilter.excludedIndices.has(value)) { isExcluded = true; break; } From c5428ff2b30b94acc3b13869cbe879f8f1a02a85 Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Fri, 30 Oct 2026 16:05:11 -0700 Subject: [PATCH 08/17] refactor: Renamed variables for clarity --- src/containers/ColorByMenu/index.tsx | 18 +++++++++--------- src/containers/ColorByMenu/selectors.ts | 8 +++++--- .../MainPlotContainer/test/selectors.test.ts | 2 +- src/state/selection/types.ts | 13 +++++++------ src/state/util.ts | 4 ++-- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/containers/ColorByMenu/index.tsx b/src/containers/ColorByMenu/index.tsx index 7db46daad..468e52920 100644 --- a/src/containers/ColorByMenu/index.tsx +++ b/src/containers/ColorByMenu/index.tsx @@ -112,14 +112,14 @@ class ColorByMenu extends React.Component { public onBarClicked({ target }: CheckboxChangeEvent) { const { groupByFilter, groupBy, handleSetFilter: handleSetFeatureFilter } = this.props; - let filter = groupByFilter ?? { discrete: true, excluded: new Set() }; + let filter = groupByFilter ?? { discrete: true, excludedValues: new Set() }; // Toggle whether the category is excluded from the filter if (filter.discrete) { - filter = { ...filter, excluded: new Set(filter.excluded) }; + filter = { ...filter, excludedValues: new Set(filter.excludedValues) }; if (target.checked) { - filter.excluded.delete(target.value); + filter.excludedValues.delete(target.value); } else { - filter.excluded.add(target.value); + filter.excludedValues.add(target.value); } } handleSetFeatureFilter(groupBy.toString(), filter); @@ -148,14 +148,14 @@ class ColorByMenu extends React.Component { handleSetFilter: handleSetFeatureFilter, interactivePanelData, } = this.props; - let filter = groupByFilter ?? { discrete: true, excluded: new Set() }; + let filter = groupByFilter ?? { discrete: true, excludedValues: new Set() }; if (filter.discrete) { - filter = { ...filter, excluded: new Set(filter.excluded) }; + filter = { ...filter, excludedValues: new Set(filter.excludedValues) }; if (target.checked) { - filter.excluded.clear(); + filter.excludedValues.clear(); } else { const keys = interactivePanelData.map((ele: PanelData) => ele.id); - keys.forEach((key) => filter?.excluded.add(key)); + keys.forEach((key) => filter?.excludedValues.add(key)); } } handleSetFeatureFilter(groupBy.toString(), filter); @@ -282,7 +282,7 @@ class ColorByMenu extends React.Component {
Show/Hide all diff --git a/src/containers/ColorByMenu/selectors.ts b/src/containers/ColorByMenu/selectors.ts index bd453455c..5f3dc3526 100644 --- a/src/containers/ColorByMenu/selectors.ts +++ b/src/containers/ColorByMenu/selectors.ts @@ -71,9 +71,11 @@ export const getGroupByTitle = createSelector( export const getCheckAllCheckboxIsIntermediate = createSelector( [getGroupByFilter, getGroupingCategoryNames], (groupByFilter, categoryNames: string[]): boolean => { - const excluded = groupByFilter?.excluded; + const excludedValues = groupByFilter?.excludedValues; return ( - excluded !== undefined && excluded.size > 0 && excluded.size !== categoryNames.length + excludedValues !== undefined && + excludedValues.size > 0 && + excludedValues.size !== categoryNames.length ); } ); @@ -175,7 +177,7 @@ export const getInteractivePanelData = createSelector( const id = category.key ?? category.name; const total: number = countsByCategory[id] || category.count || 0; const disabled = !displayableGroups.includes(id); - const excluded = groupByFilter?.excluded.has(id) ?? false; + const excluded = groupByFilter?.excludedValues.has(id) ?? false; const color = getColorForCategory( categoryToColorBy === categoryToGroupBy, excluded, diff --git a/src/containers/MainPlotContainer/test/selectors.test.ts b/src/containers/MainPlotContainer/test/selectors.test.ts index 5d65aff33..dafb55a92 100644 --- a/src/containers/MainPlotContainer/test/selectors.test.ts +++ b/src/containers/MainPlotContainer/test/selectors.test.ts @@ -81,7 +81,7 @@ describe("MainPlotContainer selectors", () => { newMockState.selection.groupBy, { discrete: true, - excluded: new Set(["Paxillin"]), + excludedValues: new Set(["Paxillin"]), }, ], ]), diff --git a/src/state/selection/types.ts b/src/state/selection/types.ts index fbf598568..181f72146 100755 --- a/src/state/selection/types.ts +++ b/src/state/selection/types.ts @@ -5,20 +5,21 @@ import type { FileInfo } from "../metadata/types"; export type DiscreteFilterData = { discrete: true; - excluded: Set; + excludedValues: Set; }; export type ContinuousFilterData = { discrete: false; - /** Min bound of the filter range, inclusive. */ - min: number; - /** Max bound of the filter range, inclusive. */ - max: number; + /** Inclusive range for the filter. */ + range: [number, number]; }; /** - * A user-selected filter, which excludes using string values for discrete data + * A filter on a feature, which excludes using string values for discrete data * or with an (inclusive) range for continuous data. + * + * Can be parsed as a `NumericFilter` for applying against raw numeric feature + * data. */ export type FilterData = DiscreteFilterData | ContinuousFilterData; diff --git a/src/state/util.ts b/src/state/util.ts index b5a58501d..fed11748e 100755 --- a/src/state/util.ts +++ b/src/state/util.ts @@ -167,7 +167,7 @@ export const getNumericFilterFromFeature = ( ); const excludedIndices = new Set(); for (let i = 0; i < optionKeys.length; i++) { - if (filter.excluded.has(optionValues[i])) { + if (filter.excludedValues.has(optionValues[i])) { excludedIndices.add(optionKeys[i]); } } @@ -178,7 +178,7 @@ export const getNumericFilterFromFeature = ( } else if (!featureDef.discrete && !filter.discrete) { return { featureKey: featureDef.key, - range: [filter.min, filter.max], + range: filter.range, }; } else { console.error( From dd98158536be94ce2a89b7b35e551db1f5af8707 Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Fri, 30 Oct 2026 16:09:29 -0700 Subject: [PATCH 09/17] fix: Linting --- src/state/selection/logics.ts | 1 - src/state/selection/reducer.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/state/selection/logics.ts b/src/state/selection/logics.ts index e6a8bbaaf..c14c576cd 100755 --- a/src/state/selection/logics.ts +++ b/src/state/selection/logics.ts @@ -38,7 +38,6 @@ import { SelectPointAction, SyncStateWithURLAction, } from "./types"; -import { makeAnnotations } from "../../containers/MainPlotContainer/selectors"; const syncStateWithUrl = createLogic({ type: SYNC_STATE_WITH_URL, diff --git a/src/state/selection/reducer.ts b/src/state/selection/reducer.ts index 33b0eea78..5445442f5 100755 --- a/src/state/selection/reducer.ts +++ b/src/state/selection/reducer.ts @@ -387,7 +387,7 @@ const actionToConfigMap: TypeToDescriptionMap = { }, [CLEAR_FILTERS]: { accepts: (action: Action): action is ClearFiltersAction => action.type === CLEAR_FILTERS, - perform: (state: SelectionStateBranch, action: ClearFiltersAction) => ({ + perform: (state: SelectionStateBranch, _action: ClearFiltersAction) => ({ ...state, filters: new Map(), activeFilters: new Set(), From de2da365f68221bcdb94f5407eac4417daa36246 Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Fri, 30 Oct 2026 16:19:13 -0700 Subject: [PATCH 10/17] fix: Linting --- src/state/selection/reducer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/state/selection/reducer.ts b/src/state/selection/reducer.ts index 5445442f5..a9e82cefd 100755 --- a/src/state/selection/reducer.ts +++ b/src/state/selection/reducer.ts @@ -387,7 +387,7 @@ const actionToConfigMap: TypeToDescriptionMap = { }, [CLEAR_FILTERS]: { accepts: (action: Action): action is ClearFiltersAction => action.type === CLEAR_FILTERS, - perform: (state: SelectionStateBranch, _action: ClearFiltersAction) => ({ + perform: (state: SelectionStateBranch) => ({ ...state, filters: new Map(), activeFilters: new Set(), From c68e3f04e5a49c6604e78f5f3e6c1e59221c53aa Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Mon, 2 Nov 2026 11:58:13 -0800 Subject: [PATCH 11/17] fix: Handle missing values when filtering --- src/state/selection/types.ts | 2 +- src/state/util.ts | 33 +++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/state/selection/types.ts b/src/state/selection/types.ts index 181f72146..ac0d5b3f3 100755 --- a/src/state/selection/types.ts +++ b/src/state/selection/types.ts @@ -33,7 +33,7 @@ export type NumericFilter = { * For some discrete feature data `data`, the ID `i` is excluded by the * filter if `excludedIndices.has(data[i]) === true`. */ - excludedIndices?: Set; + excludedIndices?: Set; /** * For some continuous feature data `data`, the ID `i` is excluded by the * filter if `data[i] < range[0]` or `range[1] < data[i]`. diff --git a/src/state/util.ts b/src/state/util.ts index fed11748e..79e41c601 100755 --- a/src/state/util.ts +++ b/src/state/util.ts @@ -11,6 +11,11 @@ import { } from "./metadata/types"; import { BatchedAction, TypeToDescriptionMap } from "./types"; import { FilterData, NumericFilter } from "./selection/types"; +import { + MISSING_CATEGORY_COLOR, + MISSING_CATEGORY_KEY, + MISSING_CATEGORY_LABEL, +} from "./selection/constants"; const HTTP_REGEX = /^https?:\/\//; @@ -161,11 +166,24 @@ export const getNumericFilterFromFeature = ( // string value, but the actual feature data is stored as an integer. // Map the excluded string values to their corresponding integer // indices. - const optionKeys = Object.keys(featureDef.options).map(Number); - const optionValues = Object.values(featureDef.options).map( + const featureOptions = { ...featureDef.options }; + if (filter.excludedValues.has(MISSING_CATEGORY_KEY)) { + featureOptions[MISSING_CATEGORY_KEY] = { + key: MISSING_CATEGORY_KEY, + name: MISSING_CATEGORY_LABEL, + color: MISSING_CATEGORY_COLOR, + }; + } + const optionKeys = Object.keys(featureOptions).map((key) => { + if (key === MISSING_CATEGORY_KEY) { + return null; + } + return Number.parseInt(key); + }); + const optionValues = Object.values(featureOptions).map( (option) => option.key ?? option.name ); - const excludedIndices = new Set(); + const excludedIndices = new Set(); for (let i = 0; i < optionKeys.length; i++) { if (filter.excludedValues.has(optionValues[i])) { excludedIndices.add(optionKeys[i]); @@ -206,9 +224,12 @@ export function isIdExcludedByFilters( let isExcluded = false; for (const [featureKey, numericFilter] of numericFilters) { const value = cellData.values[featureKey][id]; - if (numericFilter && value !== null) { - if (numericFilter.range !== undefined) { - if (value < numericFilter.range[0] || value > numericFilter.range[1]) { + if (numericFilter) { + if (numericFilter.range) { + if (value === undefined || value === null) { + isExcluded = true; + break; + } else if (value < numericFilter.range[0] || value > numericFilter.range[1]) { isExcluded = true; break; } From 3504becc2b04e57717753c270547e5df3c51d8a4 Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Mon, 2 Nov 2026 12:07:34 -0800 Subject: [PATCH 12/17] fix: Skip computation when no filters are used --- src/state/selection/selectors.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/state/selection/selectors.ts b/src/state/selection/selectors.ts index 113c927c3..3fd583987 100755 --- a/src/state/selection/selectors.ts +++ b/src/state/selection/selectors.ts @@ -436,6 +436,23 @@ export const getFilteredCellData = createSelector( groupingNames, numericFilters ): DataForPlot => { + const hasNoFilters = + numericFilters.size === 0 || + Array.from(numericFilters.values()).every( + (filter) => + filter === undefined || + (filter.range && filter.range[0] === filter.range[1]) || + (filter.excludedIndices && filter.excludedIndices.size === 0) + ); + if (hasNoFilters) { + return { + ...perCellDataForPlot, + labels: { + ...perCellDataForPlot.labels, + [categoryKey]: groupingNames, + }, + }; + } const categoryNameArray: string[] = []; const dataToReturn: MappingOfMeasuredValuesArrays = {}; const cellIds: string[] = []; From 87eb759442a8bb7ac0572d829d0189ddd4e68646 Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Mon, 2 Nov 2026 12:14:20 -0800 Subject: [PATCH 13/17] fix: Range check, handle undefined values --- src/state/selection/selectors.ts | 8 ++++++-- src/state/util.ts | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/state/selection/selectors.ts b/src/state/selection/selectors.ts index 3fd583987..949d91a21 100755 --- a/src/state/selection/selectors.ts +++ b/src/state/selection/selectors.ts @@ -387,7 +387,11 @@ export const getColorByCategoryCounts = createSelector( export const getGroupByFilter = createSelector( [getFilters, getGroupByCategory], (filters, groupByCategory): DiscreteFilterData | undefined => { - return filters.get(groupByCategory) as DiscreteFilterData; + const groupByFilter = filters.get(groupByCategory); + if (!groupByFilter || !groupByFilter.discrete) { + return undefined; + } + return groupByFilter; } ); @@ -441,7 +445,7 @@ export const getFilteredCellData = createSelector( Array.from(numericFilters.values()).every( (filter) => filter === undefined || - (filter.range && filter.range[0] === filter.range[1]) || + (!filter.range && !filter.excludedIndices) || (filter.excludedIndices && filter.excludedIndices.size === 0) ); if (hasNoFilters) { diff --git a/src/state/util.ts b/src/state/util.ts index 79e41c601..5747bdcab 100755 --- a/src/state/util.ts +++ b/src/state/util.ts @@ -223,10 +223,10 @@ export function isIdExcludedByFilters( ): boolean { let isExcluded = false; for (const [featureKey, numericFilter] of numericFilters) { - const value = cellData.values[featureKey][id]; + const value = cellData.values[featureKey][id] ?? null; if (numericFilter) { if (numericFilter.range) { - if (value === undefined || value === null) { + if (value === null) { isExcluded = true; break; } else if (value < numericFilter.range[0] || value > numericFilter.range[1]) { From 1180175e79d418dd50f4729e980f1a58fd8adeb3 Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Mon, 2 Nov 2026 12:39:49 -0800 Subject: [PATCH 14/17] refactor: Remove unused props, remove duplicate logic --- src/containers/ColorByMenu/index.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/containers/ColorByMenu/index.tsx b/src/containers/ColorByMenu/index.tsx index 468e52920..caa4add29 100644 --- a/src/containers/ColorByMenu/index.tsx +++ b/src/containers/ColorByMenu/index.tsx @@ -59,7 +59,6 @@ interface PropsFromState { downloadUrls: string[]; downloadConfig: DownloadConfig; downloadRoot: string; - filters: Map; groupByFilter: DiscreteFilterData | undefined; interactivePanelData: PanelData[]; selectionSetsPanelData: PanelData[]; @@ -110,12 +109,17 @@ class ColorByMenu extends React.Component { this.onSelectionSetDownloadButtonClicked.bind(this); } + private getDiscreteFilterCopy(filter: DiscreteFilterData | undefined): DiscreteFilterData { + return filter + ? { ...filter, excludedValues: new Set(filter.excludedValues) } + : { discrete: true, excludedValues: new Set() }; + } + public onBarClicked({ target }: CheckboxChangeEvent) { const { groupByFilter, groupBy, handleSetFilter: handleSetFeatureFilter } = this.props; - let filter = groupByFilter ?? { discrete: true, excludedValues: new Set() }; + let filter = this.getDiscreteFilterCopy(groupByFilter); // Toggle whether the category is excluded from the filter if (filter.discrete) { - filter = { ...filter, excludedValues: new Set(filter.excludedValues) }; if (target.checked) { filter.excludedValues.delete(target.value); } else { @@ -148,9 +152,8 @@ class ColorByMenu extends React.Component { handleSetFilter: handleSetFeatureFilter, interactivePanelData, } = this.props; - let filter = groupByFilter ?? { discrete: true, excludedValues: new Set() }; + let filter = this.getDiscreteFilterCopy(groupByFilter); if (filter.discrete) { - filter = { ...filter, excludedValues: new Set(filter.excludedValues) }; if (target.checked) { filter.excludedValues.clear(); } else { @@ -373,7 +376,6 @@ function mapStateToProps(state: State): PropsFromState { downloadConfig: selectionStateBranch.selectors.getDownloadConfig(state), downloadUrls: createUrlFromListOfIds(state), downloadRoot: getDownloadRoot(state), - filters: selectionStateBranch.selectors.getFilters(state), groupByFilter: selectionStateBranch.selectors.getGroupByFilter(state), groupByTitle: getGroupByTitle(state), interactivePanelData: getInteractivePanelData(state), From 599918df984522ec3c0fddd8513ba1ee96691c6e Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Mon, 2 Nov 2026 12:50:36 -0800 Subject: [PATCH 15/17] refactor: Cleanup handling for null values --- src/state/util.ts | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/state/util.ts b/src/state/util.ts index 5747bdcab..afff64680 100755 --- a/src/state/util.ts +++ b/src/state/util.ts @@ -163,30 +163,26 @@ export const getNumericFilterFromFeature = ( } if (featureDef.discrete && filter.discrete) { // For discrete features, values are marked as excluded based on the - // string value, but the actual feature data is stored as an integer. - // Map the excluded string values to their corresponding integer - // indices. + // string key, but the actual feature data is stored as an integer. Map + // the excluded string values to their corresponding integer value. const featureOptions = { ...featureDef.options }; - if (filter.excludedValues.has(MISSING_CATEGORY_KEY)) { - featureOptions[MISSING_CATEGORY_KEY] = { - key: MISSING_CATEGORY_KEY, - name: MISSING_CATEGORY_LABEL, - color: MISSING_CATEGORY_COLOR, - }; - } - const optionKeys = Object.keys(featureOptions).map((key) => { - if (key === MISSING_CATEGORY_KEY) { - return null; - } - return Number.parseInt(key); - }); - const optionValues = Object.values(featureOptions).map( + const optionValues: (number | null)[] = Object.keys(featureOptions).map((key) => + Number.parseInt(key) + ); + const optionStringKey = Object.values(featureOptions).map( (option) => option.key ?? option.name ); + + // In the data, missing values are represented as `null`. If the user is + // filtering out missing values (MISSING_CATEGORY_KEY), + // `excludedIndices` will include `null`. + optionStringKey.push(MISSING_CATEGORY_KEY); + optionValues.push(null); + const excludedIndices = new Set(); - for (let i = 0; i < optionKeys.length; i++) { - if (filter.excludedValues.has(optionValues[i])) { - excludedIndices.add(optionKeys[i]); + for (let i = 0; i < optionValues.length; i++) { + if (filter.excludedValues.has(optionStringKey[i])) { + excludedIndices.add(optionValues[i]); } } return { From 6c335cfc268b5784e4cecaa8a1b670c7b22f97b3 Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Mon, 2 Nov 2026 12:51:06 -0800 Subject: [PATCH 16/17] fix: Linting --- src/containers/ColorByMenu/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/containers/ColorByMenu/index.tsx b/src/containers/ColorByMenu/index.tsx index caa4add29..fa9a681f2 100644 --- a/src/containers/ColorByMenu/index.tsx +++ b/src/containers/ColorByMenu/index.tsx @@ -117,7 +117,7 @@ class ColorByMenu extends React.Component { public onBarClicked({ target }: CheckboxChangeEvent) { const { groupByFilter, groupBy, handleSetFilter: handleSetFeatureFilter } = this.props; - let filter = this.getDiscreteFilterCopy(groupByFilter); + const filter = this.getDiscreteFilterCopy(groupByFilter); // Toggle whether the category is excluded from the filter if (filter.discrete) { if (target.checked) { @@ -152,7 +152,7 @@ class ColorByMenu extends React.Component { handleSetFilter: handleSetFeatureFilter, interactivePanelData, } = this.props; - let filter = this.getDiscreteFilterCopy(groupByFilter); + const filter = this.getDiscreteFilterCopy(groupByFilter); if (filter.discrete) { if (target.checked) { filter.excludedValues.clear(); From d8e401e5e17f5271b1b22a98254fb750f39f30fd Mon Sep 17 00:00:00 2001 From: Peyton Lee Date: Mon, 2 Nov 2026 13:44:51 -0800 Subject: [PATCH 17/17] fix: Linting --- src/containers/ColorByMenu/index.tsx | 1 - src/state/util.ts | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/containers/ColorByMenu/index.tsx b/src/containers/ColorByMenu/index.tsx index fa9a681f2..8f8f8a217 100644 --- a/src/containers/ColorByMenu/index.tsx +++ b/src/containers/ColorByMenu/index.tsx @@ -27,7 +27,6 @@ import { DeselectGroupOfPointsAction, DiscreteFilterData, DownloadConfig, - FilterData, SelectAxisAction, SetColorOverrideAction, SetFilterAction, diff --git a/src/state/util.ts b/src/state/util.ts index afff64680..da8db71f1 100755 --- a/src/state/util.ts +++ b/src/state/util.ts @@ -12,9 +12,7 @@ import { import { BatchedAction, TypeToDescriptionMap } from "./types"; import { FilterData, NumericFilter } from "./selection/types"; import { - MISSING_CATEGORY_COLOR, - MISSING_CATEGORY_KEY, - MISSING_CATEGORY_LABEL, + MISSING_CATEGORY_KEY } from "./selection/constants"; const HTTP_REGEX = /^https?:\/\//;