-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathMappedComplexLineVis.tsx
119 lines (108 loc) · 3.15 KB
/
MappedComplexLineVis.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
import {
LineVis,
useCombinedDomain,
useDomain,
useDomains,
useSafeDomain,
useVisDomain,
} from '@h5web/lib';
import {
type ArrayValue,
type ComplexType,
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 { useToNumArrays } from '../hooks';
import { type LineConfig } from '../line/config';
import { DEFAULT_DOMAIN } from '../utils';
import ComplexLineToolbar from './ComplexLineToolbar';
import { useMappedComplexArrays } from './hooks';
import { type ComplexLineConfig } from './lineConfig';
import { COMPLEX_VIS_TYPE_LABELS } from './utils';
interface Props {
value: ArrayValue<ComplexType>;
valueLabel?: string;
auxLabels?: string[];
auxValues?: ArrayValue<ComplexType>[];
dims: number[];
dimMapping: DimensionMapping;
axisLabels?: AxisMapping<string>;
axisValues?: AxisMapping<ArrayValue<NumericType>>;
title: string;
toolbarContainer: HTMLDivElement | undefined;
config: ComplexLineConfig;
lineConfig: LineConfig;
}
function MappedComplexLineVis(props: Props) {
const {
value,
valueLabel,
auxLabels = [],
auxValues = [],
dims,
dimMapping,
axisLabels = [],
axisValues = [],
title,
toolbarContainer,
config,
lineConfig,
} = props;
const { visType } = config;
const { customDomain, yScaleType, xScaleType, curveType, showGrid } =
lineConfig;
const numAxisArrays = useToNumArrays(axisValues);
const [dataArray, ...auxArrays] = useMappedComplexArrays(
[value, ...auxValues],
dims,
dimMapping,
visType,
);
const dataDomain = useDomain(dataArray, yScaleType);
const auxDomains = useDomains(auxArrays, yScaleType);
const combinedDomain =
useCombinedDomain([dataDomain, ...auxDomains]) || DEFAULT_DOMAIN;
const visDomain = useVisDomain(customDomain, combinedDomain);
const [safeDomain] = useSafeDomain(visDomain, combinedDomain, yScaleType);
const xDimIndex = dimMapping.indexOf('x');
const ordinateLabel = valueLabel
? `${valueLabel} (${COMPLEX_VIS_TYPE_LABELS[visType].toLowerCase()})`
: COMPLEX_VIS_TYPE_LABELS[visType];
return (
<>
{toolbarContainer &&
createPortal(
<ComplexLineToolbar
dataDomain={combinedDomain}
config={config}
lineConfig={lineConfig}
/>,
toolbarContainer,
)}
<LineVis
className={visualizerStyles.vis}
dataArray={dataArray}
domain={safeDomain}
scaleType={yScaleType}
curveType={curveType}
showGrid={showGrid}
abscissaParams={{
label: axisLabels[xDimIndex],
value: numAxisArrays[xDimIndex],
scaleType: xScaleType,
}}
ordinateLabel={ordinateLabel}
title={title}
auxiliaries={auxArrays.map((array, i) => ({
label: auxLabels[i],
array,
}))}
testid={dimMapping.toString()}
/>
</>
);
}
export default MappedComplexLineVis;