From 8af83513056b25d6bc8704cc89256c4b2ecdfdba Mon Sep 17 00:00:00 2001 From: Nate Lanza Date: Fri, 8 Nov 2024 00:12:34 -0700 Subject: [PATCH] Non-functional UI for plot removal --- packages/core/src/typeutils.ts | 14 ++++- .../ElementView/ElementVisualization.tsx | 56 ++++++++++++++++++- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/packages/core/src/typeutils.ts b/packages/core/src/typeutils.ts index 9449a3e6..57a5f598 100644 --- a/packages/core/src/typeutils.ts +++ b/packages/core/src/typeutils.ts @@ -1,6 +1,7 @@ +import { isHistogram, isScatterplot } from './typecheck'; import { Aggregate, - Aggregates, Bookmark, BookmarkedIntersection, ElementBookmark, ElementQuery, NumericalBookmark, NumericalQuery, Row, Rows, SetMembershipStatus, Subset, Subsets, + Aggregates, Bookmark, BookmarkedIntersection, ElementBookmark, ElementQuery, NumericalBookmark, NumericalQuery, Plot, Row, Rows, SetMembershipStatus, Subset, Subsets, } from './types'; import { hashString } from './utils'; @@ -173,3 +174,14 @@ export function getBelongingSetsFromSetMembership(membership: { .filter((mem) => mem[1] === 'Yes') .map((mem) => mem[0]); } + +/** + * Converts a plot to a displable string + * @param plot Plot to convert. + * @returns Display string with type & axis of plot + */ +export function plotToString(plot: Plot): string { + if (isScatterplot(plot)) return `Scatterplot: ${plot.x} by ${plot.y}`; + if (isHistogram(plot)) return `Histogram: ${plot.attribute}`; + throw Error(`Cannot convert plot ${plot} to string`); +} diff --git a/packages/upset/src/components/ElementView/ElementVisualization.tsx b/packages/upset/src/components/ElementView/ElementVisualization.tsx index 07d94478..acd3ce86 100644 --- a/packages/upset/src/components/ElementView/ElementVisualization.tsx +++ b/packages/upset/src/components/ElementView/ElementVisualization.tsx @@ -6,8 +6,16 @@ import { import { SignalListener, VegaLite } from 'react-vega'; import { useRecoilValue } from 'recoil'; -import { numericalQueryToBookmark, numericalQueriesEqual, isNumericalQuery } from '@visdesignlab/upset2-core'; -import { Alert, Button } from '@mui/material'; +import { + numericalQueryToBookmark, numericalQueriesEqual, isNumericalQuery, + Plot, + plotToString, +} from '@visdesignlab/upset2-core'; +import { + Alert, Button, FormControl, IconButton, InputLabel, MenuItem, Select, +} from '@mui/material'; +import CheckIcon from '@mui/icons-material/Check'; +import CloseIcon from '@mui/icons-material/Close'; import { bookmarkSelector, currentIntersectionSelector, elementColorSelector } from '../../atoms/config/currentIntersectionAtom'; import { histogramSelector, scatterplotsSelector } from '../../atoms/config/plotAtoms'; import { currentNumericalQuery, elementsInBookmarkSelector } from '../../atoms/elementsSelectors'; @@ -16,6 +24,14 @@ import { generateVega } from './generatePlotSpec'; import { ProvenanceContext } from '../Root'; import { UpsetActions } from '../../provenance'; +/** + * The current interaction phase of the user removing a plot. + * Determines what to display in the remove plot button's area. + * false corresponds to no selection; displays the remove plot button + * true corresponds to selecting & confirming a plot; displays a select & confirm/cancel buttons + */ +type RemovePhase = boolean; + /** * Displays a matrix of plots representing the elements in the current intersection selection & bookmarks. * @returns @@ -26,6 +42,8 @@ export const ElementVisualization = () => { */ const [openAddPlot, setOpenAddPlot] = useState(false); + const [removeState, setRemoveState] = useState(false); + const scatterplots = useRecoilValue(scatterplotsSelector); const histograms = useRecoilValue(histogramSelector); const bookmarked = useRecoilValue(bookmarkSelector); @@ -88,7 +106,38 @@ export const ElementVisualization = () => { draftSelection.current = undefined; }} > - +
+ + {!removeState && + ()} + + {removeState && ( + <> + + Select Plot to Remove + + + console.log('remove')}> + + + console.log('remove')}> + + + + )} +
+ {!currentIntersection && bookmarked.length === 0 && ( { Currently visualizing all elements. Clicking on an intersection will visualize only its elements. )} + {(scatterplots.length > 0 || histograms.length > 0) && (