Skip to content

Commit

Permalink
Deselect the current intersection when the plot is clicked somewhere …
Browse files Browse the repository at this point in the history
…that causes no other action
  • Loading branch information
Nate Lanza committed Nov 14, 2024
1 parent a04be44 commit 85cccee
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/upset/src/components/Header/AttributeButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useContext } from 'react';
import React, { FC, useContext } from 'react';
import { useSetRecoilState, useRecoilValue } from 'recoil';
import { SortByOrder, AttributePlotType } from '@visdesignlab/upset2-core';

Expand Down Expand Up @@ -63,12 +63,14 @@ export const AttributeButton: FC<Props> = ({ label, tooltip }) => {
* If the attribute is not currently sorted, it sorts it in ascending order.
* If the attribute is already sorted, it toggles between ascending and descending order.
*/
const handleOnClick = () => {
const handleOnClick = (e: React.MouseEvent<SVGElement>) => {
if (sortBy !== label) {
sortByHeader('Ascending');
} else {
sortByHeader(sortByOrder === 'Ascending' ? 'Descending' : 'Ascending');
}
// To prevent the handler on SvgBase that deselects the current intersection
e.stopPropagation();
};

/**
Expand Down
6 changes: 4 additions & 2 deletions packages/upset/src/components/Header/DegreeHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { css } from '@emotion/react';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { useContext } from 'react';
import React, { useContext } from 'react';
import { Tooltip } from '@mui/material';
import { sortByOrderSelector, sortBySelector } from '../../atoms/config/sortByAtom';
import translate from '../../utils/transform';
Expand All @@ -23,12 +23,14 @@ export const DegreeHeader = () => {
actions.sortBy('Degree', order);
};

const handleOnClick = () => {
const handleOnClick = (e: React.MouseEvent<SVGElement>) => {
if (sortBy !== 'Degree') {
sortByDegree('Ascending');
} else {
sortByDegree(sortByOrder === 'Ascending' ? 'Descending' : 'Ascending');
}
// To prevent the handler on SvgBase that deselects the current intersection
e.stopPropagation();
};

const handleContextMenuClose = () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/upset/src/components/Header/SizeHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { css } from '@emotion/react';
import { drag } from 'd3-drag';
import { select } from 'd3-selection';
import {
import React, {
FC, useContext, useEffect, useRef, useState,
} from 'react';
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
Expand Down Expand Up @@ -51,12 +51,14 @@ export const SizeHeader: FC = () => {
actions.sortBy('Size', order);
};

const handleOnClick = () => {
const handleOnClick = (e: React.MouseEvent<SVGElement>) => {
if (sortBy !== 'Size') {
sortBySize('Ascending');
} else {
sortBySize(sortByOrder === 'Ascending' ? 'Descending' : 'Ascending');
}
// To prevent the handler on SvgBase that deselects the current intersection
e.stopPropagation();
};

const handleContextMenuClose = () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/upset/src/components/Rows/AggregateRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SvgIcon from '@mui/material/SvgIcon';

import { visibleSetSelector } from '../../atoms/config/visibleSetsAtoms';
import { dimensionsSelector } from '../../atoms/dimensionsAtom';
import { bookmarkSelector, currentIntersectionSelector } from '../../atoms/config/currentIntersectionAtom';
import { currentIntersectionSelector } from '../../atoms/config/currentIntersectionAtom';
import translate from '../../utils/transform';
import { highlight, mousePointer } from '../../utils/styles';
import { SizeBar } from '../Columns/SizeBar';
Expand Down Expand Up @@ -107,12 +107,14 @@ export const AggregateRow: FC<Props> = ({ aggregateRow }) => {
strokeWidth="1px"
/>
<g
onClick={() => {
onClick={(e) => {
if (collapsedIds.includes(aggregateRow.id)) {
actions.removeCollapsed(aggregateRow.id);
} else {
actions.addCollapsed(aggregateRow.id);
}
// To prevent the handler on SvgBase that deselects the current intersection
e.stopPropagation();
}}
>
{ collapsedIds.includes(aggregateRow.id) ? collapsed : expanded}
Expand Down
9 changes: 8 additions & 1 deletion packages/upset/src/components/SvgBase.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { css } from '@emotion/react';
import { FC } from 'react';
import { FC, useContext } from 'react';
import { useRecoilValue } from 'recoil';

import translate from '../utils/transform';
import { dimensionsSelector } from '../atoms/dimensionsAtom';
import { ProvenanceContext } from './Root';
import { currentIntersectionSelector } from '../atoms/config/currentIntersectionAtom';

/** @jsxImportSource @emotion/react */
type SvgBaseSettings = {
Expand All @@ -18,13 +20,18 @@ type Props = {

export const SvgBase: FC<Props> = ({ children, defaultSettings }) => {
const { height, width, margin } = defaultSettings || useRecoilValue(dimensionsSelector);
const { actions } = useContext(ProvenanceContext);
const selectedIntersection = useRecoilValue(currentIntersectionSelector);

return (
// These rules are for accessibility; unnecessary here as the plot is not accessible anyway.
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<div
css={css`
height: 100%;
width: 100%;
`}
onClick={() => { if (selectedIntersection != null) actions.setSelected(null); }}
>
<svg id="upset-svg" height={height + 50 * margin} width={width + 2 * margin} xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" fontFamily="Roboto, Arial">
<g transform={translate(margin)}>
Expand Down

0 comments on commit 85cccee

Please sign in to comment.