Skip to content

Commit 2d3dda9

Browse files
authored
Merge pull request #1894 from silx-kit/signals-menu
Move NX Heatmap signal picker to vis bar
2 parents 5d1e7d8 + f9edd91 commit 2d3dda9

File tree

12 files changed

+64
-66
lines changed

12 files changed

+64
-66
lines changed

apps/storybook/src/RadioGroup.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const Default = {
2626
{...args}
2727
options={OPTIONS}
2828
value={value}
29-
onValueChanged={setValue}
29+
onChange={setValue}
3030
/>
3131
);
3232
},

cypress/e2e/app.cy.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ describe('/mock', () => {
431431
}).should('be.visible');
432432
cy.findByRole('figure', { name: 'twoD' }).should('be.visible');
433433

434+
cy.findByRole('button', { name: 'Signals' }).click();
434435
cy.findByRole('radio', { name: 'tertiary' }).click();
435-
cy.waitForStableDOM();
436436

437437
cy.findByRole('figure', { name: 'tertiary' })
438438
.should('be.visible')
@@ -469,7 +469,9 @@ describe('/mock', () => {
469469
}
470470

471471
// Select float auxiliary signal
472-
cy.findByLabelText('tertiary_float').check();
472+
cy.findByRole('button', { name: 'Signals' }).click();
473+
cy.findByRole('radio', { name: 'tertiary_float' }).click();
474+
473475
cy.findByRole('figure', { name: 'tertiary_float' }).should('be.visible');
474476

475477
if (Cypress.env('TAKE_SNAPSHOTS')) {
5.07 KB
Loading
-3.57 KB
Loading
3.96 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { screen } from '@testing-library/react';
2+
import { expect, test } from 'vitest';
3+
4+
import { getSelectedVisTab, renderApp, waitForAllLoaders } from '../test-utils';
5+
import { NxDataVis } from '../vis-packs/nexus/visualizations';
6+
7+
test('pick auxiliary signal on NX Heatmap', async () => {
8+
const { user } = await renderApp('/nexus_entry/image_with_aux');
9+
expect(getSelectedVisTab()).toBe(NxDataVis.NxHeatmap);
10+
expect(screen.getByRole('figure', { name: 'twoD' })).toBeVisible();
11+
12+
await user.click(screen.getByRole('button', { name: 'Signals' }));
13+
await user.click(screen.getByRole('radio', { name: 'tertiary' }));
14+
await waitForAllLoaders();
15+
16+
expect(screen.getByRole('figure', { name: 'tertiary' })).toBeVisible();
17+
});

packages/app/src/vis-packs/core/line/LineToolbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ function LineToolbar(props: Props) {
120120
value={curveType}
121121
options={Object.values(CurveType)}
122122
optionsLabels={CURVE_TYPE_LABELS}
123-
onValueChanged={setCurveType}
123+
onChange={setCurveType}
124124
/>
125125
<RadioGroup
126126
name="interpolation"
127127
label="Interpolation"
128128
options={Object.values(Interpolation)}
129129
disabled={curveType === CurveType.GlyphsOnly}
130130
value={interpolation}
131-
onValueChanged={setInterpolation}
131+
onChange={setInterpolation}
132132
/>
133133
</Menu>
134134

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,6 @@
1-
.bar {
2-
grid-area: bar;
1+
.wrapper {
2+
z-index: 1; /* for picker menu to appear above visualization */
33
display: flex;
4-
align-items: center;
5-
overflow-x: auto;
6-
overflow-y: hidden;
7-
scrollbar-width: thin;
8-
min-width: 0;
9-
margin: 0;
10-
padding: 0.675rem 1.25rem 0;
11-
font-size: 0.875em;
12-
line-height: 1.4;
13-
}
14-
15-
.text {
16-
margin-right: 0.5rem;
17-
font-weight: 600;
18-
}
19-
20-
.label {
21-
display: flex;
22-
align-items: center;
23-
padding: 0.25rem;
24-
cursor: pointer;
25-
}
26-
27-
.label > input {
28-
margin-bottom: -0.1em;
29-
margin-right: 0.25rem;
30-
accent-color: var(--secondary-dark);
31-
cursor: pointer;
4+
padding: 0 0.5rem;
5+
font-size: 0.875rem;
326
}

packages/app/src/vis-packs/nexus/NxSignalPicker.tsx

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,48 @@
1+
import { assertDefined, Menu, RadioGroup, Separator } from '@h5web/lib';
12
import {
23
type ComplexType,
34
type NumericLikeType,
45
} from '@h5web/shared/hdf5-models';
6+
import { createPortal } from 'react-dom';
7+
import { MdLineAxis } from 'react-icons/md';
58

69
import { type DatasetDef } from './models';
710
import styles from './NxSignalPicker.module.css';
811

912
interface Props<T extends NumericLikeType | ComplexType> {
1013
definitions: DatasetDef<T>[];
14+
toolbarContainer: HTMLDivElement | undefined;
15+
value: DatasetDef<T>;
1116
onChange: (def: DatasetDef<T>) => void;
1217
}
1318

1419
function NxSignalPicker<T extends NumericLikeType | ComplexType>(
1520
props: Props<T>,
1621
) {
17-
const { definitions, onChange } = props;
22+
const { definitions, toolbarContainer, value, onChange } = props;
1823

19-
return (
20-
<p className={styles.bar}>
21-
<span className={styles.text}>Signal:</span>
22-
{definitions.map((def, index) => (
23-
<label key={def.dataset.name} className={styles.label}>
24-
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}
25-
<input
26-
type="radio"
27-
name="signal"
28-
value={def.dataset.name}
29-
defaultChecked={index === 0}
30-
autoComplete="off" // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio#checked
31-
onChange={() => onChange(def)}
32-
/>
33-
{def.dataset.name}
34-
</label>
35-
))}
36-
</p>
24+
if (!toolbarContainer) {
25+
return null;
26+
}
27+
28+
return createPortal(
29+
<div className={styles.wrapper}>
30+
<Separator />
31+
32+
<Menu label="Signals" Icon={MdLineAxis}>
33+
<RadioGroup
34+
name="signals"
35+
options={definitions.map((def) => def.dataset.name)}
36+
value={value.dataset.name}
37+
onChange={(name) => {
38+
const selection = definitions.find((s) => s.dataset.name === name);
39+
assertDefined(selection);
40+
onChange(selection);
41+
}}
42+
/>
43+
</Menu>
44+
</div>,
45+
toolbarContainer,
3746
);
3847
}
3948

packages/app/src/vis-packs/nexus/containers/NxHeatmapContainer.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ function NxHeatmapContainer(props: VisContainerProps) {
5858
{auxDefs.length > 0 && (
5959
<NxSignalPicker
6060
definitions={[signalDef, ...auxDefs]}
61+
value={selectedDef}
6162
onChange={setSelectedDef}
63+
toolbarContainer={toolbarContainer}
6264
/>
6365
)}
66+
6467
<DimensionMapper
6568
className={visualizerStyles.dimMapper}
6669
dims={dims}
@@ -69,6 +72,7 @@ function NxHeatmapContainer(props: VisContainerProps) {
6972
canSliceFast={useNxValuesCached(nxData)}
7073
onChange={setDimMapping}
7174
/>
75+
7276
<VisBoundary resetKey={dimMapping}>
7377
<NxValuesFetcher
7478
nxData={nxDataToFetch}

0 commit comments

Comments
 (0)