Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 40 additions & 18 deletions src/containers/ColorByMenu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Checkbox, Col, Collapse, Row } from "antd";
import { CheckboxChangeEvent } from "antd/es/checkbox";
import { filter, includes } from "lodash";
import { includes } from "lodash";
import React from "react";
import { connect } from "react-redux";
import type { ActionCreator } from "redux";
Expand All @@ -23,12 +23,13 @@ import {
BoolToggleAction,
ChangeDownloadConfigAction,
ChangeGroupByCategory,
ChangeSelectionAction,
ColorForPlot,
DeselectGroupOfPointsAction,
DiscreteFilterData,
DownloadConfig,
SelectAxisAction,
SetColorOverrideAction,
SetFilterAction,
} from "../../state/selection/types";
import { State } from "../../state/types";
import { getColorByDisplayOptions, getGroupByDisplayOptions } from "../MainPlotContainer/selectors";
Expand Down Expand Up @@ -57,7 +58,7 @@ interface PropsFromState {
downloadUrls: string[];
downloadConfig: DownloadConfig;
downloadRoot: string;
filtersToExclude: string[];
groupByFilter: DiscreteFilterData | undefined;
interactivePanelData: PanelData[];
selectionSetsPanelData: PanelData[];
isInIndeterminateState: boolean;
Expand All @@ -74,7 +75,7 @@ interface DispatchProps {
handleChangeAxis: ActionCreator<SelectAxisAction>;
handleChangeGroupByCategory: ActionCreator<ChangeGroupByCategory>;
handleCloseSelectionSet: ActionCreator<DeselectGroupOfPointsAction>;
handleFilterByCategoryName: ActionCreator<ChangeSelectionAction>;
handleSetFilter: ActionCreator<SetFilterAction>;
handleChangeDownloadSettings: ActionCreator<ChangeDownloadConfigAction>;
handleSetColorOverride: ActionCreator<SetColorOverrideAction>;
}
Expand Down Expand Up @@ -107,12 +108,24 @@ class ColorByMenu extends React.Component<ColorByMenuProps> {
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 { handleFilterByCategoryName, filtersToExclude } = this.props;
const newFilterList = includes(filtersToExclude, target.value)
? filter(filtersToExclude, (e) => e !== target.value)
: [...filtersToExclude, target.value];
handleFilterByCategoryName(newFilterList);
const { groupByFilter, groupBy, handleSetFilter: handleSetFeatureFilter } = this.props;
const filter = this.getDiscreteFilterCopy(groupByFilter);
// Toggle whether the category is excluded from the filter
if (filter.discrete) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: when would filter.discrete be false? given line 114, looks like this if would always be true right?

if (target.checked) {
filter.excludedValues.delete(target.value);
} else {
filter.excludedValues.add(target.value);
}
}
handleSetFeatureFilter(groupBy.toString(), filter);
}

public onCategorySetDownloadButtonClicked(categoryName: string) {
Expand All @@ -132,12 +145,22 @@ class ColorByMenu extends React.Component<ColorByMenuProps> {
}

public allOnOff({ target }: CheckboxChangeEvent) {
const { handleFilterByCategoryName, interactivePanelData } = this.props;
if (target.checked) {
return handleFilterByCategoryName([]);
const {
groupByFilter,
groupBy,
handleSetFilter: handleSetFeatureFilter,
interactivePanelData,
} = this.props;
const filter = this.getDiscreteFilterCopy(groupByFilter);
if (filter.discrete) {
if (target.checked) {
filter.excludedValues.clear();
} else {
const keys = interactivePanelData.map((ele: PanelData) => ele.id);
keys.forEach((key) => filter?.excludedValues.add(key));
}
}
const keys = interactivePanelData.map((ele: PanelData) => ele.id);
handleFilterByCategoryName(keys);
handleSetFeatureFilter(groupBy.toString(), filter);
}

public onActivePanelChange(value: string | string[]) {
Expand Down Expand Up @@ -205,7 +228,6 @@ class ColorByMenu extends React.Component<ColorByMenuProps> {

public renderTaggedStructuresPanel() {
const {
filtersToExclude,
isInIndeterminateState,
interactivePanelData,
downloadUrls,
Expand Down Expand Up @@ -262,7 +284,7 @@ class ColorByMenu extends React.Component<ColorByMenuProps> {
<div className={styles.interactiveLegendHeader}>
<Checkbox
indeterminate={isInIndeterminateState}
checked={filtersToExclude.length === 0}
checked={(this.props.groupByFilter?.excludedValues.size ?? 0) === 0}
onChange={this.allOnOff}
>
Show/Hide all
Expand Down Expand Up @@ -353,7 +375,7 @@ function mapStateToProps(state: State): PropsFromState {
downloadConfig: selectionStateBranch.selectors.getDownloadConfig(state),
downloadUrls: createUrlFromListOfIds(state),
downloadRoot: getDownloadRoot(state),
filtersToExclude: selectionStateBranch.selectors.getFiltersToExclude(state),
groupByFilter: selectionStateBranch.selectors.getGroupByFilter(state),
groupByTitle: getGroupByTitle(state),
interactivePanelData: getInteractivePanelData(state),
selectionSetsPanelData: getSelectionPanelData(state),
Expand All @@ -367,7 +389,7 @@ const dispatchToPropsMap: DispatchProps = {
handleChangeGroupByCategory: selectionStateBranch.actions.changeGroupByCategory,
handleChangeDownloadSettings: selectionStateBranch.actions.changeDownloadSettings,
handleCloseSelectionSet: selectionStateBranch.actions.deselectGroupOfPoints,
handleFilterByCategoryName: selectionStateBranch.actions.toggleFilterByCategoryName,
handleSetFilter: selectionStateBranch.actions.setFilter,
handleSetColorOverride: selectionStateBranch.actions.setColorOverride,
};
export default connect<PropsFromState, DispatchProps, PropsFromApp, State>(
Expand Down
30 changes: 20 additions & 10 deletions src/containers/ColorByMenu/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { chunk, includes, map, reduce, values } from "lodash";
import { chunk, map, reduce, values } from "lodash";
import { createSelector } from "reselect";

import {
Expand All @@ -23,7 +23,6 @@ import {
getColorBySelection,
getDownloadConfig,
getDownloadRoot,
getFiltersToExclude,
getSelectedGroupKeys,
getSelectedGroups,
getSelectedSetTotals,
Expand All @@ -37,8 +36,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";
Expand All @@ -65,9 +69,14 @@ 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 excludedValues = groupByFilter?.excludedValues;
return (
excludedValues !== undefined &&
excludedValues.size > 0 &&
excludedValues.size !== categoryNames.length
);
Comment on lines +72 to +79

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think there may be a tiny bug here where unselecting all options except N/A shows the checkbox in as unchecked instead of indeterminate.

I think #322 addresses it and we can resolve merge conflicts as one or the other branch goes through, don't consider it blocking.

}
);

Expand Down Expand Up @@ -126,7 +135,7 @@ export const getInteractivePanelData = createSelector(
getGroupByCategory,
getColorBySelection,
getGroupByFeatureOptionsAsList,
getFiltersToExclude,
getGroupByFilter,
getDisplayableGroups,
getGroupingCategoryNamesAsArray,
getColorOverrides,
Expand All @@ -135,7 +144,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)[]
Expand Down Expand Up @@ -168,15 +177,16 @@ 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?.excludedValues.has(id) ?? false;
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],
Expand Down
9 changes: 8 additions & 1 deletion src/containers/ColorByMenu/style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@

.feature-select-row :global(.ant-select) {
width: 100%;
}
}

/* Make intermediate checkbox visible */
.interactive-legend-container
:global(.ant-checkbox.ant-checkbox-indeterminate)
> :global(.ant-checkbox-inner)::after {
background-color: var(--dimgray);
}
Comment on lines +39 to +44

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixes a bug where this checkbox was too low contrast and couldn't be seen.

9 changes: 2 additions & 7 deletions src/containers/MainPlotContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ interface PropsFromState {
annotations: PlotlyAnnotation[];
categoricalFeatures: string[];
clickedPoints: string[];
filtersToExclude: string[];
galleryCollapsed: boolean;
hoveredPointData: SelectedPointData | null;
hoveredXValue: string;
Expand Down Expand Up @@ -188,17 +187,14 @@ class MainPlotContainer extends React.Component<MainPlotContainerProps, MainPlot
// TODO: retype once plotly has id and fullData types
public onPointHovered(hovered: any) {
const { points, event } = hovered;
const { filtersToExclude, updateMousePosition, changeHoveredPoint } = this.props;
const { updateMousePosition, changeHoveredPoint } = this.props;
updateMousePosition({
pageX: event.pageX,
pageY: event.pageY,
});

points.forEach((point: any) => {
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,
Expand Down Expand Up @@ -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),
Expand Down
12 changes: 5 additions & 7 deletions src/containers/MainPlotContainer/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ import {
getLineMovingAverageWindow,
getConnectByFeature,
getConnectByCategory,
getFiltersToExclude,
getNumericFilters,
} from "../../state/selection/selectors";
import { isIdExcludedByFilters } from "../../state/util";
import {
ColorForPlot,
MainPlotSettings,
Expand Down Expand Up @@ -296,19 +297,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)) {
Expand All @@ -332,8 +331,7 @@ const getAnnotationData = createSelector(
const y = allCellData.values[yAxis][pointIndex] ?? null;

// Apply filtering
const groupName = groupByCategoryNames[pointIndex] ?? null;
if (filtersToExclude.includes(groupName)) {
if (isIdExcludedByFilters(pointIndex, allCellData, numericFilters)) {
return acc;
}

Expand Down
12 changes: 10 additions & 2 deletions src/containers/MainPlotContainer/test/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string, FilterData>([
[
newMockState.selection.groupBy,
{
discrete: true,
excludedValues: new Set(["Paxillin"]),
},
],
]),
},
};
const result: PlotlyAnnotation[] = getAnnotations(state);
Expand Down
Loading
Loading