@vitessce/layer-controller 2.0.3-beta.0 → 2.0.3

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