-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathMappedRgbVis.tsx
84 lines (74 loc) · 2.18 KB
/
MappedRgbVis.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { RgbVis } from '@h5web/lib';
import {
type ArrayShape,
type ArrayValue,
type Dataset,
type NumericType,
} from '@h5web/shared/hdf5-models';
import { type AxisMapping } from '@h5web/shared/nexus-models';
import { createPortal } from 'react-dom';
import { type DimensionMapping } from '../../../dimension-mapper/models';
import visualizerStyles from '../../../visualizer/Visualizer.module.css';
import {
useMappedArray,
useSlicedDimsAndMapping,
useToNumArray,
useToNumArrays,
} from '../hooks';
import { type RgbVisConfig } from './config';
import RgbToolbar from './RgbToolbar';
interface Props {
dataset: Dataset<ArrayShape, NumericType>;
value: ArrayValue<NumericType>;
axisLabels?: AxisMapping<string>;
axisValues?: AxisMapping<ArrayValue<NumericType>>;
dimMapping: DimensionMapping;
title: string;
toolbarContainer: HTMLDivElement | undefined;
config: RgbVisConfig;
}
function MappedRgbVis(props: Props) {
const {
dataset,
value,
axisLabels = [],
axisValues = [],
dimMapping,
title,
toolbarContainer,
config,
} = props;
const { showGrid, keepRatio, imageType, flipXAxis, flipYAxis } = config;
const { shape: dims } = dataset;
const numAxisArrays = useToNumArrays(axisValues);
const [slicedDims, slicedMapping] = useSlicedDimsAndMapping(dims, dimMapping);
const numArray = useToNumArray(value);
const dataArray = useMappedArray(numArray, slicedDims, slicedMapping);
const xDimIndex = dimMapping.indexOf('x');
const yDimIndex = dimMapping.indexOf('y');
return (
<>
{toolbarContainer &&
createPortal(<RgbToolbar config={config} />, toolbarContainer)}
<RgbVis
className={visualizerStyles.vis}
dataArray={dataArray}
title={title}
showGrid={showGrid}
aspect={keepRatio ? 'equal' : 'auto'}
imageType={imageType}
abscissaParams={{
label: axisLabels[xDimIndex],
value: numAxisArrays[xDimIndex],
}}
ordinateParams={{
label: axisLabels[yDimIndex],
value: numAxisArrays[yDimIndex],
}}
flipXAxis={flipXAxis}
flipYAxis={flipYAxis}
/>
</>
);
}
export default MappedRgbVis;