@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import RemoveCircleIcon from '@material-ui/icons/RemoveCircle';
|
|
4
|
+
import IconButton from '@material-ui/core/IconButton';
|
|
5
|
+
import Grid from '@material-ui/core/Grid';
|
|
6
|
+
import { ChannelSelectionDropdown, ChannelVisibilityCheckbox } from './shared-channel-controls';
|
|
7
|
+
/**
|
|
8
|
+
* Controller for the handling the bitmask channels.
|
|
9
|
+
* @prop {boolean} visibility Whether or not this channel is "on"
|
|
10
|
+
* @prop {string} dimName Name of the dimensions this slider controls (usually "channel").
|
|
11
|
+
* @prop {object} channelOptions All available options for this dimension (i.e channel names).
|
|
12
|
+
* @prop {function} handlePropertyChange Callback for when a property (color, slider etc.) changes.
|
|
13
|
+
* @prop {function} handleChannelRemove When a channel is removed, this is called.
|
|
14
|
+
* @prop {number} selectionIndex The current numeric index of the selection.
|
|
15
|
+
* @prop {boolean} disableOptions Whether or not channel options are be disabled (default: false).
|
|
16
|
+
*/
|
|
17
|
+
function BitmaskChannelController({ visibility = false, dimName, channelOptions, handlePropertyChange, handleChannelRemove, selectionIndex, disableOptions = false, }) {
|
|
18
|
+
/* A valid selection is defined by an object where the keys are
|
|
19
|
+
* the name of a dimension of the data, and the values are the
|
|
20
|
+
* index of the image along that particular dimension.
|
|
21
|
+
*
|
|
22
|
+
* Since we currently only support making a selection along one
|
|
23
|
+
* addtional dimension (i.e. the dropdown just has channels or mz)
|
|
24
|
+
* we have a helper function to create the selection.
|
|
25
|
+
*
|
|
26
|
+
* e.g { channel: 2 } // channel dimension, third channel
|
|
27
|
+
*/
|
|
28
|
+
const createSelection = index => ({ [dimName]: index });
|
|
29
|
+
return (_jsxs(Grid, { container: true, direction: "row", justifyContent: "space-between", children: [_jsx(Grid, { item: true, xs: 2, children: _jsx(ChannelVisibilityCheckbox, { color: [220, 220, 220], checked: visibility, toggle: () => handlePropertyChange('visible', !visibility) }) }), _jsx(Grid, { item: true, xs: 9, children: _jsx(ChannelSelectionDropdown, { handleChange: v => handlePropertyChange('selection', createSelection(v)), selectionIndex: selectionIndex, disableOptions: disableOptions, channelOptions: channelOptions }) }), _jsx(Grid, { item: true, xs: 1, children: _jsx(IconButton, { onClick: handleChannelRemove, style: { padding: '6px 6px 6px 0px' }, children: _jsx(RemoveCircleIcon, {}) }) })] }));
|
|
30
|
+
}
|
|
31
|
+
export default BitmaskChannelController;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { makeStyles } from '@material-ui/core/styles';
|
|
4
|
+
import MoreVertIcon from '@material-ui/icons/MoreVert';
|
|
5
|
+
import MenuItem from '@material-ui/core/MenuItem';
|
|
6
|
+
import { PopperMenu } from '@vitessce/vit-s';
|
|
7
|
+
import { MuiSpan } from './styles';
|
|
8
|
+
import ColorPalette from './ColorPalette';
|
|
9
|
+
const useStyles = makeStyles(() => ({
|
|
10
|
+
menuButton: {
|
|
11
|
+
backgroundColor: 'transparent',
|
|
12
|
+
},
|
|
13
|
+
colors: {
|
|
14
|
+
'&:hover': {
|
|
15
|
+
backgroundColor: 'transparent',
|
|
16
|
+
},
|
|
17
|
+
paddingLeft: '2px',
|
|
18
|
+
paddingRight: '2px',
|
|
19
|
+
},
|
|
20
|
+
}));
|
|
21
|
+
/**
|
|
22
|
+
* Dropdown for options for a channel on the three dots button.
|
|
23
|
+
* @prop {function} handlePropertyChange Callback for changing property (color, IQR of sliders).
|
|
24
|
+
* @prop {function} handleChannelRemove Callback for channel removal.
|
|
25
|
+
* @prop {function} handleIQRUpdate Callback for IQR slider update.
|
|
26
|
+
*/
|
|
27
|
+
function ChannelOptions({ handlePropertyChange, handleChannelRemove, handleIQRUpdate }) {
|
|
28
|
+
const [open, setOpen] = useState(false);
|
|
29
|
+
const classes = useStyles();
|
|
30
|
+
const handleColorSelect = (color) => {
|
|
31
|
+
handlePropertyChange('color', color);
|
|
32
|
+
};
|
|
33
|
+
const handleRemove = () => {
|
|
34
|
+
setOpen(false);
|
|
35
|
+
handleChannelRemove();
|
|
36
|
+
};
|
|
37
|
+
return (_jsxs(PopperMenu, { open: open, setOpen: setOpen, buttonIcon: _jsx(MoreVertIcon, { fontSize: "small" }), buttonClassName: classes.menuButton, children: [_jsx(MenuItem, { dense: true, disableGutters: true, onClick: handleRemove, children: _jsx(MuiSpan, { children: "Remove" }) }), _jsx(MenuItem, { dense: true, disableGutters: true, onClick: handleIQRUpdate, children: _jsx(MuiSpan, { children: "Use IQR" }) }), _jsx(MenuItem, { dense: true, disableGutters: true, className: classes.colors, children: _jsx(ColorPalette, { handleChange: handleColorSelect }) })] }));
|
|
38
|
+
}
|
|
39
|
+
export default ChannelOptions;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import IconButton from '@material-ui/core/IconButton';
|
|
4
|
+
import LensIcon from '@material-ui/icons/Lens';
|
|
5
|
+
import { makeStyles } from '@material-ui/core/styles';
|
|
6
|
+
import { VIEWER_PALETTE } from '@vitessce/utils';
|
|
7
|
+
const useStyles = makeStyles(theme => ({
|
|
8
|
+
container: {
|
|
9
|
+
width: '70px',
|
|
10
|
+
height: '40px',
|
|
11
|
+
display: 'flex',
|
|
12
|
+
justifyContent: 'space-between',
|
|
13
|
+
alignItems: 'center',
|
|
14
|
+
flexWrap: 'wrap',
|
|
15
|
+
},
|
|
16
|
+
button: {
|
|
17
|
+
padding: '3px',
|
|
18
|
+
width: '16px',
|
|
19
|
+
},
|
|
20
|
+
icon: {
|
|
21
|
+
width: '17px',
|
|
22
|
+
height: '17px',
|
|
23
|
+
stroke: theme.palette.action.selected,
|
|
24
|
+
'stroke-width': '1px',
|
|
25
|
+
},
|
|
26
|
+
}));
|
|
27
|
+
const ColorPalette = ({ handleChange }) => {
|
|
28
|
+
const classes = useStyles();
|
|
29
|
+
return (_jsx("div", { className: classes.container, "aria-label": "color-swatch", children: VIEWER_PALETTE.map(color => (_jsx(IconButton, { className: classes.button, onClick: () => handleChange(color), children: _jsx(LensIcon, { fontSize: "small", style: { color: `rgb(${color})` }, className: classes.icon }) }, color))) }));
|
|
30
|
+
};
|
|
31
|
+
export default ColorPalette;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { makeStyles } from '@material-ui/core/styles';
|
|
4
|
+
import AddIcon from '@material-ui/icons/Add';
|
|
5
|
+
import MenuItem from '@material-ui/core/MenuItem';
|
|
6
|
+
import { PopperMenu } from '@vitessce/vit-s';
|
|
7
|
+
const useStyles = makeStyles(() => ({
|
|
8
|
+
addButton: {
|
|
9
|
+
marginTop: '10px',
|
|
10
|
+
marginBottom: '10px',
|
|
11
|
+
fontWeight: 400,
|
|
12
|
+
},
|
|
13
|
+
}));
|
|
14
|
+
function ImageAddIcon() {
|
|
15
|
+
return (_jsxs(_Fragment, { children: [_jsx(AddIcon, {}), "Add Image Layer"] }));
|
|
16
|
+
}
|
|
17
|
+
function ImageAddButton({ imageOptions, handleImageAdd }) {
|
|
18
|
+
const [open, setOpen] = useState(false);
|
|
19
|
+
const classes = useStyles();
|
|
20
|
+
const handleAdd = (imgData) => {
|
|
21
|
+
setOpen(prev => !prev);
|
|
22
|
+
handleImageAdd(imgData);
|
|
23
|
+
};
|
|
24
|
+
if (!imageOptions)
|
|
25
|
+
return null;
|
|
26
|
+
return (_jsx(PopperMenu, { open: open, setOpen: setOpen, buttonIcon: _jsx(ImageAddIcon, {}), buttonClassName: classes.addButton, placement: "bottom-start", children: imageOptions.map((imgData, i) => (_jsx(MenuItem, { dense: true, onClick: () => handleAdd(i), children: _jsx("span", { children: imgData.name }) }, imgData.name))) }));
|
|
27
|
+
}
|
|
28
|
+
export default ImageAddButton;
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useState, useRef, useEffect } from 'react';
|
|
3
|
+
import { viv, GLOBAL_LABELS, getSourceFromLoader, isRgb, } from '@vitessce/gl';
|
|
4
|
+
import Grid from '@material-ui/core/Grid';
|
|
5
|
+
import Button from '@material-ui/core/Button';
|
|
6
|
+
import AddIcon from '@material-ui/icons/Add';
|
|
7
|
+
import Slider from '@material-ui/core/Slider';
|
|
8
|
+
import Tabs from '@material-ui/core/Tabs';
|
|
9
|
+
import Tab from '@material-ui/core/Tab';
|
|
10
|
+
import Accordion from '@material-ui/core/Accordion';
|
|
11
|
+
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
|
|
12
|
+
import VisibilityIcon from '@material-ui/icons/Visibility';
|
|
13
|
+
import VisibilityOffIcon from '@material-ui/icons/VisibilityOff';
|
|
14
|
+
import { canLoadResolution } from '@vitessce/utils';
|
|
15
|
+
import LayerOptions from './LayerOptions';
|
|
16
|
+
import VolumeOptions from './VolumeOptions';
|
|
17
|
+
import { useControllerSectionStyles, StyledAccordionDetails, StyledAccordionSummary, StyledInputLabel, OverflowEllipsisGrid, } from './styles';
|
|
18
|
+
import { getMultiSelectionStats } from './utils';
|
|
19
|
+
import { DOMAINS } from './constants';
|
|
20
|
+
function TabPanel(props) {
|
|
21
|
+
const { children, value, index, ...other } = props;
|
|
22
|
+
return (_jsx("div", { role: "tabpanel", hidden: value !== index, id: `simple-tabpanel-${index}`, "aria-labelledby": `simple-tab-${index}`, ...other, children: value === index && children }));
|
|
23
|
+
}
|
|
24
|
+
// Set the domain of the sliders based on either a full range or min/max.
|
|
25
|
+
async function getDomainsAndSliders(loader, selections, domainType, use3d) {
|
|
26
|
+
let domains;
|
|
27
|
+
const stats = await getMultiSelectionStats({
|
|
28
|
+
loader: loader.data,
|
|
29
|
+
selections,
|
|
30
|
+
use3d,
|
|
31
|
+
});
|
|
32
|
+
const { sliders } = stats;
|
|
33
|
+
if (domainType === 'Min/Max') {
|
|
34
|
+
// eslint-disable-next-line prefer-destructuring
|
|
35
|
+
domains = stats.domains;
|
|
36
|
+
}
|
|
37
|
+
if (domainType === 'Full') {
|
|
38
|
+
const source = getSourceFromLoader(loader);
|
|
39
|
+
domains = selections.map(() => DOMAINS[source.dtype]);
|
|
40
|
+
}
|
|
41
|
+
return { domains, sliders };
|
|
42
|
+
}
|
|
43
|
+
const buttonStyles = {
|
|
44
|
+
borderStyle: 'dashed',
|
|
45
|
+
marginTop: '10px',
|
|
46
|
+
fontWeight: 400,
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Controller for the various imaging options (color, opactiy, sliders etc.)
|
|
50
|
+
* @prop {object} imageData Image config object, one of the `images` in the raster schema.
|
|
51
|
+
* @prop {object} layerId Randomly generated id for the image layer that this controller handles.
|
|
52
|
+
* @prop {function} handleLayerRemove Callback for handling the removal of a layer.
|
|
53
|
+
* @prop {object} loader Loader object for the current imaging layer.
|
|
54
|
+
* @prop {function} handleLayerChange Callback for handling the changing of layer properties.
|
|
55
|
+
*/
|
|
56
|
+
export default function LayerController(props) {
|
|
57
|
+
const { layer, name, loader, theme, handleLayerRemove, handleLayerChange, shouldShowTransparentColor, shouldShowDomain, shouldShowColormap, ChannelController, setViewState, disable3d, setImageLayerCallback, setAreLayerChannelsLoading, areLayerChannelsLoading, disabled, spatialHeight, spatialWidth, disableChannelsIfRgbDetected, shouldShowRemoveLayerButton, } = props;
|
|
58
|
+
const { colormap, opacity, channels, transparentColor, renderingMode, xSlice, ySlice, zSlice, resolution, use3d, modelMatrix, } = layer;
|
|
59
|
+
// Channels are used in a lot of callbacks and change handlers
|
|
60
|
+
// so ensuring they have an up to date copy of the data ensures consistency.
|
|
61
|
+
// See: https://github.com/vitessce/vitessce/issues/1036
|
|
62
|
+
const channelRef = useRef(channels);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
channelRef.current = channels;
|
|
65
|
+
return undefined;
|
|
66
|
+
}, [channels]);
|
|
67
|
+
const firstSelection = channels[0]?.selection || {};
|
|
68
|
+
const { data, channels: channelOptions } = loader;
|
|
69
|
+
const [tab, setTab] = useState(0);
|
|
70
|
+
const handleTabChange = (event, newTab) => {
|
|
71
|
+
setTab(newTab);
|
|
72
|
+
};
|
|
73
|
+
const { labels, shape } = Array.isArray(data) ? data[data.length - 1] : data;
|
|
74
|
+
const [domainType, setDomainType] = useState(layer.domainType);
|
|
75
|
+
const [isExpanded, setIsExpanded] = useState(true);
|
|
76
|
+
const [globalLabelValues, setGlobalLabelValues] = useState(GLOBAL_LABELS.filter(field => typeof firstSelection[field] === 'number').reduce((o, key) => ({ ...o, [key]: firstSelection[key] }), {}));
|
|
77
|
+
function setVisible(v) {
|
|
78
|
+
handleLayerChange({ ...layer, visible: v });
|
|
79
|
+
}
|
|
80
|
+
function setColormap(v) {
|
|
81
|
+
handleLayerChange({ ...layer, colormap: v });
|
|
82
|
+
}
|
|
83
|
+
function setOpacity(v) {
|
|
84
|
+
handleLayerChange({ ...layer, opacity: v });
|
|
85
|
+
}
|
|
86
|
+
function setChannels(v) {
|
|
87
|
+
handleLayerChange({ ...layer, channels: v });
|
|
88
|
+
}
|
|
89
|
+
function setTransparentColor(v) {
|
|
90
|
+
handleLayerChange({ ...layer, transparentColor: v });
|
|
91
|
+
}
|
|
92
|
+
function setRenderingMode(v) {
|
|
93
|
+
handleLayerChange({ ...layer, renderingMode: v });
|
|
94
|
+
}
|
|
95
|
+
function handleMultiPropertyChange(obj) {
|
|
96
|
+
handleLayerChange({ ...layer, ...obj });
|
|
97
|
+
}
|
|
98
|
+
function handleSlicerSetting(slice, val) {
|
|
99
|
+
handleLayerChange({ ...layer, [`${slice}Slice`]: val });
|
|
100
|
+
}
|
|
101
|
+
function setChannelsAndDomainType(newChannels, newDomainType) {
|
|
102
|
+
handleLayerChange({
|
|
103
|
+
...layer,
|
|
104
|
+
channels: newChannels,
|
|
105
|
+
domainType: newDomainType,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function setChannel(v, i) {
|
|
109
|
+
const newChannels = [...channelRef.current];
|
|
110
|
+
newChannels[i] = v;
|
|
111
|
+
handleLayerChange({ ...layer, channels: newChannels });
|
|
112
|
+
}
|
|
113
|
+
function addChannel(v) {
|
|
114
|
+
const newChannels = [...channelRef.current, v];
|
|
115
|
+
handleLayerChange({ ...layer, channels: newChannels });
|
|
116
|
+
}
|
|
117
|
+
function removeChannel(i) {
|
|
118
|
+
const newChannels = [...channelRef.current];
|
|
119
|
+
newChannels.splice(i, 1);
|
|
120
|
+
handleLayerChange({ ...layer, channels: newChannels });
|
|
121
|
+
}
|
|
122
|
+
const setAreAllChannelsLoading = (val) => {
|
|
123
|
+
const newAreLayerChannelsLoading = channelRef.current.map(() => val);
|
|
124
|
+
setAreLayerChannelsLoading(newAreLayerChannelsLoading);
|
|
125
|
+
};
|
|
126
|
+
// Handles adding a channel, creating a default selection
|
|
127
|
+
// for the current global settings and domain type.
|
|
128
|
+
const handleChannelAdd = async () => {
|
|
129
|
+
const selection = {};
|
|
130
|
+
labels.forEach((label) => {
|
|
131
|
+
// Set new image to default selection for non-global selections (0)
|
|
132
|
+
// and use current global selection otherwise.
|
|
133
|
+
selection[label] = GLOBAL_LABELS.includes(label)
|
|
134
|
+
? globalLabelValues[label] || 0
|
|
135
|
+
: 0;
|
|
136
|
+
});
|
|
137
|
+
const { domains, sliders } = await getDomainsAndSliders(loader, [selection], domainType, use3d);
|
|
138
|
+
const domain = domains[0];
|
|
139
|
+
const slider = domain;
|
|
140
|
+
const color = [255, 255, 255];
|
|
141
|
+
const visible = true;
|
|
142
|
+
const newChannelId = channels.length;
|
|
143
|
+
const newAreLayerChannelsLoading = [...areLayerChannelsLoading];
|
|
144
|
+
newAreLayerChannelsLoading[newChannelId] = true;
|
|
145
|
+
setAreLayerChannelsLoading(newAreLayerChannelsLoading);
|
|
146
|
+
const channel = {
|
|
147
|
+
selection,
|
|
148
|
+
slider,
|
|
149
|
+
visible,
|
|
150
|
+
color,
|
|
151
|
+
};
|
|
152
|
+
setImageLayerCallback(() => {
|
|
153
|
+
setChannel({ ...channel, slider: sliders[0] }, newChannelId);
|
|
154
|
+
const areLayerChannelsLoadingCallback = [...newAreLayerChannelsLoading];
|
|
155
|
+
areLayerChannelsLoadingCallback[newChannelId] = false;
|
|
156
|
+
setAreLayerChannelsLoading(areLayerChannelsLoadingCallback);
|
|
157
|
+
setImageLayerCallback(null);
|
|
158
|
+
});
|
|
159
|
+
addChannel(channel);
|
|
160
|
+
};
|
|
161
|
+
const handleDomainChange = async (value) => {
|
|
162
|
+
setDomainType(value);
|
|
163
|
+
const selections = channels.map(channel => channel.selection);
|
|
164
|
+
let sliders = channels.map(channel => channel.slider);
|
|
165
|
+
const { domains } = await getDomainsAndSliders(loader, selections, value, use3d);
|
|
166
|
+
// If it's the right-most slider, we take the minimum of that and the new value.
|
|
167
|
+
// Otherwise, we use the maximum of the left-hand side and the new value.
|
|
168
|
+
sliders = sliders.map((slider, i) => {
|
|
169
|
+
const [left, right] = slider;
|
|
170
|
+
return [Math.max(left, domains[i][0]), Math.min(right, domains[i][1])];
|
|
171
|
+
});
|
|
172
|
+
const newChannels = channels.map((c, i) => ({ ...c, slider: sliders[i] }));
|
|
173
|
+
setChannelsAndDomainType(newChannels, value);
|
|
174
|
+
};
|
|
175
|
+
// This call updates all channel selections with new global selection from the UI.
|
|
176
|
+
const handleGlobalChannelsSelectionChange = async ({ selection, event }) => {
|
|
177
|
+
const selections = channels.map(channel => ({
|
|
178
|
+
...channel.selection,
|
|
179
|
+
...selection,
|
|
180
|
+
}));
|
|
181
|
+
const canUpdateChannels = event.type === 'mouseup' || event.type === 'keydown';
|
|
182
|
+
// Only update domains on a mouseup event for the same reason as above.
|
|
183
|
+
if (canUpdateChannels) {
|
|
184
|
+
setAreAllChannelsLoading(true);
|
|
185
|
+
getDomainsAndSliders(loader, selections, domainType, use3d).then(({ sliders }) => {
|
|
186
|
+
const newChannelsWithSelection = channels.map(c => ({
|
|
187
|
+
...c,
|
|
188
|
+
selection: { ...c.selection, ...selection },
|
|
189
|
+
}));
|
|
190
|
+
// Set the callback before changing the selection
|
|
191
|
+
// so the callback is used when the layer (re)loads its data.
|
|
192
|
+
setImageLayerCallback(() => {
|
|
193
|
+
setImageLayerCallback(null);
|
|
194
|
+
setAreAllChannelsLoading(false);
|
|
195
|
+
const newChannelsWithSliders = [...newChannelsWithSelection].map((c, i) => ({
|
|
196
|
+
...c,
|
|
197
|
+
slider: sliders[i],
|
|
198
|
+
}));
|
|
199
|
+
setChannels(newChannelsWithSliders);
|
|
200
|
+
});
|
|
201
|
+
setChannels(newChannelsWithSelection);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
setGlobalLabelValues(prev => ({ ...prev, ...selection }));
|
|
205
|
+
};
|
|
206
|
+
let channelControllers = [];
|
|
207
|
+
if (labels.length > 0) {
|
|
208
|
+
const channelLabel = labels.find(c => c === 'channel' || c === 'c') || labels[0];
|
|
209
|
+
// Create the channel controllers for each channel.
|
|
210
|
+
channelControllers = channels.map(
|
|
211
|
+
// c is an object like { color, selection, slider, visible }.
|
|
212
|
+
(c, channelId) => {
|
|
213
|
+
// Update the auxiliary store with the current loading state of a channel.
|
|
214
|
+
const setIsLoading = (val) => {
|
|
215
|
+
const newAreLayerChannelsLoading = [...areLayerChannelsLoading];
|
|
216
|
+
newAreLayerChannelsLoading[channelId] = val;
|
|
217
|
+
setAreLayerChannelsLoading(newAreLayerChannelsLoading);
|
|
218
|
+
};
|
|
219
|
+
// Change one property of a channel (for now - soon
|
|
220
|
+
// nested structures allowing for multiple z/t selecitons at once, for example).
|
|
221
|
+
const handleChannelPropertyChange = (property, value) => {
|
|
222
|
+
// property is something like "selection" or "slider."
|
|
223
|
+
// value is the actual change, like { channel: "DAPI" }.
|
|
224
|
+
const update = { [property]: value };
|
|
225
|
+
if (property === 'selection') {
|
|
226
|
+
// Channel is loading until the layer callback is called
|
|
227
|
+
// by the layer, which fetches the raster data.
|
|
228
|
+
setIsLoading(true);
|
|
229
|
+
update.selection = {
|
|
230
|
+
...globalLabelValues,
|
|
231
|
+
...update.selection,
|
|
232
|
+
};
|
|
233
|
+
setChannel({ ...c, ...update }, channelId);
|
|
234
|
+
// Call back for raster layer handles update of UI
|
|
235
|
+
// like sliders and the loading state of the channel.
|
|
236
|
+
setImageLayerCallback(async () => {
|
|
237
|
+
const selections = [
|
|
238
|
+
{ ...channels[channelId][property], ...value },
|
|
239
|
+
];
|
|
240
|
+
const { sliders } = await getDomainsAndSliders(loader, selections, domainType, use3d);
|
|
241
|
+
[update.slider] = sliders;
|
|
242
|
+
setChannel({ ...c, ...update }, channelId);
|
|
243
|
+
setImageLayerCallback(null);
|
|
244
|
+
setIsLoading(false);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
setChannel({ ...c, ...update }, channelId);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
const handleChannelRemove = () => {
|
|
252
|
+
removeChannel(channelId);
|
|
253
|
+
};
|
|
254
|
+
const handleIQRUpdate = async () => {
|
|
255
|
+
const { data: loaderData } = loader;
|
|
256
|
+
const source = Array.isArray(loaderData)
|
|
257
|
+
? loaderData[loaderData.length - 1]
|
|
258
|
+
: loaderData;
|
|
259
|
+
const raster = await source.getRaster({
|
|
260
|
+
selection: channels[channelId].selection,
|
|
261
|
+
});
|
|
262
|
+
const stats = viv.getChannelStats(raster.data);
|
|
263
|
+
const { q1, q3 } = stats;
|
|
264
|
+
setChannel({ ...c, slider: [q1, q3] }, channelId);
|
|
265
|
+
};
|
|
266
|
+
return (_jsx(ChannelController
|
|
267
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
268
|
+
, { dimName: channelLabel, visibility: c.visible, selectionIndex: c.selection[channelLabel], slider: c.slider, color: c.color, channels: channels, channelId: channelId, domainType: domainType, loader: loader, globalLabelValues: globalLabelValues, theme: theme, channelOptions: channelOptions, colormapOn: Boolean(colormap), handlePropertyChange: handleChannelPropertyChange, handleChannelRemove: handleChannelRemove, handleIQRUpdate: handleIQRUpdate, setRasterLayerCallback: setImageLayerCallback, isLoading: areLayerChannelsLoading[channelId], use3d: use3d }, `channel-controller-${channelId}`));
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
const controllerSectionClasses = useControllerSectionStyles();
|
|
272
|
+
const { visible } = layer;
|
|
273
|
+
const visibleSetting = typeof visible === 'boolean' ? visible : true;
|
|
274
|
+
const Visibility = visibleSetting ? VisibilityIcon : VisibilityOffIcon;
|
|
275
|
+
// Only show Volume tabs if 3D is available.
|
|
276
|
+
const hasViewableResolutions = Boolean(Array.from({
|
|
277
|
+
length: loader.data.length,
|
|
278
|
+
}).filter((_, res) => canLoadResolution(loader.data, res)).length);
|
|
279
|
+
const useVolumeTabs = !disable3d && shape[labels.indexOf('z')] > 1 && hasViewableResolutions;
|
|
280
|
+
const FullController = (_jsxs(_Fragment, { children: [_jsx(LayerOptions, { channels: channels, opacity: opacity, colormap: colormap, transparentColor: transparentColor, domainType: domainType,
|
|
281
|
+
// Only allow for global dimension controllers that
|
|
282
|
+
// exist in the `dimensions` part of the loader.
|
|
283
|
+
globalControlLabels: labels.filter(label => GLOBAL_LABELS.includes(label)), globalLabelValues: globalLabelValues, handleOpacityChange: setOpacity, handleColormapChange: setColormap, handleGlobalChannelsSelectionChange: handleGlobalChannelsSelectionChange, handleTransparentColorChange: setTransparentColor, disableChannelsIfRgbDetected: isRgb(loader, channels) && disableChannelsIfRgbDetected, handleDomainChange: handleDomainChange, shouldShowTransparentColor: shouldShowTransparentColor, shouldShowDomain: shouldShowDomain, shouldShowColormap: shouldShowColormap, use3d: use3d, loader: loader, handleMultiPropertyChange: handleMultiPropertyChange, resolution: resolution, disable3d: disable3d, setRasterLayerCallback: setImageLayerCallback, setAreAllChannelsLoading: setAreAllChannelsLoading, setViewState: setViewState, spatialHeight: spatialHeight, spatialWidth: spatialWidth, modelMatrix: modelMatrix }), isRgb(loader, channels) && disableChannelsIfRgbDetected
|
|
284
|
+
? null
|
|
285
|
+
: channelControllers, isRgb(loader, channels) && disableChannelsIfRgbDetected ? null : (_jsx(Button, { disabled: channels.length === viv.MAX_CHANNELS, onClick: handleChannelAdd, fullWidth: true, variant: "outlined", style: buttonStyles, startIcon: _jsx(AddIcon, {}), size: "small", children: "Add Channel" }))] }));
|
|
286
|
+
return (_jsxs(Accordion, { className: controllerSectionClasses.root, onChange: (e, expanded) => !disabled
|
|
287
|
+
&& setIsExpanded(expanded && e?.target?.attributes?.role?.value === 'presentation'), TransitionProps: { enter: false }, expanded: !disabled && isExpanded, children: [_jsx(StyledAccordionSummary, { expandIcon: _jsx(ExpandMoreIcon, { role: "presentation" }), "aria-controls": `layer-${name}-controls`, children: _jsxs(Grid, { container: true, direction: "column", m: 1, justifyContent: "center", children: [_jsxs(OverflowEllipsisGrid, { item: true, children: [_jsx(Button, { onClick: (e) => {
|
|
288
|
+
if (!disabled) {
|
|
289
|
+
// Needed to prevent affecting the expansion panel from changing
|
|
290
|
+
e.stopPropagation();
|
|
291
|
+
const nextVisible = typeof visible === 'boolean' ? !visible : false;
|
|
292
|
+
setVisible(nextVisible);
|
|
293
|
+
}
|
|
294
|
+
}, style: {
|
|
295
|
+
marginRight: 8,
|
|
296
|
+
marginBottom: 2,
|
|
297
|
+
padding: 0,
|
|
298
|
+
minWidth: 0,
|
|
299
|
+
}, children: _jsx(Visibility, {}) }), name] }), !disabled && !isExpanded && !use3d && (_jsxs(Grid, { container: true, direction: "row", alignItems: "center", justifyContent: "center", children: [_jsx(Grid, { item: true, xs: 6, children: _jsx(StyledInputLabel, { htmlFor: `layer-${name}-opacity-closed`, children: "Opacity:" }) }), _jsx(Grid, { item: true, xs: 6, children: _jsx(Slider, { id: `layer-${name}-opacity-closed`, value: opacity, onChange: (e, v) => setOpacity(v), valueLabelDisplay: "auto", getAriaLabel: () => 'opacity slider', min: 0, max: 1, step: 0.01, orientation: "horizontal" }) })] }))] }) }), _jsxs(StyledAccordionDetails, { children: [useVolumeTabs ? (_jsxs(_Fragment, { children: [_jsxs(Tabs, { value: tab, onChange: handleTabChange, "aria-label": "simple tabs example", style: { height: '24px', minHeight: '24px' }, children: [_jsx(Tab, { label: "Channels", style: {
|
|
300
|
+
fontSize: '.75rem',
|
|
301
|
+
bottom: 12,
|
|
302
|
+
width: '50%',
|
|
303
|
+
minWidth: '50%',
|
|
304
|
+
}, disableRipple: true }), _jsx(Tab, { label: "Volume", style: {
|
|
305
|
+
fontSize: '.75rem',
|
|
306
|
+
bottom: 12,
|
|
307
|
+
width: '50%',
|
|
308
|
+
minWidth: '50%',
|
|
309
|
+
} })] }), _jsx(TabPanel, { value: tab, index: 0, children: FullController }), _jsx(TabPanel, { value: tab, index: 1, style: { marginTop: 4 }, children: _jsx(VolumeOptions, { loader: loader, handleSlicerSetting: handleSlicerSetting, handleRenderingModeChange: setRenderingMode, renderingMode: renderingMode, xSlice: xSlice, ySlice: ySlice, zSlice: zSlice, use3d: use3d, setViewState: setViewState, spatialHeight: spatialHeight, spatialWidth: spatialWidth, modelMatrix: modelMatrix }) })] })) : (FullController), shouldShowRemoveLayerButton ? (_jsx(Button, { onClick: handleLayerRemove, fullWidth: true, variant: "outlined", style: buttonStyles, size: "small", children: "Remove Image Layer" })) : null] })] }));
|
|
310
|
+
}
|