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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/deflate.b44720d0.mjs +13 -0
  2. package/dist/index.ca9e70ae.mjs +137540 -0
  3. package/dist/index.mjs +10 -0
  4. package/dist/jpeg.edb20ff0.mjs +840 -0
  5. package/dist/lerc.df2f1733.mjs +1943 -0
  6. package/dist/lzw.2a639594.mjs +128 -0
  7. package/dist/packbits.958f7a40.mjs +30 -0
  8. package/dist/pako.esm.4b234125.mjs +3940 -0
  9. package/dist/raw.4239192e.mjs +12 -0
  10. package/dist/webimage.de21cf13.mjs +32 -0
  11. package/{dist → dist-tsc}/index.js +0 -0
  12. package/package.json +10 -10
  13. package/src/BitmaskChannelController.js +63 -0
  14. package/src/ChannelOptions.js +62 -0
  15. package/src/ColorPalette.js +49 -0
  16. package/src/ImageAddButton.js +51 -0
  17. package/src/LayerController.js +599 -0
  18. package/src/LayerControllerSubscriber.js +510 -0
  19. package/src/LayerOptions.js +463 -0
  20. package/src/RasterChannelController.js +256 -0
  21. package/src/RasterChannelController.test.js +23 -0
  22. package/src/VectorLayerController.js +65 -0
  23. package/src/VolumeOptions.js +218 -0
  24. package/src/constants.js +14 -0
  25. package/src/index.js +3 -0
  26. package/{dist → src}/shared-channel-controls.js +35 -6
  27. package/src/styles.js +113 -0
  28. package/src/utils.js +129 -0
  29. package/dist/BitmaskChannelController.js +0 -31
  30. package/dist/ChannelOptions.js +0 -39
  31. package/dist/ColorPalette.js +0 -31
  32. package/dist/ImageAddButton.js +0 -28
  33. package/dist/LayerController.js +0 -311
  34. package/dist/LayerControllerSubscriber.js +0 -197
  35. package/dist/LayerOptions.js +0 -211
  36. package/dist/RasterChannelController.js +0 -160
  37. package/dist/RasterChannelController.test.js +0 -21
  38. package/dist/VectorLayerController.js +0 -30
  39. package/dist/VolumeOptions.js +0 -78
  40. package/dist/constants.js +0 -12
  41. package/dist/styles.js +0 -103
  42. package/dist/utils.js +0 -109
package/src/styles.js ADDED
@@ -0,0 +1,113 @@
1
+ import { makeStyles, withStyles } from '@material-ui/core/styles';
2
+ import AccordionSummary from '@material-ui/core/AccordionSummary';
3
+ import AccordionDetails from '@material-ui/core/AccordionDetails';
4
+ import InputLabel from '@material-ui/core/InputLabel';
5
+ import Slider from '@material-ui/core/Slider';
6
+ import Grid from '@material-ui/core/Grid';
7
+
8
+ const useSpanStyles = makeStyles(() => ({
9
+ span: {
10
+ width: '70px',
11
+ textAlign: 'center',
12
+ paddingLeft: '2px',
13
+ paddingRight: '2px',
14
+ },
15
+ }));
16
+
17
+ export function MuiSpan(props) {
18
+ const { children } = props;
19
+ const classes = useSpanStyles();
20
+ return <span className={classes.span}>{children}</span>;
21
+ }
22
+
23
+ export const useSelectStyles = makeStyles(() => ({
24
+ selectRoot: {
25
+ padding: 0,
26
+ height: 'auto',
27
+ margin: '4px 0',
28
+ },
29
+ }));
30
+
31
+ export const useOptionStyles = withStyles(theme => ({
32
+ paper: {
33
+ backgroundColor: theme.palette.background.paper,
34
+ },
35
+ span: {
36
+ width: '70px',
37
+ textAlign: 'center',
38
+ paddingLeft: '2px',
39
+ paddingRight: '2px',
40
+ },
41
+ colors: {
42
+ '&:hover': {
43
+ backgroundColor: 'transparent',
44
+ },
45
+ paddingLeft: '2px',
46
+ paddingRight: '2px',
47
+ },
48
+ popper: {
49
+ zIndex: 4,
50
+ },
51
+ }));
52
+
53
+ const sharedControllerStyles = {
54
+ width: '100%',
55
+ flexDirection: 'column',
56
+ };
57
+
58
+ export const useControllerSectionStyles = makeStyles(() => ({
59
+ root: {
60
+ ...sharedControllerStyles,
61
+ padding: '0px 8px',
62
+ },
63
+ }));
64
+
65
+ export const StyledAccordionDetails = withStyles(() => ({
66
+ root: {
67
+ ...sharedControllerStyles,
68
+ padding: '8px 8px 24px 8px',
69
+ },
70
+ }))(AccordionDetails);
71
+
72
+ export const StyledAccordionSummary = withStyles(theme => ({
73
+ root: {
74
+ padding: '0px 8px',
75
+ },
76
+ content: {
77
+ margin: '4px 0px',
78
+ minWidth: '0px',
79
+ },
80
+ expanded: {
81
+ marginBottom: theme.spacing(-3),
82
+ top: theme.spacing(-1),
83
+ },
84
+ expandIcon: {
85
+ '&$expanded': {
86
+ top: theme.spacing(-1.3),
87
+ },
88
+ },
89
+ }))(AccordionSummary);
90
+
91
+ export const StyledInputLabel = withStyles(() => ({
92
+ root: {
93
+ fontSize: '14px',
94
+ },
95
+ }))(InputLabel);
96
+
97
+ export const OverflowEllipsisGrid = withStyles(() => ({
98
+ item: {
99
+ width: '100%',
100
+ overflow: 'hidden',
101
+ whiteSpace: 'nowrap',
102
+ textOverflow: 'ellipsis',
103
+ },
104
+ }))(Grid);
105
+
106
+ export const StyledSelectionSlider = withStyles(() => ({
107
+ root: {
108
+ marginTop: '7px',
109
+ },
110
+ markActive: {
111
+ backgroundColor: 'rgba(128, 128, 128, 0.7)',
112
+ },
113
+ }))(Slider);
package/src/utils.js ADDED
@@ -0,0 +1,129 @@
1
+ import { viv } from '@vitessce/gl';
2
+ import { Matrix4 } from 'math.gl';
3
+
4
+ async function getSingleSelectionStats2D({ loader, selection }) {
5
+ const data = Array.isArray(loader) ? loader[loader.length - 1] : loader;
6
+ const raster = await data.getRaster({ selection });
7
+ const selectionStats = viv.getChannelStats(raster.data);
8
+ const { domain, contrastLimits: slider } = selectionStats;
9
+ return { domain, slider };
10
+ }
11
+
12
+ async function getSingleSelectionStats3D({ loader, selection }) {
13
+ const lowResSource = loader[loader.length - 1];
14
+ const { shape, labels } = lowResSource;
15
+ // eslint-disable-next-line no-bitwise
16
+ const sizeZ = shape[labels.indexOf('z')] >> (loader.length - 1);
17
+ const raster0 = await lowResSource.getRaster({
18
+ selection: { ...selection, z: 0 },
19
+ });
20
+ const rasterMid = await lowResSource.getRaster({
21
+ selection: { ...selection, z: Math.floor(sizeZ / 2) },
22
+ });
23
+ const rasterTop = await lowResSource.getRaster({
24
+ selection: { ...selection, z: Math.max(0, sizeZ - 1) },
25
+ });
26
+ const stats0 = viv.getChannelStats(raster0.data);
27
+ const statsMid = viv.getChannelStats(rasterMid.data);
28
+ const statsTop = viv.getChannelStats(rasterTop.data);
29
+ return {
30
+ domain: [
31
+ Math.min(stats0.domain[0], statsMid.domain[0], statsTop.domain[0]),
32
+ Math.max(stats0.domain[1], statsMid.domain[1], statsTop.domain[1]),
33
+ ],
34
+ slider: [
35
+ Math.min(
36
+ stats0.contrastLimits[0],
37
+ statsMid.contrastLimits[0],
38
+ statsTop.contrastLimits[0],
39
+ ),
40
+ Math.max(
41
+ stats0.contrastLimits[1],
42
+ statsMid.contrastLimits[1],
43
+ statsTop.contrastLimits[1],
44
+ ),
45
+ ],
46
+ };
47
+ }
48
+
49
+ /**
50
+ * Get bounding cube for a given loader i.e [[0, width], [0, height], [0, depth]]
51
+ * @param {Object} loader PixelSource|PixelSource[]
52
+ * @param {[]} selection Selection for stats.
53
+ * @param {boolean} use3d Whether or not to get 3d stats.
54
+ * @returns {Object} { domains, sliders }
55
+ */
56
+ export const getSingleSelectionStats = async ({ loader, selection, use3d }) => {
57
+ const getStats = use3d
58
+ ? getSingleSelectionStats3D
59
+ : getSingleSelectionStats2D;
60
+ return getStats({ loader, selection });
61
+ };
62
+
63
+ export const getMultiSelectionStats = async ({ loader, selections, use3d }) => {
64
+ const stats = await Promise.all(
65
+ selections.map(selection => getSingleSelectionStats({ loader, selection, use3d })),
66
+ );
67
+ const domains = stats.map(stat => stat.domain);
68
+ const sliders = stats.map(stat => stat.slider);
69
+ return { domains, sliders };
70
+ };
71
+
72
+ /**
73
+ * Get physical size scaling Matrix4
74
+ * @param {Object} loader PixelSource
75
+ * @returns {Object} matrix
76
+ */
77
+ export function getPhysicalSizeScalingMatrix(loader) {
78
+ const { x, y, z } = loader?.meta?.physicalSizes ?? {};
79
+ if (x?.size && y?.size && z?.size) {
80
+ const min = Math.min(z.size, x.size, y.size);
81
+ const ratio = [x.size / min, y.size / min, z.size / min];
82
+ return new Matrix4().scale(ratio);
83
+ }
84
+ return new Matrix4().identity();
85
+ }
86
+
87
+ /**
88
+ * Get bounding cube for a given loader
89
+ * @param {Object} loader PixelSource|PixelSource[]
90
+ * @returns {Array} [0, width], [0, height], [0, depth]]
91
+ */
92
+ export function getBoundingCube(loader) {
93
+ const source = Array.isArray(loader) ? loader[0] : loader;
94
+ const { shape, labels } = source;
95
+ const physicalSizeScalingMatrix = getPhysicalSizeScalingMatrix(source);
96
+ const xSlice = [0, physicalSizeScalingMatrix[0] * shape[labels.indexOf('x')]];
97
+ const ySlice = [0, physicalSizeScalingMatrix[5] * shape[labels.indexOf('y')]];
98
+ const zSlice = [
99
+ 0,
100
+ physicalSizeScalingMatrix[10] * shape[labels.indexOf('z')],
101
+ ];
102
+ return [xSlice, ySlice, zSlice];
103
+ }
104
+
105
+ export function abbreviateNumber(value) {
106
+ // Return an abbreviated representation of value, in 5 characters or less.
107
+
108
+ const maxLength = 5;
109
+ let maxNaiveDigits = maxLength;
110
+
111
+ /* eslint-disable no-plusplus */
112
+ if (!Number.isInteger(value)) {
113
+ --maxNaiveDigits;
114
+ } // Wasted on "."
115
+ if (value < 1) {
116
+ --maxNaiveDigits;
117
+ } // Wasted on "0."
118
+ /* eslint-disable no-plusplus */
119
+
120
+ const naive = Intl.NumberFormat('en-US', {
121
+ maximumSignificantDigits: maxNaiveDigits,
122
+ useGrouping: false,
123
+ }).format(value);
124
+ if (naive.length <= maxLength) return naive;
125
+
126
+ // "e+9" consumes 3 characters, so if we even had two significant digits,
127
+ // it would take take us to six characters, including the decimal point.
128
+ return value.toExponential(0);
129
+ }
@@ -1,31 +0,0 @@
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;
@@ -1,39 +0,0 @@
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;
@@ -1,31 +0,0 @@
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;
@@ -1,28 +0,0 @@
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;