|
| 1 | +import React from 'react'; |
| 2 | + |
| 3 | +import { RadioButtonChecked, RadioButtonUnchecked } from '@mui/icons-material'; |
| 4 | +import Grid from '@mui/material/Grid'; |
| 5 | +import IconButton from '@mui/material/IconButton'; |
| 6 | +import Slider from '@mui/material/Slider'; |
| 7 | +import Typography from '@mui/material/Typography'; |
| 8 | + |
| 9 | +const ChannelController = ({ |
| 10 | + channel_axis, |
| 11 | + names, |
| 12 | + selections, |
| 13 | + contrastLimits, |
| 14 | + contrastLimitsRange, |
| 15 | + channelVisible, |
| 16 | + colormap, |
| 17 | + colors, |
| 18 | + toggleChannelVisibility, |
| 19 | + setChannelContrast, |
| 20 | +}) => { |
| 21 | + // from vizarr ChannelController |
| 22 | + const value = [...contrastLimits]; |
| 23 | + const color = `rgb(${colormap ? [255, 255, 255] : colors})`; |
| 24 | + const on = channelVisible; |
| 25 | + const [min, max] = contrastLimitsRange; |
| 26 | + |
| 27 | + const nameIndex = Number.isInteger(channel_axis) |
| 28 | + ? selections[channel_axis] |
| 29 | + : 0; |
| 30 | + const label = names[nameIndex]; |
| 31 | + |
| 32 | + return ( |
| 33 | + <> |
| 34 | + <Grid container justifyContent="space-between"> |
| 35 | + <Typography noWrap title={label}> |
| 36 | + {label} |
| 37 | + </Typography> |
| 38 | + </Grid> |
| 39 | + <Grid container spacing={2}> |
| 40 | + <Grid display="flex" justifyContent="center" alignItems="center"> |
| 41 | + <IconButton |
| 42 | + style={{ |
| 43 | + color, |
| 44 | + padding: 0, |
| 45 | + backgroundColor: 'transparent', |
| 46 | + }} |
| 47 | + onClick={toggleChannelVisibility} |
| 48 | + > |
| 49 | + {on ? <RadioButtonChecked /> : <RadioButtonUnchecked />} |
| 50 | + </IconButton> |
| 51 | + </Grid> |
| 52 | + <Grid |
| 53 | + size="grow" |
| 54 | + display="flex" |
| 55 | + justifyContent="center" |
| 56 | + alignItems="center" |
| 57 | + > |
| 58 | + <Slider |
| 59 | + size="small" |
| 60 | + value={value} |
| 61 | + min={min} |
| 62 | + max={max} |
| 63 | + step={0.01} |
| 64 | + style={{ |
| 65 | + padding: 0, |
| 66 | + color, |
| 67 | + }} |
| 68 | + onChange={(_e, v) => setChannelContrast(v)} |
| 69 | + /> |
| 70 | + </Grid> |
| 71 | + </Grid> |
| 72 | + </> |
| 73 | + ); |
| 74 | +}; |
| 75 | + |
| 76 | +export const ChannelControllers = ({ |
| 77 | + channel_axis, |
| 78 | + names, |
| 79 | + layerProps, |
| 80 | + toggleChannelVisibility, |
| 81 | + setChannelContrast, |
| 82 | +}) => { |
| 83 | + const nChannels = layerProps.selections.length; |
| 84 | + return ( |
| 85 | + <Grid sx={{ width: '100%' }}> |
| 86 | + {[...Array(nChannels).keys()].map((i) => ( |
| 87 | + <ChannelController |
| 88 | + key={i} |
| 89 | + channel_axis={channel_axis} |
| 90 | + names={names} |
| 91 | + selections={layerProps.selections[i]} |
| 92 | + contrastLimits={layerProps.contrastLimits[i]} |
| 93 | + contrastLimitsRange={layerProps.contrastLimitsRange[i]} |
| 94 | + channelVisible={layerProps.channelsVisible[i]} |
| 95 | + colors={layerProps.colors[i]} |
| 96 | + colormap={layerProps.colormap} |
| 97 | + toggleChannelVisibility={() => toggleChannelVisibility(i)} |
| 98 | + setChannelContrast={(cl) => setChannelContrast(i, cl)} |
| 99 | + /> |
| 100 | + ))} |
| 101 | + </Grid> |
| 102 | + ); |
| 103 | +}; |
0 commit comments