@vitessce/layer-controller 2.0.3 → 3.0.0

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 (74) hide show
  1. package/dist/{deflate.b44720d0.mjs → deflate-75511377.js} +2 -2
  2. package/dist/{index.ca9e70ae.mjs → index-841a1af6.js} +137252 -126353
  3. package/dist/{index.mjs → index.js} +2 -3
  4. package/dist/{jpeg.edb20ff0.mjs → jpeg-6023316d.js} +1 -1
  5. package/dist/{lerc.df2f1733.mjs → lerc-82182c45.js} +76 -5
  6. package/dist/{lzw.2a639594.mjs → lzw-2ab01db2.js} +1 -1
  7. package/dist/{packbits.958f7a40.mjs → packbits-2633f360.js} +1 -1
  8. package/dist/{pako.esm.4b234125.mjs → pako.esm-68f84e2a.js} +97 -15
  9. package/dist/{raw.4239192e.mjs → raw-51e455c7.js} +1 -1
  10. package/dist/{webimage.de21cf13.mjs → webimage-bbb56d18.js} +1 -1
  11. package/dist-tsc/BitmaskChannelController.d.ts +21 -0
  12. package/dist-tsc/BitmaskChannelController.d.ts.map +1 -0
  13. package/dist-tsc/BitmaskChannelController.js +30 -0
  14. package/dist-tsc/ChannelOptions.d.ts +13 -0
  15. package/dist-tsc/ChannelOptions.d.ts.map +1 -0
  16. package/dist-tsc/ChannelOptions.js +38 -0
  17. package/dist-tsc/ColorPalette.d.ts +5 -0
  18. package/dist-tsc/ColorPalette.d.ts.map +1 -0
  19. package/dist-tsc/ColorPalette.js +30 -0
  20. package/dist-tsc/ImageAddButton.d.ts +6 -0
  21. package/dist-tsc/ImageAddButton.d.ts.map +1 -0
  22. package/dist-tsc/ImageAddButton.js +27 -0
  23. package/dist-tsc/LayerController.d.ts +10 -0
  24. package/dist-tsc/LayerController.d.ts.map +1 -0
  25. package/dist-tsc/LayerController.js +303 -0
  26. package/dist-tsc/LayerControllerSubscriber.d.ts +27 -0
  27. package/dist-tsc/LayerControllerSubscriber.d.ts.map +1 -0
  28. package/dist-tsc/LayerControllerSubscriber.js +194 -0
  29. package/dist-tsc/LayerOptions.d.ts +46 -0
  30. package/dist-tsc/LayerOptions.d.ts.map +1 -0
  31. package/dist-tsc/LayerOptions.js +207 -0
  32. package/dist-tsc/RasterChannelController.d.ts +35 -0
  33. package/dist-tsc/RasterChannelController.d.ts.map +1 -0
  34. package/dist-tsc/RasterChannelController.js +150 -0
  35. package/dist-tsc/RasterChannelController.test.d.ts +2 -0
  36. package/dist-tsc/RasterChannelController.test.d.ts.map +1 -0
  37. package/dist-tsc/RasterChannelController.test.js +21 -0
  38. package/dist-tsc/VectorLayerController.d.ts +2 -0
  39. package/dist-tsc/VectorLayerController.d.ts.map +1 -0
  40. package/dist-tsc/VectorLayerController.js +26 -0
  41. package/dist-tsc/VolumeOptions.d.ts +16 -0
  42. package/dist-tsc/VolumeOptions.d.ts.map +1 -0
  43. package/dist-tsc/VolumeOptions.js +71 -0
  44. package/dist-tsc/constants.d.ts +2 -0
  45. package/dist-tsc/constants.d.ts.map +1 -0
  46. package/dist-tsc/constants.js +12 -0
  47. package/dist-tsc/index.d.ts +4 -0
  48. package/dist-tsc/index.d.ts.map +1 -0
  49. package/dist-tsc/index.js +3 -3
  50. package/dist-tsc/shared-channel-controls.d.ts +27 -0
  51. package/dist-tsc/shared-channel-controls.d.ts.map +1 -0
  52. package/dist-tsc/shared-channel-controls.js +25 -0
  53. package/dist-tsc/styles.d.ts +76 -0
  54. package/dist-tsc/styles.d.ts.map +1 -0
  55. package/dist-tsc/styles.js +98 -0
  56. package/dist-tsc/utils.d.ts +24 -0
  57. package/dist-tsc/utils.d.ts.map +1 -0
  58. package/dist-tsc/utils.js +117 -0
  59. package/package.json +19 -10
  60. package/src/BitmaskChannelController.js +3 -4
  61. package/src/ChannelOptions.js +4 -5
  62. package/src/ColorPalette.js +2 -3
  63. package/src/ImageAddButton.js +2 -3
  64. package/src/LayerController.js +13 -16
  65. package/src/LayerControllerSubscriber.js +6 -15
  66. package/src/LayerOptions.js +4 -8
  67. package/src/RasterChannelController.js +7 -18
  68. package/src/RasterChannelController.test.js +1 -1
  69. package/src/VectorLayerController.js +2 -6
  70. package/src/VolumeOptions.js +13 -10
  71. package/src/index.js +3 -3
  72. package/src/shared-channel-controls.js +2 -3
  73. package/src/styles.js +9 -6
  74. package/src/utils.js +9 -0
@@ -0,0 +1,207 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import { range } from 'lodash-es';
4
+ import { Matrix4 } from 'math.gl';
5
+ import { Grid, Slider, InputLabel, Select, Checkbox } from '@material-ui/core';
6
+ import { viv } from '@vitessce/gl';
7
+ import { DEFAULT_RASTER_DOMAIN_TYPE } from '@vitessce/spatial-utils';
8
+ import { COLORMAP_OPTIONS, canLoadResolution, formatBytes, getStatsForResolution, } from '@vitessce/utils';
9
+ import { getBoundingCube, getMultiSelectionStats, } from './utils.js';
10
+ import { StyledSelectionSlider, useSelectStyles } from './styles.js';
11
+ const DOMAIN_OPTIONS = ['Full', 'Min/Max'];
12
+ /**
13
+ * Wrapper for the dropdown that selects a colormap (None, viridis, magma, etc.).
14
+ * @prop {Object} loader Loader object with metadata.
15
+ * @prop {function} handleMultiPropertyChange Function to propgate multiple layer changes at once.
16
+ * This prevents updates from overridding each other.
17
+ * @prop {number} resolution Current 3D resolution.
18
+ * @prop {boolean} disable3d Whether or not to enable 3D selection
19
+ * @prop {function} setRasterLayerCallback Setter for callbacks that fire after raster/volume loads.
20
+ * @prop {function} setAreAllChannelsLoading Setter for whether or not a given channel is loading.
21
+ * @prop {Object} setViewState Setter for the current view state.
22
+ * @prop {number} spatialHeight Height of the spatial component.
23
+ * @prop {number} spatialWidth Width of the spatial component.
24
+ * @prop {object} channels Channels object.
25
+ * @prop {boolean} use3d Whether or not 3D is enabled for this layer.
26
+ */
27
+ function VolumeDropdown({ loader: loaderWithMeta, handleMultiPropertyChange, resolution: currResolution, disable3d, setRasterLayerCallback, setAreAllChannelsLoading, setViewState, spatialHeight, spatialWidth, channels, use3d, modelMatrix, }) {
28
+ const classes = useSelectStyles();
29
+ const selections = channels.map(i => i.selection);
30
+ const { data: loader } = loaderWithMeta;
31
+ const handleChange = async (val) => {
32
+ // val is the resolution - null indicates 2D
33
+ const shouldUse3D = typeof val === 'number';
34
+ setAreAllChannelsLoading(true);
35
+ setRasterLayerCallback(() => {
36
+ setAreAllChannelsLoading(false);
37
+ setRasterLayerCallback(null);
38
+ });
39
+ if (shouldUse3D) {
40
+ const [xSlice, ySlice, zSlice] = getBoundingCube(loader);
41
+ const propertiesChanged = {
42
+ resolution: val,
43
+ xSlice,
44
+ ySlice,
45
+ zSlice,
46
+ use3d: shouldUse3D,
47
+ };
48
+ // Only make the fetch if needed i.e if the 3d was just being turned on.
49
+ if (!use3d) {
50
+ const { sliders } = await getMultiSelectionStats({
51
+ loader,
52
+ selections,
53
+ use3d: shouldUse3D,
54
+ });
55
+ propertiesChanged.channels = [...channels];
56
+ propertiesChanged.channels.forEach((ch, i) => {
57
+ // eslint-disable-next-line no-param-reassign
58
+ ch.slider = sliders[i];
59
+ });
60
+ }
61
+ // Update all properties at once to avoid overriding calls.
62
+ handleMultiPropertyChange(propertiesChanged);
63
+ const defaultViewState = viv.getDefaultInitialViewState(loader, { height: spatialHeight, width: spatialWidth }, 1.5, true, new Matrix4(modelMatrix));
64
+ setViewState({
65
+ ...defaultViewState,
66
+ rotationX: 0,
67
+ rotationOrbit: 0,
68
+ });
69
+ }
70
+ else {
71
+ const { sliders } = await getMultiSelectionStats({
72
+ loader, selections, use3d: shouldUse3D,
73
+ });
74
+ const newChannels = [...channels];
75
+ newChannels.forEach((ch, i) => {
76
+ // eslint-disable-next-line no-param-reassign
77
+ ch.slider = sliders[i];
78
+ });
79
+ // Update all properties at once to avoid overriding calls.
80
+ handleMultiPropertyChange({
81
+ resolution: val,
82
+ use3d: shouldUse3D,
83
+ spatialAxisFixed: false,
84
+ channels: newChannels,
85
+ });
86
+ const defaultViewState = viv.getDefaultInitialViewState(loader, { height: spatialHeight, width: spatialWidth }, 0.5, false, new Matrix4(modelMatrix));
87
+ setViewState({
88
+ ...defaultViewState,
89
+ rotationX: null,
90
+ rotationOrbit: null,
91
+ orbitAxis: null,
92
+ });
93
+ }
94
+ };
95
+ const { labels, shape } = Array.isArray(loader) ? loader[0] : loader;
96
+ const hasZStack = shape[labels.indexOf('z')] > 1;
97
+ return (_jsx(_Fragment, { children: _jsxs(Select, { native: true, value: currResolution, onChange: e => handleChange(e.target.value === '2D' ? e.target.value : Number(e.target.value)), classes: { root: classes.selectRoot }, children: [_jsx("option", { value: "2D", children: "2D Visualization" }, "2D"), Array.from({ length: loader.length })
98
+ .fill(0)
99
+ // eslint-disable-next-line no-unused-vars
100
+ .map((_, resolution) => {
101
+ if (loader) {
102
+ if (canLoadResolution(loader, resolution)) {
103
+ const { height, width, depthDownsampled, totalBytes, } = getStatsForResolution(loader, resolution);
104
+ return (_jsx("option", { value: resolution, disabled: disable3d
105
+ || !hasZStack, children: `3D: ${resolution}x Downsampled, ~${formatBytes(totalBytes)} per channel, (${height}, ${width}, ${depthDownsampled})` }, `(${height}, ${width}, ${depthDownsampled})`));
106
+ }
107
+ }
108
+ return null;
109
+ })] }) }));
110
+ }
111
+ /**
112
+ * Wrapper for the dropdown that selects a colormap (None, viridis, magma, etc.).
113
+ * @prop {string} value Currently selected value for the colormap.
114
+ * @prop {string} inputId Css id.
115
+ * @prop {function} handleChange Callback for every change in colormap.
116
+ */
117
+ function ColormapSelect({ value, inputId, handleChange }) {
118
+ const classes = useSelectStyles();
119
+ return (_jsxs(Select, { native: true, onChange: e => handleChange(e.target.value === '' ? null : e.target.value), value: value, inputProps: { name: 'colormap', id: inputId }, style: { width: '100%' }, classes: { root: classes.selectRoot }, children: [_jsx("option", { "aria-label": "None", value: "", children: "None" }), COLORMAP_OPTIONS.map(name => (_jsx("option", { value: name, children: name }, name)))] }));
120
+ }
121
+ function TransparentColorCheckbox({ value, handleChange }) {
122
+ return (_jsx(Checkbox, { style: { float: 'left', padding: 0 }, color: "default", onChange: () => {
123
+ if (value) {
124
+ handleChange(null);
125
+ }
126
+ else {
127
+ handleChange([0, 0, 0]);
128
+ }
129
+ }, checked: Boolean(value) }));
130
+ }
131
+ /**
132
+ * Wrapper for the slider that updates opacity.
133
+ * @prop {string} value Currently selected value between 0 and 1.
134
+ * @prop {function} handleChange Callback for every change in opacity.
135
+ */
136
+ function OpacitySlider({ value, handleChange }) {
137
+ return (_jsx(Slider, { value: value, onChange: (e, v) => handleChange(v), valueLabelDisplay: "auto", getAriaLabel: () => 'opacity slider', min: 0, max: 1, step: 0.01, orientation: "horizontal", style: { marginTop: '7px' } }));
138
+ }
139
+ /**
140
+ * Wrapper for the dropdown that chooses the domain type.
141
+ * @prop {string} value Currently selected value (i.e 'Max/Min').
142
+ * @prop {string} inputId Css id.
143
+ * @prop {function} handleChange Callback for every change in domain.
144
+ */
145
+ function SliderDomainSelector({ value, inputId, handleChange }) {
146
+ const classes = useSelectStyles();
147
+ return (_jsx(Select, { native: true, onChange: e => handleChange(e.target.value), value: value, inputProps: { name: 'domain-selector', id: inputId }, style: { width: '100%' }, classes: { root: classes.selectRoot }, children: DOMAIN_OPTIONS.map(name => (_jsx("option", { value: name, children: name }, name))) }));
148
+ }
149
+ /**
150
+ * Wrapper for the slider that chooses global selections (z, t etc.).
151
+ * @prop {string} field The dimension this selects for (z, t etc.).
152
+ * @prop {number} value Currently selected index (1, 4, etc.).
153
+ * @prop {function} handleChange Callback for every change in selection.
154
+ * @prop {function} possibleValues All available values for the field.
155
+ */
156
+ function GlobalSelectionSlider({ field, value, handleChange, possibleValues, }) {
157
+ return (_jsx(StyledSelectionSlider, { value: value,
158
+ // See https://github.com/hms-dbmi/viv/issues/176 for why
159
+ // we have the two handlers.
160
+ onChange: (event, newValue) => {
161
+ handleChange({ selection: { [field]: newValue }, event });
162
+ }, onChangeCommitted: (event, newValue) => {
163
+ handleChange({ selection: { [field]: newValue }, event });
164
+ }, valueLabelDisplay: "auto", getAriaLabel: () => `${field} slider`, marks: possibleValues.map(val => ({ value: val })), min: Number(possibleValues[0]), max: Number(possibleValues.slice(-1)), orientation: "horizontal", step: null }));
165
+ }
166
+ /**
167
+ * Wrapper for each of the options to show its name and then its UI component.
168
+ * @prop {string} name Display name for option.
169
+ * @prop {number} opacity Current opacity value.
170
+ * @prop {string} inputId An id for css.
171
+ * @prop {object} children Components to be rendered next to the name (slider, dropdown etc.).
172
+ */
173
+ function LayerOption({ name, inputId, children }) {
174
+ return (_jsxs(Grid, { container: true, direction: "row", alignItems: "center", justifyContent: "center", children: [_jsx(Grid, { item: true, xs: 6, children: _jsxs(InputLabel, { htmlFor: inputId, children: [name, ":"] }) }), _jsx(Grid, { item: true, xs: 6, children: children })] }));
175
+ }
176
+ /**
177
+ * Gloabl options for all channels (opacity, colormap, etc.).
178
+ * @prop {string} colormap What colormap is currently selected (None, viridis etc.).
179
+ * @prop {number} opacity Current opacity value.
180
+ * @prop {function} handleColormapChange Callback for when colormap changes.
181
+ * @prop {function} handleOpacityChange Callback for when opacity changes.
182
+ * @prop {object} globalControlLabels All available options for global control (z and t).
183
+ * @prop {function} handleGlobalChannelsSelectionChange Callback for global selection changes.
184
+ * @prop {function} handleDomainChange Callback for domain type changes (full or min/max).
185
+ * @prop {array} channels Current channel object for inferring the current global selection.
186
+ * @prop {array} dimensions Currently available dimensions (channel, z, t etc.).
187
+ * @prop {string} domainType One of Max/Min or Full (soon presets as well).
188
+ * @prop {boolean} disableChannelsIfRgbDetected Whether or not we need colormap controllers if RGB.
189
+ */
190
+ function LayerOptions({ colormap, opacity, handleColormapChange, handleOpacityChange, handleTransparentColorChange, globalControlLabels, globalLabelValues, handleGlobalChannelsSelectionChange, handleSliderChange, handleDomainChange, transparentColor, channels, domainType, disableChannelsIfRgbDetected, shouldShowTransparentColor, shouldShowDomain, shouldShowColormap, use3d, loader, handleMultiPropertyChange, resolution, disable3d, setRasterLayerCallback, setAreAllChannelsLoading, setViewState, spatialHeight, spatialWidth, modelMatrix, }) {
191
+ const { labels, shape } = Array.isArray(loader.data) ? loader.data[0] : loader.data;
192
+ const hasDimensionsAndChannels = labels.length > 0 && channels.length > 0;
193
+ const hasZStack = shape[labels.indexOf('z')] > 1;
194
+ // Only show volume button if we can actually view resolutions.
195
+ const hasViewableResolutions = Boolean(Array.from({
196
+ length: loader.data.length,
197
+ }).filter((_, res) => canLoadResolution(loader.data, res)).length);
198
+ return (_jsxs(Grid, { container: true, direction: "column", style: { width: '100%' }, children: [hasZStack
199
+ && !disable3d
200
+ && hasViewableResolutions
201
+ && (_jsx(VolumeDropdown, { loader: loader, handleSliderChange: handleSliderChange, handleDomainChange: handleDomainChange, channels: channels, handleMultiPropertyChange: handleMultiPropertyChange, resolution: resolution, disable3d: disable3d, setRasterLayerCallback: setRasterLayerCallback, setAreAllChannelsLoading: setAreAllChannelsLoading, setViewState: setViewState, spatialHeight: spatialHeight, spatialWidth: spatialWidth, use3d: use3d, modelMatrix: modelMatrix })), hasDimensionsAndChannels
202
+ && !use3d
203
+ && globalControlLabels.map(field => shape[labels.indexOf(field)] > 1 && (_jsx(LayerOption, { name: field, inputId: `${field}-slider`, children: _jsx(GlobalSelectionSlider, { field: field, value: globalLabelValues[field], handleChange: handleGlobalChannelsSelectionChange, possibleValues: range(shape[labels.indexOf(field)]) }) }, field))), !disableChannelsIfRgbDetected ? (_jsxs(_Fragment, { children: [shouldShowColormap && (_jsx(Grid, { item: true, children: _jsx(LayerOption, { name: "Colormap", inputId: "colormap-select", children: _jsx(ColormapSelect, { value: colormap || '', inputId: "colormap-select", handleChange: handleColormapChange }) }) })), shouldShowDomain && (_jsx(Grid, { item: true, children: _jsx(LayerOption, { name: "Domain", inputId: "domain-selector", children: _jsx(SliderDomainSelector, { value: domainType || DEFAULT_RASTER_DOMAIN_TYPE, handleChange: (value) => {
204
+ handleDomainChange(value);
205
+ } }) }) }))] })) : null, !use3d && (_jsx(Grid, { item: true, children: _jsx(LayerOption, { name: "Opacity", inputId: "opacity-slider", children: _jsx(OpacitySlider, { value: opacity, handleChange: handleOpacityChange }) }) })), shouldShowTransparentColor && !use3d && (_jsx(Grid, { item: true, children: _jsx(LayerOption, { name: "Zero Transparent", inputId: "transparent-color-selector", children: _jsx(TransparentColorCheckbox, { value: transparentColor, handleChange: handleTransparentColorChange }) }) }))] }));
206
+ }
207
+ export default LayerOptions;
@@ -0,0 +1,35 @@
1
+ export default RasterChannelController;
2
+ /**
3
+ * Controller for the handling the colormapping sliders.
4
+ * @prop {boolean} visibility Whether or not this channel is "on"
5
+ * @prop {array} slider Current slider range.
6
+ * @prop {array} color Current color for this channel.
7
+ * @prop {array} domain Current max/min for this channel.
8
+ * @prop {string} dimName Name of the dimensions this slider controls (usually "channel").
9
+ * @prop {boolean} colormapOn Whether or not the colormap (viridis, magma etc.) is on.
10
+ * @prop {object} channelOptions All available options for this dimension (i.e channel names).
11
+ * @prop {function} handlePropertyChange Callback for when a property (color, slider etc.) changes.
12
+ * @prop {function} handleChannelRemove When a channel is removed, this is called.
13
+ * @prop {function} handleIQRUpdate When the IQR button is clicked, this is called.
14
+ * @prop {number} selectionIndex The current numeric index of the selection.
15
+ */
16
+ declare function RasterChannelController({ visibility, slider, color, channels, channelId, domainType: newDomainType, dimName, theme, loader, colormapOn, channelOptions, handlePropertyChange, handleChannelRemove, handleIQRUpdate, selectionIndex, isLoading, use3d: newUse3d, }: {
17
+ visibility?: boolean | undefined;
18
+ slider: any;
19
+ color: any;
20
+ channels: any;
21
+ channelId: any;
22
+ domainType: any;
23
+ dimName: any;
24
+ theme: any;
25
+ loader: any;
26
+ colormapOn: any;
27
+ channelOptions: any;
28
+ handlePropertyChange: any;
29
+ handleChannelRemove: any;
30
+ handleIQRUpdate: any;
31
+ selectionIndex: any;
32
+ isLoading: any;
33
+ use3d: any;
34
+ }): JSX.Element;
35
+ //# sourceMappingURL=RasterChannelController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RasterChannelController.d.ts","sourceRoot":"","sources":["../src/RasterChannelController.js"],"names":[],"mappings":";AAqFA;;;;;;;;;;;;;GAaG;AACH;;;;;;;;;;;;;;;;;;gBA+IC"}
@@ -0,0 +1,150 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React, { useCallback, useState, useEffect } from 'react';
3
+ import { Grid, Slider } from '@material-ui/core';
4
+ import { debounce, isEqual } from 'lodash-es';
5
+ import { getSourceFromLoader } from '@vitessce/spatial-utils';
6
+ import ChannelOptions from './ChannelOptions.js';
7
+ import { DOMAINS } from './constants.js';
8
+ import { getMultiSelectionStats, toRgbUIString } from './utils.js';
9
+ import { ChannelSelectionDropdown, ChannelVisibilityCheckbox, } from './shared-channel-controls.js';
10
+ function abbreviateNumber(value) {
11
+ // Return an abbreviated representation of value, in 5 characters or less.
12
+ const maxLength = 5;
13
+ let maxNaiveDigits = maxLength;
14
+ /* eslint-disable no-plusplus */
15
+ if (!Number.isInteger(value)) {
16
+ --maxNaiveDigits;
17
+ } // Wasted on "."
18
+ if (value < 1) {
19
+ --maxNaiveDigits;
20
+ } // Wasted on "0."
21
+ /* eslint-disable no-plusplus */
22
+ const naive = Intl.NumberFormat('en-US', {
23
+ maximumSignificantDigits: maxNaiveDigits,
24
+ useGrouping: false,
25
+ }).format(value);
26
+ if (naive.length <= maxLength)
27
+ return naive;
28
+ // "e+9" consumes 3 characters, so if we even had two significant digits,
29
+ // it would take take us to six characters, including the decimal point.
30
+ return value.toExponential(0);
31
+ }
32
+ /**
33
+ * Slider for controlling current colormap.
34
+ * @prop {string} color Current color for this channel.
35
+ * @prop {arry} slider Current value of the slider.
36
+ * @prop {function} handleChange Callback for each slider change.
37
+ * @prop {array} domain Current max/min allowable slider values.
38
+ */
39
+ function ChannelSlider({ color, slider = [0, 0], handleChange, domain = [0, 0], dtype, disabled, }) {
40
+ const [min, max] = domain;
41
+ const sliderCopy = slider.slice();
42
+ if (slider[0] < min) {
43
+ sliderCopy[0] = min;
44
+ }
45
+ if (slider[1] > max) {
46
+ sliderCopy[1] = max;
47
+ }
48
+ const handleChangeDebounced = useCallback(debounce(handleChange, 3, { trailing: true }), [handleChange]);
49
+ const step = max - min < 500 && dtype.startsWith('Float') ? (max - min) / 500 : 1;
50
+ return (_jsx(Slider, { value: slider, valueLabelFormat: abbreviateNumber, onChange: (e, v) => handleChangeDebounced(v), valueLabelDisplay: "auto", getAriaLabel: () => `${color}-${slider}`, min: min, max: max, step: step, orientation: "horizontal", style: { color, marginTop: '7px' }, disabled: disabled }));
51
+ }
52
+ /**
53
+ * Controller for the handling the colormapping sliders.
54
+ * @prop {boolean} visibility Whether or not this channel is "on"
55
+ * @prop {array} slider Current slider range.
56
+ * @prop {array} color Current color for this channel.
57
+ * @prop {array} domain Current max/min for this channel.
58
+ * @prop {string} dimName Name of the dimensions this slider controls (usually "channel").
59
+ * @prop {boolean} colormapOn Whether or not the colormap (viridis, magma etc.) is on.
60
+ * @prop {object} channelOptions All available options for this dimension (i.e channel names).
61
+ * @prop {function} handlePropertyChange Callback for when a property (color, slider etc.) changes.
62
+ * @prop {function} handleChannelRemove When a channel is removed, this is called.
63
+ * @prop {function} handleIQRUpdate When the IQR button is clicked, this is called.
64
+ * @prop {number} selectionIndex The current numeric index of the selection.
65
+ */
66
+ function RasterChannelController({ visibility = false, slider, color, channels, channelId, domainType: newDomainType, dimName, theme, loader, colormapOn, channelOptions, handlePropertyChange, handleChannelRemove, handleIQRUpdate, selectionIndex, isLoading, use3d: newUse3d, }) {
67
+ const { dtype } = getSourceFromLoader(loader);
68
+ const [domain, setDomain] = useState(null);
69
+ const [domainType, setDomainType] = useState(null);
70
+ const [use3d, setUse3d] = useState(null);
71
+ const [selection, setSelection] = useState([
72
+ { ...channels[channelId].selection },
73
+ ]);
74
+ const rgbColor = toRgbUIString(colormapOn, color, theme);
75
+ useEffect(() => {
76
+ // Use mounted to prevent state updates/re-renders after the component has been unmounted.
77
+ // All state updates should happen within the mounted check.
78
+ let mounted = true;
79
+ if (dtype && loader && channels) {
80
+ const selections = [{ ...channels[channelId].selection }];
81
+ let domains;
82
+ const hasDomainChanged = newDomainType !== domainType;
83
+ const has3dChanged = use3d !== newUse3d;
84
+ const hasSelectionChanged = !isEqual(selections, selection);
85
+ if (hasDomainChanged || hasSelectionChanged || has3dChanged) {
86
+ if (newDomainType === 'Full') {
87
+ domains = [DOMAINS[dtype]];
88
+ const [newDomain] = domains;
89
+ if (mounted) {
90
+ setDomain(newDomain);
91
+ setDomainType(newDomainType);
92
+ if (hasSelectionChanged) {
93
+ setSelection(selections);
94
+ }
95
+ if (has3dChanged) {
96
+ setUse3d(newUse3d);
97
+ }
98
+ }
99
+ }
100
+ else {
101
+ getMultiSelectionStats({
102
+ loader: loader.data,
103
+ selections,
104
+ use3d: newUse3d,
105
+ }).then((stats) => {
106
+ // eslint-disable-next-line prefer-destructuring
107
+ domains = stats.domains;
108
+ const [newDomain] = domains;
109
+ if (mounted) {
110
+ setDomain(newDomain);
111
+ setDomainType(newDomainType);
112
+ if (hasSelectionChanged) {
113
+ setSelection(selections);
114
+ }
115
+ if (has3dChanged) {
116
+ setUse3d(newUse3d);
117
+ }
118
+ }
119
+ });
120
+ }
121
+ }
122
+ }
123
+ return () => {
124
+ mounted = false;
125
+ };
126
+ }, [
127
+ domainType,
128
+ channels,
129
+ channelId,
130
+ loader,
131
+ dtype,
132
+ newDomainType,
133
+ selection,
134
+ newUse3d,
135
+ use3d,
136
+ ]);
137
+ /* A valid selection is defined by an object where the keys are
138
+ * the name of a dimension of the data, and the values are the
139
+ * index of the image along that particular dimension.
140
+ *
141
+ * Since we currently only support making a selection along one
142
+ * addtional dimension (i.e. the dropdown just has channels or mz)
143
+ * we have a helper function to create the selection.
144
+ *
145
+ * e.g { channel: 2 } // channel dimension, third channel
146
+ */
147
+ const createSelection = index => ({ [dimName]: index });
148
+ return (_jsxs(Grid, { container: true, direction: "column", m: 1, justifyContent: "center", children: [_jsxs(Grid, { container: true, direction: "row", justifyContent: "space-between", children: [_jsx(Grid, { item: true, xs: 10, children: _jsx(ChannelSelectionDropdown, { handleChange: v => handlePropertyChange('selection', createSelection(v)), selectionIndex: selectionIndex, channelOptions: channelOptions, disabled: isLoading }) }), _jsx(Grid, { item: true, xs: 1, style: { marginTop: '4px' }, children: _jsx(ChannelOptions, { handlePropertyChange: handlePropertyChange, handleChannelRemove: handleChannelRemove, handleIQRUpdate: handleIQRUpdate, disabled: isLoading }) })] }), _jsxs(Grid, { container: true, direction: "row", justifyContent: "space-between", children: [_jsx(Grid, { item: true, xs: 2, children: _jsx(ChannelVisibilityCheckbox, { color: rgbColor, checked: visibility, toggle: () => handlePropertyChange('visible', !visibility), disabled: isLoading }) }), _jsx(Grid, { item: true, xs: 9, children: _jsx(ChannelSlider, { color: rgbColor, slider: slider, domain: domain || DOMAINS[dtype], dtype: dtype, handleChange: v => handlePropertyChange('slider', v), disabled: isLoading }) })] })] }));
149
+ }
150
+ export default RasterChannelController;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=RasterChannelController.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RasterChannelController.test.d.ts","sourceRoot":"","sources":["../src/RasterChannelController.test.js"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import { toRgbUIString } from './utils.js';
2
+ const GREY = [220, 220, 220];
3
+ describe('layer-controller/RasterChannelController.js', () => {
4
+ describe('toRgbUIString()', () => {
5
+ it('Maps color value to itself when colormap off and not white with dark theme', () => {
6
+ expect(toRgbUIString(false, [200, 200, 200], 'dark')).toEqual(`rgb(${[200, 200, 200]})`);
7
+ });
8
+ it('Maps color value to grey when colormap on with dark theme', () => {
9
+ expect(toRgbUIString(true, [200, 200, 200], 'dark')).toEqual(`rgb(${GREY})`);
10
+ });
11
+ it('Maps color value to grey when colormap on with light theme', () => {
12
+ expect(toRgbUIString(true, [200, 200, 200], 'light')).toEqual(`rgb(${GREY})`);
13
+ });
14
+ it('Maps color value to grey when colormap off and white with light theme', () => {
15
+ expect(toRgbUIString(false, [255, 255, 255], 'light')).toEqual(`rgb(${GREY})`);
16
+ });
17
+ it('Maps color value to grey when colormap off and white with light theme', () => {
18
+ expect(toRgbUIString(false, [200, 200, 200], 'light')).toEqual(`rgb(${[200, 200, 200]})`);
19
+ });
20
+ });
21
+ });
@@ -0,0 +1,2 @@
1
+ export default function VectorLayerController(props: any): JSX.Element;
2
+ //# sourceMappingURL=VectorLayerController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VectorLayerController.d.ts","sourceRoot":"","sources":["../src/VectorLayerController.js"],"names":[],"mappings":"AAKA,uEAuDC"}
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import { Grid, Checkbox, Paper, Typography, Slider } from '@material-ui/core';
4
+ import { useControllerSectionStyles } from './styles.js';
5
+ export default function VectorLayerController(props) {
6
+ const { label, layer, layerType, handleLayerChange, } = props;
7
+ const slider = layer.opacity;
8
+ const isOn = layer.visible;
9
+ function handleSliderChange(v) {
10
+ if (layerType === 'cells') {
11
+ const stroked = v < 0.7;
12
+ handleLayerChange({ ...layer, opacity: v, stroked });
13
+ }
14
+ else {
15
+ handleLayerChange({ ...layer, opacity: v });
16
+ }
17
+ }
18
+ function handleCheckBoxChange(v) {
19
+ handleLayerChange({ ...layer, visible: v });
20
+ }
21
+ const classes = useControllerSectionStyles();
22
+ return (_jsx(Grid, { item: true, style: { marginTop: '10px' }, children: _jsxs(Paper, { className: classes.root, children: [_jsx(Typography, { style: {
23
+ padding: '15px 8px 0px 8px',
24
+ marginBottom: '-5px',
25
+ }, children: label }), _jsxs(Grid, { container: true, direction: "row", justifyContent: "space-between", children: [_jsx(Grid, { item: true, xs: 2, children: _jsx(Checkbox, { color: "primary", checked: isOn, onChange: (e, v) => handleCheckBoxChange(v) }) }), _jsx(Grid, { item: true, xs: 9, style: { paddingRight: '8px' }, children: _jsx(Slider, { value: slider, min: 0, max: 1, step: 0.001, onChange: (e, v) => handleSliderChange(v), style: { marginTop: '7px' }, orientation: "horizontal" }) })] })] }) }));
26
+ }
@@ -0,0 +1,16 @@
1
+ export default VolumeOptions;
2
+ declare function VolumeOptions({ handleSlicerSetting, handleRenderingModeChange, renderingMode, xSlice, ySlice, zSlice, use3d, loader, setViewState, spatialHeight, spatialWidth, modelMatrix, }: {
3
+ handleSlicerSetting: any;
4
+ handleRenderingModeChange: any;
5
+ renderingMode: any;
6
+ xSlice: any;
7
+ ySlice: any;
8
+ zSlice: any;
9
+ use3d: any;
10
+ loader: any;
11
+ setViewState: any;
12
+ spatialHeight: any;
13
+ spatialWidth: any;
14
+ modelMatrix: any;
15
+ }): JSX.Element;
16
+ //# sourceMappingURL=VolumeOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VolumeOptions.d.ts","sourceRoot":"","sources":["../src/VolumeOptions.js"],"names":[],"mappings":";AAqLA;;;;;;;;;;;;;gBAqCC"}
@@ -0,0 +1,71 @@
1
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import { Matrix4 } from 'math.gl';
4
+ import { Grid, Typography, Button, makeStyles, createStyles, FormControl, Select, InputLabel, Slider, } from '@material-ui/core';
5
+ import { viv } from '@vitessce/gl';
6
+ import { abbreviateNumber, getBoundingCube } from './utils.js';
7
+ import { useSelectStyles } from './styles.js';
8
+ const useSlicerStyles = makeStyles(theme => createStyles({
9
+ enabled: {},
10
+ disabled: {
11
+ color: theme.palette.text.disabled,
12
+ // Because of the .5 opacity of the disabled color in the theme, and the fact
13
+ // that there are multiple overlaid parts to the slider,
14
+ // this needs to be set manually for the desired effect.
15
+ '& .MuiSlider-thumb': {
16
+ color: 'rgb(100, 100, 100, 1.0)',
17
+ },
18
+ '& .MuiSlider-track': {
19
+ color: 'rgb(100, 100, 100, 1.0)',
20
+ },
21
+ },
22
+ }));
23
+ const Slicer = ({ xSlice, ySlice, zSlice, handleSlicerSetting, loader, use3d, }) => {
24
+ const [xSliceInit, ySliceInit, zSliceInit] = getBoundingCube(loader.data);
25
+ const sliceValuesAndSetSliceFunctions = [
26
+ [
27
+ xSlice,
28
+ xSliceNew => handleSlicerSetting('x', xSliceNew),
29
+ 'x',
30
+ xSliceInit,
31
+ ],
32
+ [
33
+ ySlice,
34
+ ySliceNew => handleSlicerSetting('y', ySliceNew),
35
+ 'y',
36
+ ySliceInit,
37
+ ],
38
+ [
39
+ zSlice,
40
+ zSliceNew => handleSlicerSetting('z', zSliceNew),
41
+ 'z',
42
+ zSliceInit,
43
+ ],
44
+ ];
45
+ const classes = useSlicerStyles();
46
+ const Slicers = sliceValuesAndSetSliceFunctions.map(([val, setVal, label, [min, max]]) => (_jsxs(Grid, { container: true, direction: "row", justifyContent: "flex-start", alignItems: "center", children: [_jsx(Grid, { item: true, xs: 1, children: _jsxs(Typography, { className: !use3d ? classes.disabled : classes.enabled, style: { marginBottom: 0 }, children: [label, ":"] }) }), _jsx(Grid, { item: true, xs: 11, children: _jsx(Slider, { disabled: !use3d, className: !use3d ? classes.disabled : classes.enabled, value: val, onChange: (e, v) => setVal(v), valueLabelDisplay: "auto", valueLabelFormat: v => abbreviateNumber(v), getAriaLabel: () => `${label} slider`, min: min, max: max, step: 0.005, orientation: "horizontal" }) })] }, label)));
47
+ return (_jsxs(_Fragment, { children: [_jsxs(Typography, { className: !use3d ? classes.disabled : classes.enabled, style: { marginTop: 16, marginBottom: 0 }, children: ["Clipping Planes:", ' '] }), ' ', Slicers] }));
48
+ };
49
+ const renderingOptions = Object.values(viv.RENDERING_MODES);
50
+ function RenderingModeSelect({ handleRenderingModeChange, renderingMode, use3d, }) {
51
+ const classes = useSelectStyles();
52
+ // Empty option allows for displaying the title of the dropdown fully in the UI.
53
+ const options = !use3d ? [...renderingOptions, ''] : renderingOptions;
54
+ return (_jsxs(FormControl, { fullWidth: true, children: [_jsx(InputLabel, { htmlFor: "rendering-mode-select", children: "Rendering Mode" }), _jsx(Select, { native: true, onChange: e => handleRenderingModeChange(e.target.value), value: use3d ? renderingMode : '', inputProps: {
55
+ name: 'rendering-mode',
56
+ id: 'rendering-mode-select',
57
+ }, disabled: !use3d, classes: { root: classes.selectRoot }, children: options.map(name => (_jsx("option", { value: name, children: name }, name))) })] }));
58
+ }
59
+ const ReCenterButton = ({ setViewState, use3d, spatialHeight, spatialWidth, loader, modelMatrix, }) => (_jsx(Grid, { item: true, xs: "auto", children: _jsx(Button, { onClick: () => {
60
+ const defaultViewState = viv.getDefaultInitialViewState(loader.data, { height: spatialHeight, width: spatialWidth }, 1.5, use3d, new Matrix4(modelMatrix));
61
+ setViewState({
62
+ ...defaultViewState,
63
+ rotationX: 0,
64
+ rotationOrbit: 0,
65
+ });
66
+ }, disabled: !use3d, style: {
67
+ padding: 0,
68
+ marginBottom: 6,
69
+ }, children: "Re-Center" }) }, "recenter"));
70
+ const VolumeOptions = ({ handleSlicerSetting, handleRenderingModeChange, renderingMode, xSlice, ySlice, zSlice, use3d, loader, setViewState, spatialHeight, spatialWidth, modelMatrix, }) => (_jsxs(_Fragment, { children: [_jsx(RenderingModeSelect, { handleRenderingModeChange: handleRenderingModeChange, renderingMode: renderingMode, use3d: use3d }), _jsx(Slicer, { xSlice: xSlice, ySlice: ySlice, zSlice: zSlice, handleSlicerSetting: handleSlicerSetting, use3d: use3d, loader: loader }), _jsx(ReCenterButton, { setViewState: setViewState, use3d: use3d, spatialHeight: spatialHeight, spatialWidth: spatialWidth, loader: loader, modelMatrix: modelMatrix })] }));
71
+ export default VolumeOptions;
@@ -0,0 +1,2 @@
1
+ export const DOMAINS: {};
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.js"],"names":[],"mappings":"AAaA,yBAAoC"}
@@ -0,0 +1,12 @@
1
+ import { viv } from '@vitessce/gl';
2
+ function getDomains() {
3
+ const domains = {};
4
+ const needMin = ['Int8', 'Int16', 'Int32'];
5
+ Object.keys(viv.DTYPE_VALUES).forEach((dtype) => {
6
+ const { max } = viv.DTYPE_VALUES[dtype];
7
+ const min = needMin.includes(dtype) ? -(max + 1) : 0;
8
+ domains[dtype] = [min, max];
9
+ });
10
+ return domains;
11
+ }
12
+ export const DOMAINS = getDomains();
@@ -0,0 +1,4 @@
1
+ export { LayerControllerSubscriber } from "./LayerControllerSubscriber.js";
2
+ export { default as LayerController } from "./LayerController.js";
3
+ export { default as VectorLayerController } from "./VectorLayerController.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
package/dist-tsc/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { LayerControllerSubscriber, register } from './LayerControllerSubscriber';
2
- export { default as LayerController } from './LayerController';
3
- export { default as VectorLayerController } from './VectorLayerController';
1
+ export { LayerControllerSubscriber } from './LayerControllerSubscriber.js';
2
+ export { default as LayerController } from './LayerController.js';
3
+ export { default as VectorLayerController } from './VectorLayerController.js';
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Dropdown for selecting a channel.
3
+ * @prop {function} handleChange Callback for each new selection.
4
+ * @prop {array} channelOptions List of available selections, like ['DAPI', 'FITC', ...].
5
+ * @prop {boolean} disabled Whether or not the component is disabled.
6
+ * @prop {number} selectionIndex Current numeric index of a selection.
7
+ */
8
+ export function ChannelSelectionDropdown({ handleChange, disabled, channelOptions, selectionIndex, }: {
9
+ handleChange: any;
10
+ disabled: any;
11
+ channelOptions: any;
12
+ selectionIndex: any;
13
+ }): JSX.Element;
14
+ /**
15
+ * Checkbox for toggling on/off of a channel.
16
+ * @prop {string} color Current color for this channel.
17
+ * @prop {boolean} checked Whether or not this channel is "on".
18
+ * @prop {boolean} disabled Whether or not the component is disabled.
19
+ * @prop {function} toggle Callback for toggling on/off.
20
+ */
21
+ export function ChannelVisibilityCheckbox({ color, checked, toggle, disabled, }: {
22
+ color: any;
23
+ checked: any;
24
+ toggle: any;
25
+ disabled: any;
26
+ }): JSX.Element;
27
+ //# sourceMappingURL=shared-channel-controls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-channel-controls.d.ts","sourceRoot":"","sources":["../src/shared-channel-controls.js"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH;;;;;gBAqBC;AAED;;;;;;GAMG;AACH;;;;;gBAWC"}