@vitessce/layer-controller 2.0.0-beta.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.
- package/LICENSE +21 -0
- package/dist/BitmaskChannelController.js +31 -0
- package/dist/ChannelOptions.js +39 -0
- package/dist/ColorPalette.js +31 -0
- package/dist/ImageAddButton.js +28 -0
- package/dist/LayerController.js +310 -0
- package/dist/LayerControllerSubscriber.js +197 -0
- package/dist/LayerOptions.js +210 -0
- package/dist/RasterChannelController.js +160 -0
- package/dist/RasterChannelController.test.js +21 -0
- package/dist/VectorLayerController.js +30 -0
- package/dist/VolumeOptions.js +78 -0
- package/dist/constants.js +12 -0
- package/dist/index.js +3 -0
- package/dist/shared-channel-controls.js +26 -0
- package/dist/styles.js +103 -0
- package/dist/utils.js +109 -0
- package/package.json +38 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/* eslint-disable dot-notation */
|
|
3
|
+
/* eslint-disable no-unused-vars */
|
|
4
|
+
import React, { useCallback, useRef, forwardRef, } from 'react';
|
|
5
|
+
import Grid from '@material-ui/core/Grid';
|
|
6
|
+
import { TitleInfo, useReady, useClosestVitessceContainerSize, useWindowDimensions, useImageData, useObsLocationsData, useObsSegmentationsData, useCoordination, useLoaders, useAuxiliaryCoordination, useComponentLayout, registerPluginViewType, } from '@vitessce/vit-s';
|
|
7
|
+
import { ViewType, COMPONENT_COORDINATION_TYPES } from '@vitessce/constants-internal';
|
|
8
|
+
import { capitalize } from '@vitessce/utils';
|
|
9
|
+
import { initializeLayerChannels, DEFAULT_RASTER_LAYER_PROPS } from '@vitessce/gl';
|
|
10
|
+
import RasterChannelController from './RasterChannelController';
|
|
11
|
+
import BitmaskChannelController from './BitmaskChannelController';
|
|
12
|
+
import VectorLayerController from './VectorLayerController';
|
|
13
|
+
import LayerController from './LayerController';
|
|
14
|
+
import ImageAddButton from './ImageAddButton';
|
|
15
|
+
// LayerController is memoized to prevent updates from prop changes that
|
|
16
|
+
// are caused by view state updates i.e zooming and panning within
|
|
17
|
+
// the actual Spatial component. Re-rendering this component is very
|
|
18
|
+
// expensive so we have to be careful with props in this file in general.
|
|
19
|
+
const LayerControllerMemoized = React.memo(forwardRef((props, ref) => {
|
|
20
|
+
const { title, removeGridComponent, theme, isReady, dataset, obsType, moleculesLayer, setMoleculesLayer, cellsLayer, // May be one polygon layer object or an array of bitmask layers.
|
|
21
|
+
setCellsLayer, rasterLayers, imageLayerLoaders, imageLayerMeta, imageLayerCallbacks, setImageLayerCallbacks, areLoadingImageChannels, setAreLoadingImageChannels, handleRasterLayerChange, handleRasterLayerRemove, obsSegmentationsType, segmentationLayerLoaders, segmentationLayerMeta, segmentationLayerCallbacks, setSegmentationLayerCallbacks, areLoadingSegmentationChannels, setAreLoadingSegmentationChannels, handleSegmentationLayerChange, handleSegmentationLayerRemove, disable3d, globalDisable3d, disableChannelsIfRgbDetected, layerIs3DIndex, setZoom, setTargetX, setTargetY, setTargetZ, setRotationX, setRotationOrbit, componentHeight, componentWidth, spatialLayout, handleImageAdd, enableLayerButtonsWithOneLayer, } = props;
|
|
22
|
+
const shouldShowImageLayerButton = Boolean(enableLayerButtonsWithOneLayer || imageLayerLoaders?.length > 1);
|
|
23
|
+
return (_jsx(TitleInfo, { title: title, isScroll: true, removeGridComponent: removeGridComponent, theme: theme, isReady: isReady, children: _jsxs("div", { className: "layer-controller-container", ref: ref, children: [moleculesLayer && (_jsx(VectorLayerController, { label: "Molecules", layerType: "molecules", layer: moleculesLayer, handleLayerChange: setMoleculesLayer }, `${dataset}-molecules`)), cellsLayer && obsSegmentationsType === 'polygon' && (_jsx(VectorLayerController, { label: `${capitalize(obsType)} Segmentations`, layerType: "cells", layer: cellsLayer, handleLayerChange: setCellsLayer }, `${dataset}-cells`)), cellsLayer && obsSegmentationsType === 'bitmask'
|
|
24
|
+
&& cellsLayer.map((layer, i) => {
|
|
25
|
+
const { index } = layer;
|
|
26
|
+
const loader = segmentationLayerLoaders?.[index];
|
|
27
|
+
const layerMeta = segmentationLayerMeta?.[index];
|
|
28
|
+
const isRaster = false;
|
|
29
|
+
// Set up the call back mechanism so that each layer manages
|
|
30
|
+
// callbacks/loading state for itself and its channels.
|
|
31
|
+
const setSegmentationLayerCallback = (cb) => {
|
|
32
|
+
const newRasterLayersCallbacks = [
|
|
33
|
+
...(imageLayerCallbacks || []),
|
|
34
|
+
];
|
|
35
|
+
newRasterLayersCallbacks[i] = cb;
|
|
36
|
+
setSegmentationLayerCallbacks(newRasterLayersCallbacks);
|
|
37
|
+
};
|
|
38
|
+
const areLayerChannelsLoading = (areLoadingSegmentationChannels || [])[i] || [];
|
|
39
|
+
const setAreLayerChannelsLoading = (v) => {
|
|
40
|
+
const newAreLoadingImageChannels = [
|
|
41
|
+
...(areLoadingSegmentationChannels || []),
|
|
42
|
+
];
|
|
43
|
+
newAreLoadingImageChannels[i] = v;
|
|
44
|
+
setAreLoadingSegmentationChannels(newAreLoadingImageChannels);
|
|
45
|
+
};
|
|
46
|
+
return loader && layerMeta ? (_jsx(Grid
|
|
47
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
48
|
+
, { item: true, style: { marginTop: '10px' }, children: _jsx(LayerController, { name: layerMeta.name, layer: layer, loader: loader, theme: theme, handleLayerChange: v => handleSegmentationLayerChange(v, i), handleLayerRemove: () => handleSegmentationLayerRemove(i), ChannelController: BitmaskChannelController, shouldShowTransparentColor: isRaster, shouldShowDomain: isRaster, shouldShowColormap: isRaster,
|
|
49
|
+
// Disable 3D if given explicit instructions to do so
|
|
50
|
+
// or if another layer is using 3D mode.
|
|
51
|
+
disable3d: globalDisable3d
|
|
52
|
+
|| (disable3d || []).indexOf(layerMeta.name) >= 0
|
|
53
|
+
|| (typeof layerIs3DIndex === 'number'
|
|
54
|
+
&& layerIs3DIndex !== -1
|
|
55
|
+
&& layerIs3DIndex !== i), disabled: typeof layerIs3DIndex === 'number'
|
|
56
|
+
&& layerIs3DIndex !== -1
|
|
57
|
+
&& layerIs3DIndex !== i, disableChannelsIfRgbDetected: disableChannelsIfRgbDetected, imageLayerCallbacks: imageLayerCallbacks, setImageLayerCallback: setSegmentationLayerCallback, setViewState: ({ zoom: newZoom, target, rotationX: newRotationX, rotationOrbit: newRotationOrbit, }) => {
|
|
58
|
+
setZoom(newZoom);
|
|
59
|
+
setTargetX(target[0]);
|
|
60
|
+
setTargetY(target[1]);
|
|
61
|
+
setTargetZ(target[2]);
|
|
62
|
+
setRotationX(newRotationX);
|
|
63
|
+
setRotationOrbit(newRotationOrbit);
|
|
64
|
+
}, setAreLayerChannelsLoading: setAreLayerChannelsLoading, areLayerChannelsLoading: areLayerChannelsLoading, spatialHeight: (componentHeight * (spatialLayout ? spatialLayout.h : 1)) / 12, spatialWidth: (componentWidth * (spatialLayout ? spatialLayout.w : 1)) / 12, shouldShowRemoveLayerButton: shouldShowImageLayerButton }) }, `${dataset}-raster-${index}-${i}`)) : null;
|
|
65
|
+
}), rasterLayers
|
|
66
|
+
&& rasterLayers.map((layer, i) => {
|
|
67
|
+
const { index } = layer;
|
|
68
|
+
const loader = imageLayerLoaders?.[index];
|
|
69
|
+
const layerMeta = imageLayerMeta?.[index];
|
|
70
|
+
// Bitmasks are handled above.
|
|
71
|
+
const isRaster = true;
|
|
72
|
+
// Set up the call back mechanism so that each layer manages
|
|
73
|
+
// callbacks/loading state for itself and its channels.
|
|
74
|
+
const setImageLayerCallback = (cb) => {
|
|
75
|
+
const newRasterLayersCallbacks = [
|
|
76
|
+
...(imageLayerCallbacks || []),
|
|
77
|
+
];
|
|
78
|
+
newRasterLayersCallbacks[i] = cb;
|
|
79
|
+
setImageLayerCallbacks(newRasterLayersCallbacks);
|
|
80
|
+
};
|
|
81
|
+
const areLayerChannelsLoading = (areLoadingImageChannels || [])[i] || [];
|
|
82
|
+
const setAreLayerChannelsLoading = (v) => {
|
|
83
|
+
const newAreLoadingImageChannels = [
|
|
84
|
+
...(areLoadingImageChannels || []),
|
|
85
|
+
];
|
|
86
|
+
newAreLoadingImageChannels[i] = v;
|
|
87
|
+
setAreLoadingImageChannels(newAreLoadingImageChannels);
|
|
88
|
+
};
|
|
89
|
+
return loader && layerMeta ? (_jsx(Grid
|
|
90
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
91
|
+
, { item: true, style: { marginTop: '10px' }, children: _jsx(LayerController, { name: layerMeta.name, layer: layer, loader: loader, theme: theme, handleLayerChange: v => handleRasterLayerChange(v, i), handleLayerRemove: () => handleRasterLayerRemove(i), ChannelController: RasterChannelController, shouldShowTransparentColor: isRaster, shouldShowDomain: isRaster, shouldShowColormap: isRaster,
|
|
92
|
+
// Disable 3D if given explicit instructions to do so
|
|
93
|
+
// or if another layer is using 3D mode.
|
|
94
|
+
disable3d: globalDisable3d
|
|
95
|
+
|| (disable3d || []).indexOf(layerMeta.name) >= 0
|
|
96
|
+
|| (typeof layerIs3DIndex === 'number'
|
|
97
|
+
&& layerIs3DIndex !== -1
|
|
98
|
+
&& layerIs3DIndex !== i), disabled: typeof layerIs3DIndex === 'number'
|
|
99
|
+
&& layerIs3DIndex !== -1
|
|
100
|
+
&& layerIs3DIndex !== i, disableChannelsIfRgbDetected: disableChannelsIfRgbDetected, imageLayerCallbacks: imageLayerCallbacks, setImageLayerCallback: setImageLayerCallback, setViewState: ({ zoom: newZoom, target, rotationX: newRotationX, rotationOrbit: newRotationOrbit, }) => {
|
|
101
|
+
setZoom(newZoom);
|
|
102
|
+
setTargetX(target[0]);
|
|
103
|
+
setTargetY(target[1]);
|
|
104
|
+
setTargetZ(target[2]);
|
|
105
|
+
setRotationX(newRotationX);
|
|
106
|
+
setRotationOrbit(newRotationOrbit);
|
|
107
|
+
}, setAreLayerChannelsLoading: setAreLayerChannelsLoading, areLayerChannelsLoading: areLayerChannelsLoading, spatialHeight: (componentHeight * (spatialLayout ? spatialLayout.h : 1)) / 12, spatialWidth: (componentWidth * (spatialLayout ? spatialLayout.w : 1)) / 12, shouldShowRemoveLayerButton: shouldShowImageLayerButton }) }, `${dataset}-raster-${index}-${i}`)) : null;
|
|
108
|
+
}), shouldShowImageLayerButton
|
|
109
|
+
? (_jsx(Grid, { item: true, children: _jsx(ImageAddButton, { imageOptions: imageLayerMeta, handleImageAdd: handleImageAdd }) })) : null] }) }));
|
|
110
|
+
}));
|
|
111
|
+
/**
|
|
112
|
+
* A subscriber component for the spatial layer controller.
|
|
113
|
+
* @param {object} props
|
|
114
|
+
* @param {string} props.theme The current theme name.
|
|
115
|
+
* @param {object} props.coordinationScopes The mapping from coordination types to coordination
|
|
116
|
+
* scopes.
|
|
117
|
+
* @param {function} props.removeGridComponent The callback function to pass to TitleInfo,
|
|
118
|
+
* to call when the component has been removed from the grid.
|
|
119
|
+
* @param {string} props.title The component title.
|
|
120
|
+
* @param {Object} props.disable3d Which layers should have 3D disabled (from `raster.json` names).
|
|
121
|
+
* @param {boolean} props.globalDisable3d Disable 3D for all layers. Overrides the `disable3d` prop.
|
|
122
|
+
* @param {boolean} props.disableChannelsIfRgbDetected Disable channel controls if an
|
|
123
|
+
* RGB image is detected i.e 3 channel 8 bit.
|
|
124
|
+
* @param {boolean} props.enableLayerButtonsWithOneLayer If there is only one layer,
|
|
125
|
+
* show the the layer add/remove buttons.
|
|
126
|
+
*/
|
|
127
|
+
export function LayerControllerSubscriber(props) {
|
|
128
|
+
const { coordinationScopes, removeGridComponent, theme, title = 'Spatial Layers', disable3d, globalDisable3d, disableChannelsIfRgbDetected, enableLayerButtonsWithOneLayer, } = props;
|
|
129
|
+
const loaders = useLoaders();
|
|
130
|
+
// Get "props" from the coordination space.
|
|
131
|
+
const [{ dataset, obsType, spatialImageLayer: rasterLayers, spatialSegmentationLayer: cellsLayer, spatialPointLayer: moleculesLayer, }, { setSpatialImageLayer: setRasterLayers, setSpatialSegmentationLayer: setCellsLayer, setSpatialPointLayer: setMoleculesLayer, setSpatialTargetX: setTargetX, setSpatialTargetY: setTargetY, setSpatialTargetZ: setTargetZ, setSpatialRotationX: setRotationX, setSpatialRotationOrbit: setRotationOrbit, setSpatialZoom: setZoom, },] = useCoordination(COMPONENT_COORDINATION_TYPES[ViewType.LAYER_CONTROLLER], coordinationScopes);
|
|
132
|
+
const [{ imageLayerCallbacks, areLoadingImageChannels, segmentationLayerCallbacks, areLoadingSegmentationChannels, }, { setImageLayerCallbacks, setAreLoadingImageChannels, setSegmentationLayerCallbacks, setAreLoadingSegmentationChannels, },] = useAuxiliaryCoordination(COMPONENT_COORDINATION_TYPES.layerController, coordinationScopes);
|
|
133
|
+
// Spatial layout + window size is needed for the "re-center" button to work properly.
|
|
134
|
+
// Dimensions of the Spatial component can be inferred and used for resetting view state to
|
|
135
|
+
// a nice, centered view.
|
|
136
|
+
const [spatialLayout] = useComponentLayout('spatial', ['spatialImageLayer'], coordinationScopes);
|
|
137
|
+
const layerControllerRef = useRef();
|
|
138
|
+
const [componentWidth, componentHeight] = useClosestVitessceContainerSize(layerControllerRef);
|
|
139
|
+
const { height: windowHeight, width: windowWidth } = useWindowDimensions();
|
|
140
|
+
// Get data from loaders using the data hooks.
|
|
141
|
+
// eslint-disable-next-line no-unused-vars
|
|
142
|
+
const [obsLocationsData, obsLocationsStatus] = useObsLocationsData(loaders, dataset, () => { }, false, { setSpatialPointLayer: setMoleculesLayer }, { spatialPointLayer: moleculesLayer }, {});
|
|
143
|
+
const [{ obsSegmentations, obsSegmentationsType }, obsSegmentationsStatus,] = useObsSegmentationsData(loaders, dataset, () => { }, false, { setSpatialSegmentationLayer: setCellsLayer }, { spatialSegmentationLayer: cellsLayer }, {});
|
|
144
|
+
const [{ image }, imageStatus] = useImageData(loaders, dataset, () => { }, false, { setSpatialImageLayer: setRasterLayers }, { spatialImageLayer: rasterLayers }, {});
|
|
145
|
+
const { loaders: imageLayerLoaders, meta: imageLayerMeta } = image || {};
|
|
146
|
+
const isReady = useReady([
|
|
147
|
+
obsLocationsStatus,
|
|
148
|
+
obsSegmentationsStatus,
|
|
149
|
+
imageStatus,
|
|
150
|
+
]);
|
|
151
|
+
const segmentationLayerLoaders = obsSegmentations && obsSegmentationsType === 'bitmask' ? obsSegmentations.loaders : null;
|
|
152
|
+
const segmentationLayerMeta = obsSegmentations && obsSegmentationsType === 'bitmask' ? obsSegmentations.meta : null;
|
|
153
|
+
// useCallback prevents new functions from propogating
|
|
154
|
+
// changes to the underlying component.
|
|
155
|
+
const handleImageAdd = useCallback(async (index) => {
|
|
156
|
+
const loader = imageLayerLoaders[index];
|
|
157
|
+
const newChannels = await initializeLayerChannels(loader, (rasterLayers[index] || {}).use3d);
|
|
158
|
+
const newLayer = {
|
|
159
|
+
index,
|
|
160
|
+
modelMatrix: imageLayerMeta[index]?.metadata?.transform?.matrix,
|
|
161
|
+
...DEFAULT_RASTER_LAYER_PROPS,
|
|
162
|
+
channels: newChannels,
|
|
163
|
+
type: imageLayerMeta[index]?.metadata?.isBitmask ? 'bitmask' : 'raster',
|
|
164
|
+
};
|
|
165
|
+
const newLayers = [...rasterLayers, newLayer];
|
|
166
|
+
setRasterLayers(newLayers);
|
|
167
|
+
}, [imageLayerLoaders, imageLayerMeta, rasterLayers, setRasterLayers]);
|
|
168
|
+
const handleRasterLayerChange = useCallback((newLayer, i) => {
|
|
169
|
+
const newLayers = [...rasterLayers];
|
|
170
|
+
newLayers[i] = newLayer;
|
|
171
|
+
setRasterLayers(newLayers);
|
|
172
|
+
}, [rasterLayers, setRasterLayers]);
|
|
173
|
+
const handleRasterLayerRemove = useCallback((i) => {
|
|
174
|
+
const newLayers = [...rasterLayers];
|
|
175
|
+
newLayers.splice(i, 1);
|
|
176
|
+
setRasterLayers(newLayers);
|
|
177
|
+
}, [rasterLayers, setRasterLayers]);
|
|
178
|
+
const handleSegmentationLayerChange = useCallback((newLayer, i) => {
|
|
179
|
+
// Currently only used when obsSegmentationsType is 'bitmask'
|
|
180
|
+
const newLayers = [...cellsLayer];
|
|
181
|
+
newLayers[i] = newLayer;
|
|
182
|
+
setCellsLayer(newLayers);
|
|
183
|
+
}, [cellsLayer, setCellsLayer]);
|
|
184
|
+
const handleSegmentationLayerRemove = useCallback((i) => {
|
|
185
|
+
// Currently only used when obsSegmentationsType is 'bitmask'
|
|
186
|
+
const newLayers = [...cellsLayer];
|
|
187
|
+
newLayers.splice(i, 1);
|
|
188
|
+
setCellsLayer(newLayers);
|
|
189
|
+
}, [cellsLayer, setCellsLayer]);
|
|
190
|
+
const layerIs3DIndex = rasterLayers?.findIndex && rasterLayers.findIndex(layer => layer.use3d);
|
|
191
|
+
return (_jsx(LayerControllerMemoized, { ref: layerControllerRef, title: title, removeGridComponent: removeGridComponent, theme: theme, isReady: isReady, moleculesLayer: moleculesLayer, dataset: dataset, obsType: obsType, setMoleculesLayer: setMoleculesLayer, cellsLayer: cellsLayer, setCellsLayer: setCellsLayer, rasterLayers: rasterLayers, imageLayerLoaders: imageLayerLoaders, imageLayerMeta: imageLayerMeta, imageLayerCallbacks: imageLayerCallbacks, setImageLayerCallbacks: setImageLayerCallbacks, areLoadingImageChannels: areLoadingImageChannels, setAreLoadingImageChannels: setAreLoadingImageChannels, handleRasterLayerChange: handleRasterLayerChange, handleRasterLayerRemove: handleRasterLayerRemove, obsSegmentationsType: obsSegmentationsType, segmentationLayerLoaders: segmentationLayerLoaders, segmentationLayerMeta: segmentationLayerMeta, segmentationLayerCallbacks: segmentationLayerCallbacks, setSegmentationLayerCallbacks: setSegmentationLayerCallbacks, areLoadingSegmentationChannels: areLoadingSegmentationChannels, setAreLoadingSegmentationChannels: setAreLoadingSegmentationChannels, handleSegmentationLayerChange: handleSegmentationLayerChange, handleSegmentationLayerRemove: handleSegmentationLayerRemove, disable3d: disable3d, globalDisable3d: globalDisable3d, layerIs3DIndex: layerIs3DIndex, disableChannelsIfRgbDetected: disableChannelsIfRgbDetected, enableLayerButtonsWithOneLayer: enableLayerButtonsWithOneLayer, setZoom: setZoom, setTargetX: setTargetX, setTargetY: setTargetY, setTargetZ: setTargetZ, setRotationX: setRotationX, setRotationOrbit: setRotationOrbit,
|
|
192
|
+
// Fall back to window for height and width.
|
|
193
|
+
componentHeight: componentHeight || windowHeight, componentWidth: componentWidth || windowWidth, spatialLayout: spatialLayout, handleImageAdd: handleImageAdd }));
|
|
194
|
+
}
|
|
195
|
+
export function register() {
|
|
196
|
+
registerPluginViewType(ViewType.LAYER_CONTROLLER, LayerControllerSubscriber, COMPONENT_COORDINATION_TYPES[ViewType.LAYER_CONTROLLER]);
|
|
197
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
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, DEFAULT_RASTER_DOMAIN_TYPE } from '@vitessce/gl';
|
|
11
|
+
import { COLORMAP_OPTIONS, canLoadResolution, formatBytes, getStatsForResolution, } from '@vitessce/utils';
|
|
12
|
+
import { getBoundingCube, getMultiSelectionStats, } from './utils';
|
|
13
|
+
import { StyledSelectionSlider, useSelectStyles } from './styles';
|
|
14
|
+
const DOMAIN_OPTIONS = ['Full', 'Min/Max'];
|
|
15
|
+
/**
|
|
16
|
+
* Wrapper for the dropdown that selects a colormap (None, viridis, magma, etc.).
|
|
17
|
+
* @prop {Object} loader Loader object with metadata.
|
|
18
|
+
* @prop {function} handleMultiPropertyChange Function to propgate multiple layer changes at once.
|
|
19
|
+
* This prevents updates from overridding each other.
|
|
20
|
+
* @prop {number} resolution Current 3D resolution.
|
|
21
|
+
* @prop {boolean} disable3d Whether or not to enable 3D selection
|
|
22
|
+
* @prop {function} setRasterLayerCallback Setter for callbacks that fire after raster/volume loads.
|
|
23
|
+
* @prop {function} setAreAllChannelsLoading Setter for whether or not a given channel is loading.
|
|
24
|
+
* @prop {Object} setViewState Setter for the current view state.
|
|
25
|
+
* @prop {number} spatialHeight Height of the spatial component.
|
|
26
|
+
* @prop {number} spatialWidth Width of the spatial component.
|
|
27
|
+
* @prop {object} channels Channels object.
|
|
28
|
+
* @prop {boolean} use3d Whether or not 3D is enabled for this layer.
|
|
29
|
+
*/
|
|
30
|
+
function VolumeDropdown({ loader: loaderWithMeta, handleMultiPropertyChange, resolution: currResolution, disable3d, setRasterLayerCallback, setAreAllChannelsLoading, setViewState, spatialHeight, spatialWidth, channels, use3d, modelMatrix, }) {
|
|
31
|
+
const classes = useSelectStyles();
|
|
32
|
+
const selections = channels.map(i => i.selection);
|
|
33
|
+
const { data: loader } = loaderWithMeta;
|
|
34
|
+
const handleChange = async (val) => {
|
|
35
|
+
// val is the resolution - null indicates 2D
|
|
36
|
+
const shouldUse3D = typeof val === 'number';
|
|
37
|
+
setAreAllChannelsLoading(true);
|
|
38
|
+
setRasterLayerCallback(() => {
|
|
39
|
+
setAreAllChannelsLoading(false);
|
|
40
|
+
setRasterLayerCallback(null);
|
|
41
|
+
});
|
|
42
|
+
if (shouldUse3D) {
|
|
43
|
+
const [xSlice, ySlice, zSlice] = getBoundingCube(loader);
|
|
44
|
+
const propertiesChanged = {
|
|
45
|
+
resolution: val,
|
|
46
|
+
xSlice,
|
|
47
|
+
ySlice,
|
|
48
|
+
zSlice,
|
|
49
|
+
use3d: shouldUse3D,
|
|
50
|
+
};
|
|
51
|
+
// Only make the fetch if needed i.e if the 3d was just being turned on.
|
|
52
|
+
if (!use3d) {
|
|
53
|
+
const { sliders } = await getMultiSelectionStats({
|
|
54
|
+
loader,
|
|
55
|
+
selections,
|
|
56
|
+
use3d: shouldUse3D,
|
|
57
|
+
});
|
|
58
|
+
propertiesChanged.channels = [...channels];
|
|
59
|
+
propertiesChanged.channels.forEach((ch, i) => {
|
|
60
|
+
// eslint-disable-next-line no-param-reassign
|
|
61
|
+
ch.slider = sliders[i];
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// Update all properties at once to avoid overriding calls.
|
|
65
|
+
handleMultiPropertyChange(propertiesChanged);
|
|
66
|
+
const defaultViewState = viv.getDefaultInitialViewState(loader, { height: spatialHeight, width: spatialWidth }, 1.5, true, new Matrix4(modelMatrix));
|
|
67
|
+
setViewState({
|
|
68
|
+
...defaultViewState,
|
|
69
|
+
rotationX: 0,
|
|
70
|
+
rotationOrbit: 0,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const { sliders } = await getMultiSelectionStats({
|
|
75
|
+
loader, selections, use3d: shouldUse3D,
|
|
76
|
+
});
|
|
77
|
+
const newChannels = [...channels];
|
|
78
|
+
newChannels.forEach((ch, i) => {
|
|
79
|
+
// eslint-disable-next-line no-param-reassign
|
|
80
|
+
ch.slider = sliders[i];
|
|
81
|
+
});
|
|
82
|
+
// Update all properties at once to avoid overriding calls.
|
|
83
|
+
handleMultiPropertyChange({
|
|
84
|
+
resolution: val,
|
|
85
|
+
use3d: shouldUse3D,
|
|
86
|
+
spatialAxisFixed: false,
|
|
87
|
+
channels: newChannels,
|
|
88
|
+
});
|
|
89
|
+
const defaultViewState = viv.getDefaultInitialViewState(loader, { height: spatialHeight, width: spatialWidth }, 0.5, false, new Matrix4(modelMatrix));
|
|
90
|
+
setViewState({
|
|
91
|
+
...defaultViewState,
|
|
92
|
+
rotationX: null,
|
|
93
|
+
rotationOrbit: null,
|
|
94
|
+
orbitAxis: null,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const { labels, shape } = Array.isArray(loader) ? loader[0] : loader;
|
|
99
|
+
const hasZStack = shape[labels.indexOf('z')] > 1;
|
|
100
|
+
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 })
|
|
101
|
+
.fill(0)
|
|
102
|
+
// eslint-disable-next-line no-unused-vars
|
|
103
|
+
.map((_, resolution) => {
|
|
104
|
+
if (loader) {
|
|
105
|
+
if (canLoadResolution(loader, resolution)) {
|
|
106
|
+
const { height, width, depthDownsampled, totalBytes, } = getStatsForResolution(loader, resolution);
|
|
107
|
+
return (_jsx("option", { value: resolution, disabled: disable3d
|
|
108
|
+
|| !hasZStack, children: `3D: ${resolution}x Downsampled, ~${formatBytes(totalBytes)} per channel, (${height}, ${width}, ${depthDownsampled})` }, `(${height}, ${width}, ${depthDownsampled})`));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
})] }) }));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Wrapper for the dropdown that selects a colormap (None, viridis, magma, etc.).
|
|
116
|
+
* @prop {string} value Currently selected value for the colormap.
|
|
117
|
+
* @prop {string} inputId Css id.
|
|
118
|
+
* @prop {function} handleChange Callback for every change in colormap.
|
|
119
|
+
*/
|
|
120
|
+
function ColormapSelect({ value, inputId, handleChange }) {
|
|
121
|
+
const classes = useSelectStyles();
|
|
122
|
+
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)))] }));
|
|
123
|
+
}
|
|
124
|
+
function TransparentColorCheckbox({ value, handleChange }) {
|
|
125
|
+
return (_jsx(Checkbox, { style: { float: 'left', padding: 0 }, color: "default", onChange: () => {
|
|
126
|
+
if (value) {
|
|
127
|
+
handleChange(null);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
handleChange([0, 0, 0]);
|
|
131
|
+
}
|
|
132
|
+
}, checked: Boolean(value) }));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Wrapper for the slider that updates opacity.
|
|
136
|
+
* @prop {string} value Currently selected value between 0 and 1.
|
|
137
|
+
* @prop {function} handleChange Callback for every change in opacity.
|
|
138
|
+
*/
|
|
139
|
+
function OpacitySlider({ value, handleChange }) {
|
|
140
|
+
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' } }));
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Wrapper for the dropdown that chooses the domain type.
|
|
144
|
+
* @prop {string} value Currently selected value (i.e 'Max/Min').
|
|
145
|
+
* @prop {string} inputId Css id.
|
|
146
|
+
* @prop {function} handleChange Callback for every change in domain.
|
|
147
|
+
*/
|
|
148
|
+
function SliderDomainSelector({ value, inputId, handleChange }) {
|
|
149
|
+
const classes = useSelectStyles();
|
|
150
|
+
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))) }));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Wrapper for the slider that chooses global selections (z, t etc.).
|
|
154
|
+
* @prop {string} field The dimension this selects for (z, t etc.).
|
|
155
|
+
* @prop {number} value Currently selected index (1, 4, etc.).
|
|
156
|
+
* @prop {function} handleChange Callback for every change in selection.
|
|
157
|
+
* @prop {function} possibleValues All available values for the field.
|
|
158
|
+
*/
|
|
159
|
+
function GlobalSelectionSlider({ field, value, handleChange, possibleValues, }) {
|
|
160
|
+
return (_jsx(StyledSelectionSlider, { value: value,
|
|
161
|
+
// See https://github.com/hms-dbmi/viv/issues/176 for why
|
|
162
|
+
// we have the two handlers.
|
|
163
|
+
onChange: (event, newValue) => {
|
|
164
|
+
handleChange({ selection: { [field]: newValue }, event });
|
|
165
|
+
}, onChangeCommitted: (event, newValue) => {
|
|
166
|
+
handleChange({ selection: { [field]: newValue }, event });
|
|
167
|
+
}, valueLabelDisplay: "auto", getAriaLabel: () => `${field} slider`, marks: possibleValues.map(val => ({ value: val })), min: Number(possibleValues[0]), max: Number(possibleValues.slice(-1)), orientation: "horizontal", step: null }));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Wrapper for each of the options to show its name and then its UI component.
|
|
171
|
+
* @prop {string} name Display name for option.
|
|
172
|
+
* @prop {number} opacity Current opacity value.
|
|
173
|
+
* @prop {string} inputId An id for css.
|
|
174
|
+
* @prop {object} children Components to be rendered next to the name (slider, dropdown etc.).
|
|
175
|
+
*/
|
|
176
|
+
function LayerOption({ name, inputId, children }) {
|
|
177
|
+
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 })] }));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Gloabl options for all channels (opacity, colormap, etc.).
|
|
181
|
+
* @prop {string} colormap What colormap is currently selected (None, viridis etc.).
|
|
182
|
+
* @prop {number} opacity Current opacity value.
|
|
183
|
+
* @prop {function} handleColormapChange Callback for when colormap changes.
|
|
184
|
+
* @prop {function} handleOpacityChange Callback for when opacity changes.
|
|
185
|
+
* @prop {object} globalControlLabels All available options for global control (z and t).
|
|
186
|
+
* @prop {function} handleGlobalChannelsSelectionChange Callback for global selection changes.
|
|
187
|
+
* @prop {function} handleDomainChange Callback for domain type changes (full or min/max).
|
|
188
|
+
* @prop {array} channels Current channel object for inferring the current global selection.
|
|
189
|
+
* @prop {array} dimensions Currently available dimensions (channel, z, t etc.).
|
|
190
|
+
* @prop {string} domainType One of Max/Min or Full (soon presets as well).
|
|
191
|
+
* @prop {boolean} disableChannelsIfRgbDetected Whether or not we need colormap controllers if RGB.
|
|
192
|
+
*/
|
|
193
|
+
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, }) {
|
|
194
|
+
const { labels, shape } = Array.isArray(loader.data) ? loader.data[0] : loader.data;
|
|
195
|
+
const hasDimensionsAndChannels = labels.length > 0 && channels.length > 0;
|
|
196
|
+
const hasZStack = shape[labels.indexOf('z')] > 1;
|
|
197
|
+
// Only show volume button if we can actually view resolutions.
|
|
198
|
+
const hasViewableResolutions = Boolean(Array.from({
|
|
199
|
+
length: loader.data.length,
|
|
200
|
+
}).filter((_, res) => canLoadResolution(loader.data, res)).length);
|
|
201
|
+
return (_jsxs(Grid, { container: true, direction: "column", style: { width: '100%' }, children: [hasZStack
|
|
202
|
+
&& !disable3d
|
|
203
|
+
&& hasViewableResolutions
|
|
204
|
+
&& (_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
|
|
205
|
+
&& !use3d
|
|
206
|
+
&& 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) => {
|
|
207
|
+
handleDomainChange(value);
|
|
208
|
+
} }) }) }))] })) : 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 }) }) }))] }));
|
|
209
|
+
}
|
|
210
|
+
export default LayerOptions;
|
|
@@ -0,0 +1,160 @@
|
|
|
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/gl';
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
}
|