Skip to content

Commit 944d167

Browse files
committed
Support 64-bit integers
1 parent 34e0a67 commit 944d167

31 files changed

+320
-231
lines changed

apps/storybook/src/HeatmapVisDisplay.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { type Meta, type StoryFn, type StoryObj } from '@storybook/react';
1010
import HeatmapVisStoriesMeta from './HeatmapVis.stories';
1111

1212
const { dataArray } = HeatmapVisStoriesMeta.args;
13-
const asymTwoD = mockValues.twoDAsym();
13+
const asymTwoD = mockValues.twoD_asym();
1414

1515
const meta = {
1616
...HeatmapVisStoriesMeta,

packages/app/src/metadata-viewer/utils.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
2+
isFloatType,
23
isH5WebComplex,
34
isIntegerType,
4-
isNumericType,
55
isScalarShape,
66
} from '@h5web/shared/guards';
77
import {
@@ -28,17 +28,15 @@ export function renderShape(shape: Shape): string {
2828
}
2929

3030
export function renderType(type: DType): string {
31-
if (isNumericType(type)) {
32-
const { endianness, size } = type;
33-
34-
const endiannessStr = endianness ? `, ${endianness}` : '';
35-
const signStr = isIntegerType(type)
36-
? type.signed
37-
? ' (signed)'
38-
: ' (unsigned)'
39-
: '';
31+
if (isIntegerType(type)) {
32+
const sign = type.signed ? ' (signed)' : ' (unsigned)';
33+
const endianness = type.endianness ? `, ${type.endianness}` : '';
34+
return `Integer${sign}, ${type.size}-bit${endianness}`;
35+
}
4036

41-
return `${type.class}${signStr}, ${size}-bit${endiannessStr}`;
37+
if (isFloatType(type)) {
38+
const endianness = type.endianness ? `, ${type.endianness}` : '';
39+
return `Float, ${type.size}-bit${endianness}`;
4240
}
4341

4442
if (type.class === DTypeClass.String) {

packages/app/src/providers/mock/mock-file.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export function makeMockFile(): GroupWithChildren {
152152
group('typed_arrays', [
153153
array('uint8', { type: intType(false, 8) }),
154154
array('int16', { type: intType(true, 16) }),
155+
array('int64', { type: intType(true, 64) }),
155156
array('float32', { type: floatType(32) }),
156157
array('float64', { type: floatType(64) }),
157158
withImageAttr(array('uint8_rgb', { type: intType(false, 8) })),
@@ -267,6 +268,13 @@ export function makeMockFile(): GroupWithChildren {
267268
axes: { X: array('X'), Y_scatter: array('Y_scatter') },
268269
axesAttr: ['X', 'Y_scatter'],
269270
}),
271+
nxData('bigint', {
272+
signal: array('twoD_bigint'),
273+
auxiliary: { secondary_bigint: array('secondary_bigint') },
274+
auxAttr: ['secondary_bigint'],
275+
axes: { X_bigint: array('X_bigint') },
276+
axesAttr: ['.', 'X_bigint'],
277+
}),
270278
nxGroup('old-style', 'NXdata', {
271279
children: [
272280
array('twoD', {

packages/app/src/vis-packs/core/complex/MappedComplexLineVis.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { createPortal } from 'react-dom';
1616

1717
import { type DimensionMapping } from '../../../dimension-mapper/models';
1818
import visualizerStyles from '../../../visualizer/Visualizer.module.css';
19+
import { useToNumArrays } from '../hooks';
1920
import { type LineConfig } from '../line/config';
2021
import { DEFAULT_DOMAIN } from '../utils';
2122
import ComplexLineToolbar from './ComplexLineToolbar';
@@ -46,8 +47,8 @@ function MappedComplexLineVis(props: Props) {
4647
auxValues = [],
4748
dims,
4849
dimMapping,
49-
axisLabels,
50-
axisValues,
50+
axisLabels = [],
51+
axisValues = [],
5152
title,
5253
toolbarContainer,
5354
config,
@@ -58,6 +59,7 @@ function MappedComplexLineVis(props: Props) {
5859
const { customDomain, yScaleType, xScaleType, curveType, showGrid } =
5960
lineConfig;
6061

62+
const numAxisArrays = useToNumArrays(axisValues);
6163
const [dataArray, ...auxArrays] = useMappedComplexArrays(
6264
[value, ...auxValues],
6365
dims,
@@ -98,8 +100,8 @@ function MappedComplexLineVis(props: Props) {
98100
curveType={curveType}
99101
showGrid={showGrid}
100102
abscissaParams={{
101-
label: axisLabels?.[xDimIndex],
102-
value: axisValues?.[xDimIndex],
103+
label: axisLabels[xDimIndex],
104+
value: numAxisArrays[xDimIndex],
103105
scaleType: xScaleType,
104106
}}
105107
ordinateLabel={ordinateLabel}

packages/app/src/vis-packs/core/complex/MappedComplexVis.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
useBaseArray,
2222
useMappedArray,
2323
useSlicedDimsAndMapping,
24+
useToNumArrays,
2425
} from '../hooks';
2526
import { DEFAULT_DOMAIN } from '../utils';
2627
import ComplexToolbar from './ComplexToolbar';
@@ -44,8 +45,8 @@ function MappedComplexVis(props: Props) {
4445
value,
4546
dims,
4647
dimMapping,
47-
axisLabels,
48-
axisValues,
48+
axisLabels = [],
49+
axisValues = [],
4950
title,
5051
toolbarContainer,
5152
config,
@@ -62,8 +63,9 @@ function MappedComplexVis(props: Props) {
6263
invertColorMap,
6364
} = heatmapConfig;
6465

65-
const [slicedDims, slicedMapping] = useSlicedDimsAndMapping(dims, dimMapping);
66+
const numAxisArrays = useToNumArrays(axisValues);
6667

68+
const [slicedDims, slicedMapping] = useSlicedDimsAndMapping(dims, dimMapping);
6769
const mappedArray = useMappedArray(value, slicedDims, slicedMapping);
6870

6971
const { phaseValues, phaseBounds, amplitudeValues, amplitudeBounds } =
@@ -111,12 +113,12 @@ function MappedComplexVis(props: Props) {
111113
showGrid={showGrid}
112114
invertColorMap={invertColorMap}
113115
abscissaParams={{
114-
label: axisLabels?.[xDimIndex],
115-
value: axisValues?.[xDimIndex],
116+
label: axisLabels[xDimIndex],
117+
value: numAxisArrays[xDimIndex],
116118
}}
117119
ordinateParams={{
118-
label: axisLabels?.[yDimIndex],
119-
value: axisValues?.[yDimIndex],
120+
label: axisLabels[yDimIndex],
121+
value: numAxisArrays[yDimIndex],
120122
}}
121123
alpha={
122124
visType === ComplexVisType.PhaseAmplitude

packages/app/src/vis-packs/core/compound/MappedCompoundVis.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function MappedCompoundVis(props: Props) {
7575
className={visualizerStyles.vis}
7676
dims={mappedArray.shape}
7777
cellFormatter={(row, col) =>
78+
// @ts-expect-error - `val: never` because formatter type isn't narrowed down
7879
fieldFormatters[col](mappedArray.get(row, col))
7980
}
8081
cellWidth={customCellWidth ?? cellWidth}

packages/app/src/vis-packs/core/heatmap/MappedHeatmapVis.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
useMappedArray,
1717
useSlicedDimsAndMapping,
1818
useToNumArray,
19+
useToNumArrays,
1920
} from '../hooks';
2021
import { DEFAULT_DOMAIN, formatNumLikeType, getSliceSelection } from '../utils';
2122
import { type HeatmapConfig } from './config';
@@ -38,8 +39,8 @@ function MappedHeatmapVis(props: Props) {
3839
dataset,
3940
value,
4041
dimMapping,
41-
axisLabels,
42-
axisValues,
42+
axisLabels = [],
43+
axisValues = [],
4344
title,
4445
toolbarContainer,
4546
config,
@@ -57,8 +58,10 @@ function MappedHeatmapVis(props: Props) {
5758
flipYAxis,
5859
} = config;
5960

60-
const { shape: dims } = dataset;
6161
const numArray = useToNumArray(value);
62+
const numAxisArrays = useToNumArrays(axisValues);
63+
64+
const { shape: dims } = dataset;
6265
const [slicedDims, slicedMapping] = useSlicedDimsAndMapping(dims, dimMapping);
6366
const dataArray = useMappedArray(numArray, slicedDims, slicedMapping);
6467

@@ -101,12 +104,12 @@ function MappedHeatmapVis(props: Props) {
101104
showGrid={showGrid}
102105
invertColorMap={invertColorMap}
103106
abscissaParams={{
104-
label: axisLabels?.[xDimIndex],
105-
value: axisValues?.[xDimIndex],
107+
label: axisLabels[xDimIndex],
108+
value: numAxisArrays[xDimIndex],
106109
}}
107110
ordinateParams={{
108-
label: axisLabels?.[yDimIndex],
109-
value: axisValues?.[yDimIndex],
111+
label: axisLabels[yDimIndex],
112+
value: numAxisArrays[yDimIndex],
110113
}}
111114
flipXAxis={flipXAxis}
112115
flipYAxis={flipYAxis}

packages/app/src/vis-packs/core/hooks.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ export const useToNumArray = createMemo(toNumArray);
2828

2929
export function useToNumArrays(
3030
arrays: ArrayValue<NumericLikeType>[],
31-
): NumArray[] {
31+
): NumArray[];
32+
33+
export function useToNumArrays(
34+
arrays: (ArrayValue<NumericLikeType> | undefined)[],
35+
): (NumArray | undefined)[];
36+
37+
export function useToNumArrays(
38+
arrays: (ArrayValue<NumericLikeType> | undefined)[],
39+
): (NumArray | undefined)[] {
3240
return useMemo(() => arrays.map(toNumArray), arrays); // eslint-disable-line react-hooks/exhaustive-deps
3341
}
3442

packages/app/src/vis-packs/core/line/LineVisContainer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ function LineVisContainer(props: VisContainerProps) {
4343
<MappedLineVis
4444
dataset={entity}
4545
value={value}
46-
dims={dims}
4746
dimMapping={dimMapping}
4847
title={entity.name}
4948
toolbarContainer={toolbarContainer}

packages/app/src/vis-packs/core/line/MappedLineVis.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ interface Props {
3838
auxLabels?: string[];
3939
auxValues?: ArrayValue<NumericLikeType>[];
4040
auxErrors?: (ArrayValue<NumericType> | undefined)[];
41-
dims: number[];
4241
dimMapping: DimensionMapping;
4342
axisLabels?: AxisMapping<string>;
4443
axisValues?: AxisMapping<ArrayValue<NumericType>>;
@@ -57,10 +56,9 @@ function MappedLineVis(props: Props) {
5756
auxLabels = [],
5857
auxValues = [],
5958
auxErrors = [],
60-
dims,
6159
dimMapping,
62-
axisLabels,
63-
axisValues,
60+
axisLabels = [],
61+
axisValues = [],
6462
title,
6563
toolbarContainer,
6664
config,
@@ -76,20 +74,25 @@ function MappedLineVis(props: Props) {
7674
showErrors,
7775
} = config;
7876

77+
const { shape: dims } = dataset;
78+
const [slicedDims, slicedMapping] = useSlicedDimsAndMapping(dims, dimMapping);
79+
const hookArgs = [slicedDims, slicedMapping] as const;
80+
7981
const numArray = useToNumArray(value);
8082
const numAuxArrays = useToNumArrays(auxValues);
81-
const [slicedDims, slicedMapping] = useSlicedDimsAndMapping(dims, dimMapping);
83+
const numErrorsArray = useToNumArray(errors);
84+
const numAuxErrorsArrays = useToNumArrays(auxErrors);
85+
const numAxisArrays = useToNumArrays(axisValues);
8286

83-
const hookArgs = [slicedDims, slicedMapping] as const;
8487
const dataArray = useMappedArray(numArray, ...hookArgs);
85-
const errorArray = useMappedArray(errors, ...hookArgs);
88+
const errorsArray = useMappedArray(numErrorsArray, ...hookArgs);
8689
const auxArrays = useMappedArrays(numAuxArrays, ...hookArgs);
87-
const auxErrorsArrays = useMappedArrays(auxErrors, ...hookArgs);
90+
const auxErrorsArrays = useMappedArrays(numAuxErrorsArrays, ...hookArgs);
8891

8992
const dataDomain = useDomain(
9093
dataArray,
9194
yScaleType,
92-
showErrors ? errorArray : undefined,
95+
showErrors ? errorsArray : undefined,
9396
ignoreValue,
9497
);
9598

@@ -130,14 +133,14 @@ function MappedLineVis(props: Props) {
130133
curveType={curveType}
131134
showGrid={showGrid}
132135
abscissaParams={{
133-
label: axisLabels?.[xDimIndex],
134-
value: axisValues?.[xDimIndex],
136+
label: axisLabels[xDimIndex],
137+
value: numAxisArrays[xDimIndex],
135138
scaleType: xScaleType,
136139
}}
137140
ordinateLabel={valueLabel}
138141
title={title}
139142
dtype={formatNumLikeType(dataset.type)}
140-
errorsArray={errorArray}
143+
errorsArray={errorsArray}
141144
showErrors={showErrors}
142145
auxiliaries={auxArrays.map((array, i) => ({
143146
label: auxLabels[i],

0 commit comments

Comments
 (0)