@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.
- package/dist/deflate.b44720d0.mjs +13 -0
- package/dist/index.ca9e70ae.mjs +137540 -0
- package/dist/index.mjs +10 -0
- package/dist/jpeg.edb20ff0.mjs +840 -0
- package/dist/lerc.df2f1733.mjs +1943 -0
- package/dist/lzw.2a639594.mjs +128 -0
- package/dist/packbits.958f7a40.mjs +30 -0
- package/dist/pako.esm.4b234125.mjs +3940 -0
- package/dist/raw.4239192e.mjs +12 -0
- package/dist/webimage.de21cf13.mjs +32 -0
- package/{dist → dist-tsc}/index.js +0 -0
- package/package.json +10 -10
- package/src/BitmaskChannelController.js +63 -0
- package/src/ChannelOptions.js +62 -0
- package/src/ColorPalette.js +49 -0
- package/src/ImageAddButton.js +51 -0
- package/src/LayerController.js +599 -0
- package/src/LayerControllerSubscriber.js +510 -0
- package/src/LayerOptions.js +463 -0
- package/src/RasterChannelController.js +256 -0
- package/src/RasterChannelController.test.js +23 -0
- package/src/VectorLayerController.js +65 -0
- package/src/VolumeOptions.js +218 -0
- package/src/constants.js +14 -0
- package/src/index.js +3 -0
- package/{dist → src}/shared-channel-controls.js +35 -6
- package/src/styles.js +113 -0
- package/src/utils.js +129 -0
- package/dist/BitmaskChannelController.js +0 -31
- package/dist/ChannelOptions.js +0 -39
- package/dist/ColorPalette.js +0 -31
- package/dist/ImageAddButton.js +0 -28
- package/dist/LayerController.js +0 -311
- package/dist/LayerControllerSubscriber.js +0 -197
- package/dist/LayerOptions.js +0 -211
- package/dist/RasterChannelController.js +0 -160
- package/dist/RasterChannelController.test.js +0 -21
- package/dist/VectorLayerController.js +0 -30
- package/dist/VolumeOptions.js +0 -78
- package/dist/constants.js +0 -12
- package/dist/styles.js +0 -103
- package/dist/utils.js +0 -109
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import React, { useCallback, useState, useEffect } from 'react';
|
|
2
|
+
|
|
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
|
+
|
|
8
|
+
import { getSourceFromLoader } from '@vitessce/spatial-utils';
|
|
9
|
+
import ChannelOptions from './ChannelOptions';
|
|
10
|
+
import { DOMAINS } from './constants';
|
|
11
|
+
import { getMultiSelectionStats } from './utils';
|
|
12
|
+
import {
|
|
13
|
+
ChannelSelectionDropdown,
|
|
14
|
+
ChannelVisibilityCheckbox,
|
|
15
|
+
} from './shared-channel-controls';
|
|
16
|
+
|
|
17
|
+
// Returns an rgb string for display, and changes the color (arr)
|
|
18
|
+
// to use a grey for light theme + white color or if the colormap is on.
|
|
19
|
+
export const toRgbUIString = (on, arr, theme) => {
|
|
20
|
+
const color = on || (theme === 'light' && arr.every(i => i === 255))
|
|
21
|
+
? [220, 220, 220]
|
|
22
|
+
: arr;
|
|
23
|
+
return `rgb(${color})`;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function abbreviateNumber(value) {
|
|
27
|
+
// Return an abbreviated representation of value, in 5 characters or less.
|
|
28
|
+
|
|
29
|
+
const maxLength = 5;
|
|
30
|
+
let maxNaiveDigits = maxLength;
|
|
31
|
+
|
|
32
|
+
/* eslint-disable no-plusplus */
|
|
33
|
+
if (!Number.isInteger(value)) {
|
|
34
|
+
--maxNaiveDigits;
|
|
35
|
+
} // Wasted on "."
|
|
36
|
+
if (value < 1) {
|
|
37
|
+
--maxNaiveDigits;
|
|
38
|
+
} // Wasted on "0."
|
|
39
|
+
/* eslint-disable no-plusplus */
|
|
40
|
+
|
|
41
|
+
const naive = Intl.NumberFormat('en-US', {
|
|
42
|
+
maximumSignificantDigits: maxNaiveDigits,
|
|
43
|
+
useGrouping: false,
|
|
44
|
+
}).format(value);
|
|
45
|
+
if (naive.length <= maxLength) return naive;
|
|
46
|
+
|
|
47
|
+
// "e+9" consumes 3 characters, so if we even had two significant digits,
|
|
48
|
+
// it would take take us to six characters, including the decimal point.
|
|
49
|
+
return value.toExponential(0);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Slider for controlling current colormap.
|
|
54
|
+
* @prop {string} color Current color for this channel.
|
|
55
|
+
* @prop {arry} slider Current value of the slider.
|
|
56
|
+
* @prop {function} handleChange Callback for each slider change.
|
|
57
|
+
* @prop {array} domain Current max/min allowable slider values.
|
|
58
|
+
*/
|
|
59
|
+
function ChannelSlider({
|
|
60
|
+
color,
|
|
61
|
+
slider = [0, 0],
|
|
62
|
+
handleChange,
|
|
63
|
+
domain = [0, 0],
|
|
64
|
+
dtype,
|
|
65
|
+
disabled,
|
|
66
|
+
}) {
|
|
67
|
+
const [min, max] = domain;
|
|
68
|
+
const sliderCopy = slider.slice();
|
|
69
|
+
if (slider[0] < min) {
|
|
70
|
+
sliderCopy[0] = min;
|
|
71
|
+
}
|
|
72
|
+
if (slider[1] > max) {
|
|
73
|
+
sliderCopy[1] = max;
|
|
74
|
+
}
|
|
75
|
+
const handleChangeDebounced = useCallback(
|
|
76
|
+
debounce(handleChange, 3, { trailing: true }),
|
|
77
|
+
[handleChange],
|
|
78
|
+
);
|
|
79
|
+
const step = max - min < 500 && dtype === 'Float32' ? (max - min) / 500 : 1;
|
|
80
|
+
return (
|
|
81
|
+
<Slider
|
|
82
|
+
value={slider}
|
|
83
|
+
valueLabelFormat={abbreviateNumber}
|
|
84
|
+
onChange={(e, v) => handleChangeDebounced(v)}
|
|
85
|
+
valueLabelDisplay="auto"
|
|
86
|
+
getAriaLabel={() => `${color}-${slider}`}
|
|
87
|
+
min={min}
|
|
88
|
+
max={max}
|
|
89
|
+
step={step}
|
|
90
|
+
orientation="horizontal"
|
|
91
|
+
style={{ color, marginTop: '7px' }}
|
|
92
|
+
disabled={disabled}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Controller for the handling the colormapping sliders.
|
|
99
|
+
* @prop {boolean} visibility Whether or not this channel is "on"
|
|
100
|
+
* @prop {array} slider Current slider range.
|
|
101
|
+
* @prop {array} color Current color for this channel.
|
|
102
|
+
* @prop {array} domain Current max/min for this channel.
|
|
103
|
+
* @prop {string} dimName Name of the dimensions this slider controls (usually "channel").
|
|
104
|
+
* @prop {boolean} colormapOn Whether or not the colormap (viridis, magma etc.) is on.
|
|
105
|
+
* @prop {object} channelOptions All available options for this dimension (i.e channel names).
|
|
106
|
+
* @prop {function} handlePropertyChange Callback for when a property (color, slider etc.) changes.
|
|
107
|
+
* @prop {function} handleChannelRemove When a channel is removed, this is called.
|
|
108
|
+
* @prop {function} handleIQRUpdate When the IQR button is clicked, this is called.
|
|
109
|
+
* @prop {number} selectionIndex The current numeric index of the selection.
|
|
110
|
+
*/
|
|
111
|
+
function RasterChannelController({
|
|
112
|
+
visibility = false,
|
|
113
|
+
slider,
|
|
114
|
+
color,
|
|
115
|
+
channels,
|
|
116
|
+
channelId,
|
|
117
|
+
domainType: newDomainType,
|
|
118
|
+
dimName,
|
|
119
|
+
theme,
|
|
120
|
+
loader,
|
|
121
|
+
colormapOn,
|
|
122
|
+
channelOptions,
|
|
123
|
+
handlePropertyChange,
|
|
124
|
+
handleChannelRemove,
|
|
125
|
+
handleIQRUpdate,
|
|
126
|
+
selectionIndex,
|
|
127
|
+
isLoading,
|
|
128
|
+
use3d: newUse3d,
|
|
129
|
+
}) {
|
|
130
|
+
const { dtype } = getSourceFromLoader(loader);
|
|
131
|
+
const [domain, setDomain] = useState(null);
|
|
132
|
+
const [domainType, setDomainType] = useState(null);
|
|
133
|
+
const [use3d, setUse3d] = useState(null);
|
|
134
|
+
const [selection, setSelection] = useState([
|
|
135
|
+
{ ...channels[channelId].selection },
|
|
136
|
+
]);
|
|
137
|
+
const rgbColor = toRgbUIString(colormapOn, color, theme);
|
|
138
|
+
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
// Use mounted to prevent state updates/re-renders after the component has been unmounted.
|
|
141
|
+
// All state updates should happen within the mounted check.
|
|
142
|
+
let mounted = true;
|
|
143
|
+
if (dtype && loader && channels) {
|
|
144
|
+
const selections = [{ ...channels[channelId].selection }];
|
|
145
|
+
let domains;
|
|
146
|
+
const hasDomainChanged = newDomainType !== domainType;
|
|
147
|
+
const has3dChanged = use3d !== newUse3d;
|
|
148
|
+
const hasSelectionChanged = !isEqual(selections, selection);
|
|
149
|
+
if (hasDomainChanged || hasSelectionChanged || has3dChanged) {
|
|
150
|
+
if (newDomainType === 'Full') {
|
|
151
|
+
domains = [DOMAINS[dtype]];
|
|
152
|
+
const [newDomain] = domains;
|
|
153
|
+
if (mounted) {
|
|
154
|
+
setDomain(newDomain);
|
|
155
|
+
setDomainType(newDomainType);
|
|
156
|
+
if (hasSelectionChanged) {
|
|
157
|
+
setSelection(selections);
|
|
158
|
+
}
|
|
159
|
+
if (has3dChanged) {
|
|
160
|
+
setUse3d(newUse3d);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
getMultiSelectionStats({
|
|
165
|
+
loader: loader.data,
|
|
166
|
+
selections,
|
|
167
|
+
use3d: newUse3d,
|
|
168
|
+
}).then((stats) => {
|
|
169
|
+
// eslint-disable-next-line prefer-destructuring
|
|
170
|
+
domains = stats.domains;
|
|
171
|
+
const [newDomain] = domains;
|
|
172
|
+
if (mounted) {
|
|
173
|
+
setDomain(newDomain);
|
|
174
|
+
setDomainType(newDomainType);
|
|
175
|
+
if (hasSelectionChanged) {
|
|
176
|
+
setSelection(selections);
|
|
177
|
+
}
|
|
178
|
+
if (has3dChanged) {
|
|
179
|
+
setUse3d(newUse3d);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return () => {
|
|
187
|
+
mounted = false;
|
|
188
|
+
};
|
|
189
|
+
}, [
|
|
190
|
+
domainType,
|
|
191
|
+
channels,
|
|
192
|
+
channelId,
|
|
193
|
+
loader,
|
|
194
|
+
dtype,
|
|
195
|
+
newDomainType,
|
|
196
|
+
selection,
|
|
197
|
+
newUse3d,
|
|
198
|
+
use3d,
|
|
199
|
+
]);
|
|
200
|
+
/* A valid selection is defined by an object where the keys are
|
|
201
|
+
* the name of a dimension of the data, and the values are the
|
|
202
|
+
* index of the image along that particular dimension.
|
|
203
|
+
*
|
|
204
|
+
* Since we currently only support making a selection along one
|
|
205
|
+
* addtional dimension (i.e. the dropdown just has channels or mz)
|
|
206
|
+
* we have a helper function to create the selection.
|
|
207
|
+
*
|
|
208
|
+
* e.g { channel: 2 } // channel dimension, third channel
|
|
209
|
+
*/
|
|
210
|
+
const createSelection = index => ({ [dimName]: index });
|
|
211
|
+
return (
|
|
212
|
+
<Grid container direction="column" m={1} justifyContent="center">
|
|
213
|
+
<Grid container direction="row" justifyContent="space-between">
|
|
214
|
+
<Grid item xs={10}>
|
|
215
|
+
<ChannelSelectionDropdown
|
|
216
|
+
handleChange={v => handlePropertyChange('selection', createSelection(v))
|
|
217
|
+
}
|
|
218
|
+
selectionIndex={selectionIndex}
|
|
219
|
+
channelOptions={channelOptions}
|
|
220
|
+
disabled={isLoading}
|
|
221
|
+
/>
|
|
222
|
+
</Grid>
|
|
223
|
+
<Grid item xs={1} style={{ marginTop: '4px' }}>
|
|
224
|
+
<ChannelOptions
|
|
225
|
+
handlePropertyChange={handlePropertyChange}
|
|
226
|
+
handleChannelRemove={handleChannelRemove}
|
|
227
|
+
handleIQRUpdate={handleIQRUpdate}
|
|
228
|
+
disabled={isLoading}
|
|
229
|
+
/>
|
|
230
|
+
</Grid>
|
|
231
|
+
</Grid>
|
|
232
|
+
<Grid container direction="row" justifyContent="space-between">
|
|
233
|
+
<Grid item xs={2}>
|
|
234
|
+
<ChannelVisibilityCheckbox
|
|
235
|
+
color={rgbColor}
|
|
236
|
+
checked={visibility}
|
|
237
|
+
toggle={() => handlePropertyChange('visible', !visibility)}
|
|
238
|
+
disabled={isLoading}
|
|
239
|
+
/>
|
|
240
|
+
</Grid>
|
|
241
|
+
<Grid item xs={9}>
|
|
242
|
+
<ChannelSlider
|
|
243
|
+
color={rgbColor}
|
|
244
|
+
slider={slider}
|
|
245
|
+
domain={domain || DOMAINS[dtype]}
|
|
246
|
+
dtype={dtype}
|
|
247
|
+
handleChange={v => handlePropertyChange('slider', v)}
|
|
248
|
+
disabled={isLoading}
|
|
249
|
+
/>
|
|
250
|
+
</Grid>
|
|
251
|
+
</Grid>
|
|
252
|
+
</Grid>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export default RasterChannelController;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { toRgbUIString } from './RasterChannelController';
|
|
2
|
+
|
|
3
|
+
const GREY = [220, 220, 220];
|
|
4
|
+
|
|
5
|
+
describe('layer-controller/RasterChannelController.js', () => {
|
|
6
|
+
describe('toRgbUIString()', () => {
|
|
7
|
+
it('Maps color value to itself when colormap off and not white with dark theme', () => {
|
|
8
|
+
expect(toRgbUIString(false, [200, 200, 200], 'dark')).toEqual(`rgb(${[200, 200, 200]})`);
|
|
9
|
+
});
|
|
10
|
+
it('Maps color value to grey when colormap on with dark theme', () => {
|
|
11
|
+
expect(toRgbUIString(true, [200, 200, 200], 'dark')).toEqual(`rgb(${GREY})`);
|
|
12
|
+
});
|
|
13
|
+
it('Maps color value to grey when colormap on with light theme', () => {
|
|
14
|
+
expect(toRgbUIString(true, [200, 200, 200], 'light')).toEqual(`rgb(${GREY})`);
|
|
15
|
+
});
|
|
16
|
+
it('Maps color value to grey when colormap off and white with light theme', () => {
|
|
17
|
+
expect(toRgbUIString(false, [255, 255, 255], 'light')).toEqual(`rgb(${GREY})`);
|
|
18
|
+
});
|
|
19
|
+
it('Maps color value to grey when colormap off and white with light theme', () => {
|
|
20
|
+
expect(toRgbUIString(false, [200, 200, 200], 'light')).toEqual(`rgb(${[200, 200, 200]})`);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
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
|
+
|
|
10
|
+
export default function VectorLayerController(props) {
|
|
11
|
+
const {
|
|
12
|
+
label,
|
|
13
|
+
layer,
|
|
14
|
+
layerType,
|
|
15
|
+
handleLayerChange,
|
|
16
|
+
} = props;
|
|
17
|
+
|
|
18
|
+
const slider = layer.opacity;
|
|
19
|
+
const isOn = layer.visible;
|
|
20
|
+
|
|
21
|
+
function handleSliderChange(v) {
|
|
22
|
+
if (layerType === 'cells') {
|
|
23
|
+
const stroked = v < 0.7;
|
|
24
|
+
handleLayerChange({ ...layer, opacity: v, stroked });
|
|
25
|
+
} else {
|
|
26
|
+
handleLayerChange({ ...layer, opacity: v });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function handleCheckBoxChange(v) {
|
|
31
|
+
handleLayerChange({ ...layer, visible: v });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const classes = useControllerSectionStyles();
|
|
35
|
+
return (
|
|
36
|
+
<Grid item style={{ marginTop: '10px' }}>
|
|
37
|
+
<Paper className={classes.root}>
|
|
38
|
+
<Typography
|
|
39
|
+
style={{
|
|
40
|
+
padding: '15px 8px 0px 8px',
|
|
41
|
+
marginBottom: '-5px',
|
|
42
|
+
}}
|
|
43
|
+
>
|
|
44
|
+
{label}
|
|
45
|
+
</Typography>
|
|
46
|
+
<Grid container direction="row" justifyContent="space-between">
|
|
47
|
+
<Grid item xs={2}>
|
|
48
|
+
<Checkbox color="primary" checked={isOn} onChange={(e, v) => handleCheckBoxChange(v)} />
|
|
49
|
+
</Grid>
|
|
50
|
+
<Grid item xs={9} style={{ paddingRight: '8px' }}>
|
|
51
|
+
<Slider
|
|
52
|
+
value={slider}
|
|
53
|
+
min={0}
|
|
54
|
+
max={1}
|
|
55
|
+
step={0.001}
|
|
56
|
+
onChange={(e, v) => handleSliderChange(v)}
|
|
57
|
+
style={{ marginTop: '7px' }}
|
|
58
|
+
orientation="horizontal"
|
|
59
|
+
/>
|
|
60
|
+
</Grid>
|
|
61
|
+
</Grid>
|
|
62
|
+
</Paper>
|
|
63
|
+
</Grid>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Matrix4 } from 'math.gl';
|
|
3
|
+
import Grid from '@material-ui/core/Grid';
|
|
4
|
+
import Typography from '@material-ui/core/Typography';
|
|
5
|
+
import Button from '@material-ui/core/Button';
|
|
6
|
+
import { makeStyles, createStyles } from '@material-ui/core/styles';
|
|
7
|
+
import FormControl from '@material-ui/core/FormControl';
|
|
8
|
+
import Select from '@material-ui/core/Select';
|
|
9
|
+
import InputLabel from '@material-ui/core/InputLabel';
|
|
10
|
+
import Slider from '@material-ui/core/Slider';
|
|
11
|
+
import { viv } from '@vitessce/gl';
|
|
12
|
+
import { abbreviateNumber, getBoundingCube } from './utils';
|
|
13
|
+
import { useSelectStyles } from './styles';
|
|
14
|
+
|
|
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
|
+
|
|
31
|
+
const Slicer = ({
|
|
32
|
+
xSlice,
|
|
33
|
+
ySlice,
|
|
34
|
+
zSlice,
|
|
35
|
+
handleSlicerSetting,
|
|
36
|
+
loader,
|
|
37
|
+
use3d,
|
|
38
|
+
}) => {
|
|
39
|
+
const [xSliceInit, ySliceInit, zSliceInit] = getBoundingCube(loader.data);
|
|
40
|
+
const sliceValuesAndSetSliceFunctions = [
|
|
41
|
+
[
|
|
42
|
+
xSlice,
|
|
43
|
+
xSliceNew => handleSlicerSetting('x', xSliceNew),
|
|
44
|
+
'x',
|
|
45
|
+
xSliceInit,
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
ySlice,
|
|
49
|
+
ySliceNew => handleSlicerSetting('y', ySliceNew),
|
|
50
|
+
'y',
|
|
51
|
+
ySliceInit,
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
zSlice,
|
|
55
|
+
zSliceNew => handleSlicerSetting('z', zSliceNew),
|
|
56
|
+
'z',
|
|
57
|
+
zSliceInit,
|
|
58
|
+
],
|
|
59
|
+
];
|
|
60
|
+
const classes = useSlicerStyles();
|
|
61
|
+
const Slicers = sliceValuesAndSetSliceFunctions.map(
|
|
62
|
+
([val, setVal, label, [min, max]]) => (
|
|
63
|
+
<Grid
|
|
64
|
+
container
|
|
65
|
+
direction="row"
|
|
66
|
+
justifyContent="flex-start"
|
|
67
|
+
alignItems="center"
|
|
68
|
+
key={label}
|
|
69
|
+
>
|
|
70
|
+
<Grid item xs={1}>
|
|
71
|
+
<Typography
|
|
72
|
+
className={!use3d ? classes.disabled : classes.enabled}
|
|
73
|
+
style={{ marginBottom: 0 }}
|
|
74
|
+
>
|
|
75
|
+
{label}:
|
|
76
|
+
</Typography>
|
|
77
|
+
</Grid>
|
|
78
|
+
<Grid item xs={11}>
|
|
79
|
+
<Slider
|
|
80
|
+
disabled={!use3d}
|
|
81
|
+
className={!use3d ? classes.disabled : classes.enabled}
|
|
82
|
+
value={val}
|
|
83
|
+
onChange={(e, v) => setVal(v)}
|
|
84
|
+
valueLabelDisplay="auto"
|
|
85
|
+
valueLabelFormat={v => abbreviateNumber(v)}
|
|
86
|
+
getAriaLabel={() => `${label} slider`}
|
|
87
|
+
min={min}
|
|
88
|
+
max={max}
|
|
89
|
+
step={0.005}
|
|
90
|
+
orientation="horizontal"
|
|
91
|
+
/>
|
|
92
|
+
</Grid>
|
|
93
|
+
</Grid>
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
return (
|
|
97
|
+
<>
|
|
98
|
+
<Typography
|
|
99
|
+
className={!use3d ? classes.disabled : classes.enabled}
|
|
100
|
+
style={{ marginTop: 16, marginBottom: 0 }}
|
|
101
|
+
>
|
|
102
|
+
Clipping Planes:{' '}
|
|
103
|
+
</Typography>{' '}
|
|
104
|
+
{Slicers}
|
|
105
|
+
</>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const renderingOptions = Object.values(viv.RENDERING_MODES);
|
|
110
|
+
|
|
111
|
+
function RenderingModeSelect({
|
|
112
|
+
handleRenderingModeChange,
|
|
113
|
+
renderingMode,
|
|
114
|
+
use3d,
|
|
115
|
+
}) {
|
|
116
|
+
const classes = useSelectStyles();
|
|
117
|
+
// Empty option allows for displaying the title of the dropdown fully in the UI.
|
|
118
|
+
const options = !use3d ? [...renderingOptions, ''] : renderingOptions;
|
|
119
|
+
return (
|
|
120
|
+
<FormControl fullWidth>
|
|
121
|
+
<InputLabel htmlFor="rendering-mode-select">Rendering Mode</InputLabel>
|
|
122
|
+
<Select
|
|
123
|
+
native
|
|
124
|
+
onChange={e => handleRenderingModeChange(e.target.value)}
|
|
125
|
+
value={use3d ? renderingMode : ''}
|
|
126
|
+
inputProps={{
|
|
127
|
+
name: 'rendering-mode',
|
|
128
|
+
id: 'rendering-mode-select',
|
|
129
|
+
}}
|
|
130
|
+
disabled={!use3d}
|
|
131
|
+
classes={{ root: classes.selectRoot }}
|
|
132
|
+
>
|
|
133
|
+
{options.map(name => (
|
|
134
|
+
<option key={name} value={name}>
|
|
135
|
+
{name}
|
|
136
|
+
</option>
|
|
137
|
+
))}
|
|
138
|
+
</Select>
|
|
139
|
+
</FormControl>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const ReCenterButton = ({
|
|
144
|
+
setViewState,
|
|
145
|
+
use3d,
|
|
146
|
+
spatialHeight,
|
|
147
|
+
spatialWidth,
|
|
148
|
+
loader,
|
|
149
|
+
modelMatrix,
|
|
150
|
+
}) => (
|
|
151
|
+
<Grid item xs="auto" key="recenter">
|
|
152
|
+
<Button
|
|
153
|
+
onClick={() => {
|
|
154
|
+
const defaultViewState = viv.getDefaultInitialViewState(
|
|
155
|
+
loader.data,
|
|
156
|
+
{ height: spatialHeight, width: spatialWidth },
|
|
157
|
+
1.5,
|
|
158
|
+
use3d,
|
|
159
|
+
new Matrix4(modelMatrix),
|
|
160
|
+
);
|
|
161
|
+
setViewState({
|
|
162
|
+
...defaultViewState,
|
|
163
|
+
rotationX: 0,
|
|
164
|
+
rotationOrbit: 0,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
disabled={!use3d}
|
|
169
|
+
style={{
|
|
170
|
+
padding: 0,
|
|
171
|
+
marginBottom: 6,
|
|
172
|
+
}}
|
|
173
|
+
>
|
|
174
|
+
Re-Center
|
|
175
|
+
</Button>
|
|
176
|
+
</Grid>
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const VolumeOptions = ({
|
|
180
|
+
handleSlicerSetting,
|
|
181
|
+
handleRenderingModeChange,
|
|
182
|
+
renderingMode,
|
|
183
|
+
xSlice,
|
|
184
|
+
ySlice,
|
|
185
|
+
zSlice,
|
|
186
|
+
use3d,
|
|
187
|
+
loader,
|
|
188
|
+
setViewState,
|
|
189
|
+
spatialHeight,
|
|
190
|
+
spatialWidth,
|
|
191
|
+
modelMatrix,
|
|
192
|
+
}) => (
|
|
193
|
+
<>
|
|
194
|
+
<RenderingModeSelect
|
|
195
|
+
handleRenderingModeChange={handleRenderingModeChange}
|
|
196
|
+
renderingMode={renderingMode}
|
|
197
|
+
use3d={use3d}
|
|
198
|
+
/>
|
|
199
|
+
<Slicer
|
|
200
|
+
xSlice={xSlice}
|
|
201
|
+
ySlice={ySlice}
|
|
202
|
+
zSlice={zSlice}
|
|
203
|
+
handleSlicerSetting={handleSlicerSetting}
|
|
204
|
+
use3d={use3d}
|
|
205
|
+
loader={loader}
|
|
206
|
+
/>
|
|
207
|
+
<ReCenterButton
|
|
208
|
+
setViewState={setViewState}
|
|
209
|
+
use3d={use3d}
|
|
210
|
+
spatialHeight={spatialHeight}
|
|
211
|
+
spatialWidth={spatialWidth}
|
|
212
|
+
loader={loader}
|
|
213
|
+
modelMatrix={modelMatrix}
|
|
214
|
+
/>
|
|
215
|
+
</>
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
export default VolumeOptions;
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { viv } from '@vitessce/gl';
|
|
2
|
+
|
|
3
|
+
function getDomains() {
|
|
4
|
+
const domains = {};
|
|
5
|
+
const needMin = ['Int8', 'Int16', 'Int32'];
|
|
6
|
+
Object.keys(viv.DTYPE_VALUES).forEach((dtype) => {
|
|
7
|
+
const { max } = viv.DTYPE_VALUES[dtype];
|
|
8
|
+
const min = needMin.includes(dtype) ? -(max + 1) : 0;
|
|
9
|
+
domains[dtype] = [min, max];
|
|
10
|
+
});
|
|
11
|
+
return domains;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const DOMAINS = getDomains();
|
package/src/index.js
ADDED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
1
|
import React from 'react';
|
|
2
|
+
|
|
3
3
|
import Checkbox from '@material-ui/core/Checkbox';
|
|
4
4
|
import Select from '@material-ui/core/Select';
|
|
5
5
|
import { useSelectStyles } from './styles';
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Dropdown for selecting a channel.
|
|
8
9
|
* @prop {function} handleChange Callback for each new selection.
|
|
@@ -10,10 +11,29 @@ import { useSelectStyles } from './styles';
|
|
|
10
11
|
* @prop {boolean} disabled Whether or not the component is disabled.
|
|
11
12
|
* @prop {number} selectionIndex Current numeric index of a selection.
|
|
12
13
|
*/
|
|
13
|
-
export function ChannelSelectionDropdown({
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
export function ChannelSelectionDropdown({
|
|
15
|
+
handleChange,
|
|
16
|
+
disabled,
|
|
17
|
+
channelOptions,
|
|
18
|
+
selectionIndex,
|
|
19
|
+
}) {
|
|
20
|
+
const classes = useSelectStyles();
|
|
21
|
+
return (
|
|
22
|
+
<Select
|
|
23
|
+
classes={{ root: classes.selectRoot }}
|
|
24
|
+
native
|
|
25
|
+
value={selectionIndex}
|
|
26
|
+
onChange={e => handleChange(Number(e.target.value))}
|
|
27
|
+
>
|
|
28
|
+
{channelOptions.map((opt, i) => (
|
|
29
|
+
<option disabled={disabled} key={opt} value={i}>
|
|
30
|
+
{opt}
|
|
31
|
+
</option>
|
|
32
|
+
))}
|
|
33
|
+
</Select>
|
|
34
|
+
);
|
|
16
35
|
}
|
|
36
|
+
|
|
17
37
|
/**
|
|
18
38
|
* Checkbox for toggling on/off of a channel.
|
|
19
39
|
* @prop {string} color Current color for this channel.
|
|
@@ -21,6 +41,15 @@ export function ChannelSelectionDropdown({ handleChange, disabled, channelOption
|
|
|
21
41
|
* @prop {boolean} disabled Whether or not the component is disabled.
|
|
22
42
|
* @prop {function} toggle Callback for toggling on/off.
|
|
23
43
|
*/
|
|
24
|
-
export function ChannelVisibilityCheckbox({
|
|
25
|
-
|
|
44
|
+
export function ChannelVisibilityCheckbox({
|
|
45
|
+
color, checked, toggle, disabled,
|
|
46
|
+
}) {
|
|
47
|
+
return (
|
|
48
|
+
<Checkbox
|
|
49
|
+
onChange={toggle}
|
|
50
|
+
checked={checked}
|
|
51
|
+
disabled={disabled}
|
|
52
|
+
style={{ color, '&$checked': { color } }}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
26
55
|
}
|