@vitessce/layer-controller 4.1.0 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/{deflate-CO8WP3TK.js → deflate-Bn_X6_zo.js} +1 -1
  2. package/dist/{index-DqF3uPwm.js → index-KPdFdtqD.js} +98 -22
  3. package/dist/index.js +3 -1
  4. package/dist/{jpeg-DLpV0wRq.js → jpeg-BKMAcEDV.js} +1 -1
  5. package/dist/{lerc-DsC1LnVo.js → lerc-DrRHpq46.js} +1 -1
  6. package/dist/{lzw-rFGfN0gQ.js → lzw-NyHi0pOJ.js} +1 -1
  7. package/dist/{packbits-CbBp069q.js → packbits-W8xQwU7O.js} +1 -1
  8. package/dist/{raw-DAszYM2p.js → raw-CQ1-Oqp0.js} +1 -1
  9. package/dist/{webimage-TkLIn1ud.js → webimage-DckhYFL0.js} +1 -1
  10. package/dist-tsc/BitmaskChannelController.d.ts +3 -1
  11. package/dist-tsc/BitmaskChannelController.d.ts.map +1 -1
  12. package/dist-tsc/BitmaskChannelController.js +3 -2
  13. package/dist-tsc/BitmaskChannelController.js.map +1 -1
  14. package/dist-tsc/LayerController.d.ts.map +1 -1
  15. package/dist-tsc/LayerController.js +3 -3
  16. package/dist-tsc/LayerController.js.map +1 -1
  17. package/dist-tsc/LayerControllerSubscriber.d.ts.map +1 -1
  18. package/dist-tsc/LayerControllerSubscriber.js +5 -5
  19. package/dist-tsc/LayerControllerSubscriber.js.map +1 -1
  20. package/dist-tsc/LayerOptions.d.ts +5 -1
  21. package/dist-tsc/LayerOptions.d.ts.map +1 -1
  22. package/dist-tsc/LayerOptions.js +16 -2
  23. package/dist-tsc/LayerOptions.js.map +1 -1
  24. package/dist-tsc/RasterChannelController.d.ts +2 -1
  25. package/dist-tsc/RasterChannelController.d.ts.map +1 -1
  26. package/dist-tsc/RasterChannelController.js +3 -2
  27. package/dist-tsc/RasterChannelController.js.map +1 -1
  28. package/dist-tsc/channel-sort-utils.d.ts +21 -0
  29. package/dist-tsc/channel-sort-utils.d.ts.map +1 -0
  30. package/dist-tsc/channel-sort-utils.js +29 -0
  31. package/dist-tsc/channel-sort-utils.js.map +1 -0
  32. package/dist-tsc/index.d.ts +1 -0
  33. package/dist-tsc/index.js +1 -0
  34. package/dist-tsc/index.js.map +1 -1
  35. package/dist-tsc/shared-channel-controls.d.ts +3 -1
  36. package/dist-tsc/shared-channel-controls.d.ts.map +1 -1
  37. package/dist-tsc/shared-channel-controls.js +6 -3
  38. package/dist-tsc/shared-channel-controls.js.map +1 -1
  39. package/package.json +7 -7
  40. package/src/BitmaskChannelController.js +3 -0
  41. package/src/LayerController.js +5 -0
  42. package/src/LayerControllerSubscriber.js +10 -0
  43. package/src/LayerOptions.js +43 -0
  44. package/src/RasterChannelController.js +3 -0
  45. package/src/channel-sort-utils.js +30 -0
  46. package/src/index.js +1 -0
  47. package/src/shared-channel-controls.js +11 -4
@@ -82,6 +82,8 @@ const LayerControllerMemoized = React.memo(
82
82
  spatialLayout,
83
83
  handleImageAdd,
84
84
  enableLayerButtonsWithOneLayer,
85
+ channelsSortOrder,
86
+ setChannelsSortOrder,
85
87
  helpText,
86
88
  } = props;
87
89
  const shouldShowImageLayerButton = Boolean(
@@ -194,6 +196,8 @@ const LayerControllerMemoized = React.memo(
194
196
  spatialHeight={(componentHeight * (spatialLayout ? spatialLayout.h : 1)) / 12}
195
197
  spatialWidth={(componentWidth * (spatialLayout ? spatialLayout.w : 1)) / 12}
196
198
  shouldShowRemoveLayerButton={shouldShowImageLayerButton}
199
+ channelsSortOrder={channelsSortOrder}
200
+ setChannelsSortOrder={setChannelsSortOrder}
197
201
  />
198
202
  </Grid>
199
203
  ) : null;
@@ -276,6 +280,8 @@ const LayerControllerMemoized = React.memo(
276
280
  spatialHeight={(componentHeight * (spatialLayout ? spatialLayout.h : 1)) / 12}
277
281
  spatialWidth={(componentWidth * (spatialLayout ? spatialLayout.w : 1)) / 12}
278
282
  shouldShowRemoveLayerButton={shouldShowImageLayerButton}
283
+ channelsSortOrder={channelsSortOrder}
284
+ setChannelsSortOrder={setChannelsSortOrder}
279
285
  />
280
286
  </Grid>
281
287
  ) : null;
@@ -337,6 +343,7 @@ export function LayerControllerSubscriber(props) {
337
343
  spatialSegmentationLayer: cellsLayer,
338
344
  spatialPointLayer: moleculesLayer,
339
345
  photometricInterpretation: photometricInterpretationFromCoordination,
346
+ spatialChannelsSortOrder: channelsSortOrder,
340
347
  },
341
348
  {
342
349
  setSpatialImageLayer: setRasterLayers,
@@ -348,6 +355,7 @@ export function LayerControllerSubscriber(props) {
348
355
  setSpatialRotationX: setRotationX,
349
356
  setSpatialRotationOrbit: setRotationOrbit,
350
357
  setSpatialZoom: setZoom,
358
+ setSpatialChannelsSortOrder: setChannelsSortOrder,
351
359
  },
352
360
  ] = useCoordination(
353
361
  COMPONENT_COORDINATION_TYPES[ViewType.LAYER_CONTROLLER],
@@ -500,6 +508,8 @@ export function LayerControllerSubscriber(props) {
500
508
  handleRasterLayerChange={handleRasterLayerChange}
501
509
  handleRasterLayerRemove={handleRasterLayerRemove}
502
510
  photometricInterpretation={photometricInterpretation}
511
+ channelsSortOrder={channelsSortOrder}
512
+ setChannelsSortOrder={setChannelsSortOrder}
503
513
 
504
514
  obsSegmentationsType={obsSegmentationsType}
505
515
  segmentationLayerLoaders={segmentationLayerLoaders}
@@ -15,6 +15,7 @@ import {
15
15
  COLORMAP_OPTIONS,
16
16
  formatBytes,
17
17
  } from '@vitessce/utils';
18
+ import { CHANNELS_SORT_ORDER_OPTIONS } from './channel-sort-utils.js';
18
19
  import {
19
20
  useSelectionSliderStyles,
20
21
  useSelectStyles,
@@ -241,6 +242,32 @@ function OpacitySlider({ value, inputId, handleChange }) {
241
242
  );
242
243
  }
243
244
 
245
+ /**
246
+ * Wrapper for the dropdown that chooses the channel dropdown sort order.
247
+ * @prop {string} value Currently selected value ('original' or 'alphabetical').
248
+ * @prop {string} inputId Css id.
249
+ * @prop {function} handleChange Callback for every change in sort order.
250
+ */
251
+ function ChannelsSortOrderSelect({ value, inputId, handleChange }) {
252
+ const { classes } = useSelectStyles();
253
+ return (
254
+ <NativeSelect
255
+ onChange={e => handleChange(e.target.value)}
256
+ value={value || 'original'}
257
+ id={inputId}
258
+ inputProps={{ 'aria-label': 'Channel sort order selector' }}
259
+ style={{ width: '100%' }}
260
+ classes={{ root: classes.selectRoot }}
261
+ >
262
+ {CHANNELS_SORT_ORDER_OPTIONS.map(({ value: optValue, label }) => (
263
+ <option key={optValue} value={optValue}>
264
+ {label}
265
+ </option>
266
+ ))}
267
+ </NativeSelect>
268
+ );
269
+ }
270
+
244
271
  /**
245
272
  * Wrapper for the dropdown that chooses the domain type.
246
273
  * @prop {string} value Currently selected value (i.e 'Max/Min').
@@ -350,6 +377,8 @@ function LayerOption({ name, inputId, children }) {
350
377
  * @prop {array} dimensions Currently available dimensions (channel, z, t etc.).
351
378
  * @prop {string} domainType One of Max/Min or Full (soon presets as well).
352
379
  * @prop {boolean} disableChannelsIfRgbDetected Whether or not we need colormap controllers if RGB.
380
+ * @prop {string} channelsSortOrder Channel dropdown sort order ('original' or 'alphabetical').
381
+ + @prop {function} handleChannelsSortOrderChange Callback for sort order changes.
353
382
  */
354
383
  function LayerOptions({
355
384
  colormap,
@@ -362,6 +391,8 @@ function LayerOptions({
362
391
  handleGlobalChannelsSelectionChange,
363
392
  handleSliderChange,
364
393
  handleDomainChange,
394
+ channelsSortOrder,
395
+ handleChannelsSortOrderChange,
365
396
  transparentColor,
366
397
  channels,
367
398
  domainType,
@@ -394,6 +425,7 @@ function LayerOptions({
394
425
  const domainSelectorId = useId();
395
426
  const opacitySliderId = useId();
396
427
  const zeroTransparentId = useId();
428
+ const channelsSortOrderId = useId();
397
429
  return (
398
430
  <Grid container sx={{ flexDirection: 'column', width: '100%' }}>
399
431
  {hasZStack
@@ -446,6 +478,17 @@ function LayerOptions({
446
478
  </LayerOption>
447
479
  </Grid>
448
480
  )}
481
+ {hasDimensionsAndChannels && handleChannelsSortOrderChange && (
482
+ <Grid>
483
+ <LayerOption name="Channel Order" inputId={channelsSortOrderId}>
484
+ <ChannelsSortOrderSelect
485
+ value={channelsSortOrder}
486
+ inputId={channelsSortOrderId}
487
+ handleChange={handleChannelsSortOrderChange}
488
+ />
489
+ </LayerOption>
490
+ </Grid>
491
+ )}
449
492
  {shouldShowDomain && (
450
493
  <Grid>
451
494
  <LayerOption name="Domain" inputId={domainSelectorId}>
@@ -23,6 +23,7 @@ import { useChannelSliderStyles } from './styles.js';
23
23
  * @prop {arry} slider Current value of the slider.
24
24
  * @prop {function} handleChange Callback for each slider change.
25
25
  * @prop {array} domain Current max/min allowable slider values.
26
+ * @prop {string} channelsSortOrder Either 'original' or 'alphabetical'.
26
27
  */
27
28
  function ChannelSlider({
28
29
  color,
@@ -102,6 +103,7 @@ function RasterChannelController({
102
103
  selectionIndex,
103
104
  isLoading,
104
105
  use3d: newUse3d,
106
+ channelsSortOrder,
105
107
  }) {
106
108
  const { dtype } = getSourceFromLoader(loader);
107
109
  const [domain, setDomain] = useState(null);
@@ -207,6 +209,7 @@ function RasterChannelController({
207
209
  selectionIndex={selectionIndex}
208
210
  channelOptions={channelOptions}
209
211
  disabled={isLoading}
212
+ channelsSortOrder={channelsSortOrder}
210
213
  />
211
214
  </Grid>
212
215
  <Grid size={1} sx={{ marginTop: '4px' }}>
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Options for the spatialChannelsSortOrder coordination type.
3
+ * Shared by the layer-controller and layer-controller-beta views.
4
+ */
5
+ export const CHANNELS_SORT_ORDER_OPTIONS = [
6
+ { value: 'original', label: 'Original' },
7
+ { value: 'alphabetical', label: 'Alphabetical' },
8
+ ];
9
+
10
+ /**
11
+ * Get channel dropdown options in the requested display order.
12
+ * The returned channelIndex always refers to the position in the
13
+ * original channel list, so selections are unaffected by sorting.
14
+ * @param {string[]} channelNames The channel names, in original order.
15
+ * @param {string} channelsSortOrder Either 'original' or 'alphabetical'.
16
+ * @returns {{ channelName: string, channelIndex: number }[]}
17
+ */
18
+ export function getSortedChannelOptions(channelNames, channelsSortOrder) {
19
+ if (!Array.isArray(channelNames)) return [];
20
+ const options = channelNames
21
+ .map((channelName, channelIndex) => ({ channelName, channelIndex }));
22
+ if (channelsSortOrder === 'alphabetical') {
23
+ // numeric: true ensures m/z-style numeric labels sort as 1, 2, 3, 10
24
+ // rather than lexicographically as 1, 10, 2, 3.
25
+ return options.sort((a, b) => String(a.channelName).localeCompare(
26
+ String(b.channelName), undefined, { numeric: true, sensitivity: 'base' },
27
+ ));
28
+ }
29
+ return options;
30
+ }
package/src/index.js CHANGED
@@ -10,3 +10,4 @@ export {
10
10
  useOverflowEllipsisGridStyles,
11
11
  useSelectionSliderStyles,
12
12
  } from './styles.js';
13
+ export { CHANNELS_SORT_ORDER_OPTIONS, getSortedChannelOptions } from './channel-sort-utils.js';
@@ -1,7 +1,8 @@
1
- import React from 'react';
1
+ import React, { useMemo } from 'react';
2
2
 
3
3
  import { Checkbox, NativeSelect } from '@vitessce/styles';
4
4
  import { useSelectStyles } from './styles.js';
5
+ import { getSortedChannelOptions } from './channel-sort-utils.js';
5
6
 
6
7
  /**
7
8
  * Dropdown for selecting a channel.
@@ -9,14 +10,20 @@ import { useSelectStyles } from './styles.js';
9
10
  * @prop {array} channelOptions List of available selections, like ['DAPI', 'FITC', ...].
10
11
  * @prop {boolean} disabled Whether or not the component is disabled.
11
12
  * @prop {number} selectionIndex Current numeric index of a selection.
13
+ * @prop {string} channelsSortOrder Either 'original' or 'alphabetical'.
12
14
  */
13
15
  export function ChannelSelectionDropdown({
14
16
  handleChange,
15
17
  disabled,
16
18
  channelOptions,
17
19
  selectionIndex,
20
+ channelsSortOrder,
18
21
  }) {
19
22
  const { classes } = useSelectStyles();
23
+ const sortedOptions = useMemo(
24
+ () => getSortedChannelOptions(channelOptions, channelsSortOrder),
25
+ [channelOptions, channelsSortOrder],
26
+ );
20
27
  return (
21
28
  <NativeSelect
22
29
  classes={{ root: classes.selectRoot }}
@@ -24,9 +31,9 @@ export function ChannelSelectionDropdown({
24
31
  onChange={e => handleChange(Number(e.target.value))}
25
32
  inputProps={{ 'aria-label': 'Select a channel' }}
26
33
  >
27
- {channelOptions.map((opt, i) => (
28
- <option disabled={disabled} key={opt} value={i}>
29
- {opt}
34
+ {sortedOptions.map(({ channelName, channelIndex }) => (
35
+ <option disabled={disabled} key={`${channelName}-${channelIndex}`} value={channelIndex}>
36
+ {channelName}
30
37
  </option>
31
38
  ))}
32
39
  </NativeSelect>