-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathMappedHeatmapVis.tsx
122 lines (110 loc) · 3.33 KB
/
MappedHeatmapVis.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { HeatmapVis, useDomain, useSafeDomain, useVisDomain } from '@h5web/lib';
import {
type ArrayShape,
type ArrayValue,
type Dataset,
type NumericLikeType,
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 { useDataContext } from '../../../providers/DataProvider';
import visualizerStyles from '../../../visualizer/Visualizer.module.css';
import {
useMappedArray,
useSlicedDimsAndMapping,
useToNumArray,
useToNumArrays,
} from '../hooks';
import { DEFAULT_DOMAIN, formatNumLikeType, getSliceSelection } from '../utils';
import { type HeatmapConfig } from './config';
import HeatmapToolbar from './HeatmapToolbar';
interface Props {
dataset: Dataset<ArrayShape, NumericLikeType>;
value: ArrayValue<NumericLikeType>;
axisLabels?: AxisMapping<string>;
axisValues?: AxisMapping<ArrayValue<NumericType>>;
dimMapping: DimensionMapping;
title: string;
toolbarContainer: HTMLDivElement | undefined;
config: HeatmapConfig;
ignoreValue?: (val: number) => boolean;
}
function MappedHeatmapVis(props: Props) {
const {
dataset,
value,
dimMapping,
axisLabels = [],
axisValues = [],
title,
toolbarContainer,
config,
ignoreValue,
} = props;
const {
customDomain,
colorMap,
scaleType,
keepRatio,
showGrid,
invertColorMap,
flipXAxis,
flipYAxis,
} = config;
const numArray = useToNumArray(value);
const numAxisArrays = useToNumArrays(axisValues);
const { shape: dims } = dataset;
const [slicedDims, slicedMapping] = useSlicedDimsAndMapping(dims, dimMapping);
const dataArray = useMappedArray(numArray, slicedDims, slicedMapping);
const dataDomain =
useDomain(dataArray, scaleType, undefined, ignoreValue) || DEFAULT_DOMAIN;
const visDomain = useVisDomain(customDomain, dataDomain);
const [safeDomain] = useSafeDomain(visDomain, dataDomain, scaleType);
const xDimIndex = dimMapping.indexOf('x');
const yDimIndex = dimMapping.indexOf('y');
const { getExportURL } = useDataContext();
const selection = getSliceSelection(dimMapping);
return (
<>
{toolbarContainer &&
createPortal(
<HeatmapToolbar
dataDomain={dataDomain}
isSlice={selection !== undefined}
config={config}
getExportURL={
getExportURL &&
((format) => getExportURL(format, dataset, selection, value))
}
/>,
toolbarContainer,
)}
<HeatmapVis
className={visualizerStyles.vis}
dataArray={dataArray}
title={title}
dtype={formatNumLikeType(dataset.type)}
domain={safeDomain}
colorMap={colorMap}
scaleType={scaleType}
aspect={keepRatio ? 'equal' : 'auto'}
showGrid={showGrid}
invertColorMap={invertColorMap}
abscissaParams={{
label: axisLabels[xDimIndex],
value: numAxisArrays[xDimIndex],
}}
ordinateParams={{
label: axisLabels[yDimIndex],
value: numAxisArrays[yDimIndex],
}}
flipXAxis={flipXAxis}
flipYAxis={flipYAxis}
ignoreValue={ignoreValue}
/>
</>
);
}
export default MappedHeatmapVis;