Skip to content

Commit

Permalink
Pass dtype as string to visualization components
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Oct 16, 2023
1 parent 4abe8c3 commit 11f2523
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 31 deletions.
4 changes: 2 additions & 2 deletions packages/app/src/vis-packs/core/heatmap/MappedHeatmapVis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
useSlicedDimsAndMapping,
useToNumArray,
} from '../hooks';
import { DEFAULT_DOMAIN, getSliceSelection } from '../utils';
import { DEFAULT_DOMAIN, formatNumLikeType, getSliceSelection } from '../utils';
import type { HeatmapConfig } from './config';
import HeatmapToolbar from './HeatmapToolbar';

Expand Down Expand Up @@ -90,7 +90,7 @@ function MappedHeatmapVis(props: Props) {
<HeatmapVis
dataArray={dataArray}
title={title}
dtype={dataset.type}
dtype={dataset && formatNumLikeType(dataset.type)}
domain={safeDomain}
colorMap={colorMap}
scaleType={scaleType}
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/vis-packs/core/line/MappedLineVis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
useSlicedDimsAndMapping,
useToNumArray,
} from '../hooks';
import { formatNumLikeType } from '../utils';
import type { LineConfig } from './config';
import LineToolbar from './LineToolbar';

Expand Down Expand Up @@ -123,7 +124,7 @@ function MappedLineVis(props: Props) {
}}
ordinateLabel={valueLabel}
title={title}
dtype={dataset?.type}
dtype={dataset && formatNumLikeType(dataset.type)}
errorsArray={errorArray}
showErrors={showErrors}
auxiliaries={auxArrays.map((array, i) => ({
Expand Down
13 changes: 12 additions & 1 deletion packages/app/src/vis-packs/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
NumArray,
NumericLikeType,
} from '@h5web/shared';
import { createArrayFromView } from '@h5web/shared';
import { createArrayFromView, DTypeClass, isNumericType } from '@h5web/shared';
import { isNumber } from 'lodash';
import type { NdArray, TypedArray } from 'ndarray';
import ndarray from 'ndarray';
Expand Down Expand Up @@ -97,3 +97,14 @@ export function toNumArray(arr: ArrayValue<NumericLikeType>): NumArray {

return arr as NumArray;
}

const TYPE_STRINGS: Record<NumericLikeType['class'], string> = {
[DTypeClass.Bool]: 'bool',
[DTypeClass.Integer]: 'int',
[DTypeClass.Unsigned]: 'uint',
[DTypeClass.Float]: 'float',
};

export function formatNumLikeType(type: NumericLikeType): string {
return `${TYPE_STRINGS[type.class]}${isNumericType(type) ? type.size : ''}`;
}
8 changes: 4 additions & 4 deletions packages/lib/src/vis/heatmap/HeatmapVis.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Domain, NumArray, NumericLikeType } from '@h5web/shared';
import type { Domain, NumArray } from '@h5web/shared';
import {
assertDefined,
formatTooltipVal,
Expand All @@ -15,7 +15,7 @@ import { useAxisDomain, useValueToIndexScale } from '../hooks';
import type { Aspect, AxisParams, VisScaleType } from '../models';
import TooltipMesh from '../shared/TooltipMesh';
import VisCanvas from '../shared/VisCanvas';
import { DEFAULT_DOMAIN, formatNumLikeType } from '../utils';
import { DEFAULT_DOMAIN } from '../utils';
import ColorBar from './ColorBar';
import HeatmapMesh from './HeatmapMesh';
import styles from './HeatmapVis.module.css';
Expand All @@ -30,7 +30,7 @@ interface Props {
aspect?: Aspect;
showGrid?: boolean;
title?: string;
dtype?: NumericLikeType;
dtype?: string;
invertColorMap?: boolean;
abscissaParams?: AxisParams;
ordinateParams?: AxisParams;
Expand Down Expand Up @@ -121,7 +121,7 @@ function HeatmapVis(props: Props) {
{`${ordinateLabel ?? 'y'}=${formatTooltipVal(ordinate)}`}
<div className={styles.tooltipValue}>
<strong>{formatTooltipVal(dataArray.get(yi, xi))}</strong>
{dtype && <em>{` (${formatNumLikeType(dtype)})`}</em>}
{dtype && <em>{` (${dtype})`}</em>}
{alpha && ` (${formatTooltipVal(alpha.array.get(yi, xi))})`}
</div>
</>
Expand Down
13 changes: 4 additions & 9 deletions packages/lib/src/vis/line/LineVis.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import type {
AxisScaleType,
Domain,
NumArray,
NumericLikeType,
} from '@h5web/shared';
import type { AxisScaleType, Domain, NumArray } from '@h5web/shared';
import {
assertDefined,
assertLength,
Expand All @@ -27,7 +22,7 @@ import {
import type { AxisParams } from '../models';
import TooltipMesh from '../shared/TooltipMesh';
import VisCanvas from '../shared/VisCanvas';
import { DEFAULT_DOMAIN, extendDomain, formatNumLikeType } from '../utils';
import { DEFAULT_DOMAIN, extendDomain } from '../utils';
import DataCurve from './DataCurve';
import styles from './LineVis.module.css';
import type { AuxiliaryParams, TooltipData } from './models';
Expand All @@ -42,7 +37,7 @@ interface Props {
abscissaParams?: AxisParams;
ordinateLabel?: string;
title?: string;
dtype?: NumericLikeType;
dtype?: string;
errorsArray?: NdArray<NumArray>;
showErrors?: boolean;
auxiliaries?: AuxiliaryParams[];
Expand Down Expand Up @@ -156,7 +151,7 @@ function LineVis(props: Props) {
<span>
<strong>{formatTooltipVal(value)}</strong>
{error !== undefined && ` ±${formatTooltipErr(error)}`}
{dtype && <em>{` (${formatNumLikeType(dtype)})`}</em>}
{dtype && <em>{` (${dtype})`}</em>}
</span>
</div>

Expand Down
14 changes: 0 additions & 14 deletions packages/lib/src/vis/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import type {
ColorScaleType,
Domain,
NumArray,
NumericLikeType,
} from '@h5web/shared';
import {
DTypeClass,
formatTick,
getBounds,
getValidDomainForScale,
isDefined,
isNumericType,
isTypedArray,
ScaleType,
} from '@h5web/shared';
Expand Down Expand Up @@ -351,13 +348,6 @@ export function getAxisDomain(
: extendedDomain;
}

const TYPE_STRINGS: Record<NumericLikeType['class'], string> = {
[DTypeClass.Bool]: 'bool',
[DTypeClass.Integer]: 'int',
[DTypeClass.Unsigned]: 'uint',
[DTypeClass.Float]: 'float',
};

export const VERTEX_SHADER = `
varying vec2 coords;
Expand All @@ -367,10 +357,6 @@ export const VERTEX_SHADER = `
}
`;

export function formatNumLikeType(type: NumericLikeType): string {
return `${TYPE_STRINGS[type.class]}${isNumericType(type) ? type.size : ''}`;
}

export function getUniforms(
uniforms: Record<string, unknown>,
): Record<string, IUniform> {
Expand Down

0 comments on commit 11f2523

Please sign in to comment.