From 11f2523c00b53f0673755df10eca27d14d7bbd82 Mon Sep 17 00:00:00 2001 From: Axel Bocciarelli Date: Mon, 16 Oct 2023 15:33:14 +0200 Subject: [PATCH] Pass `dtype` as string to visualization components --- .../vis-packs/core/heatmap/MappedHeatmapVis.tsx | 4 ++-- .../app/src/vis-packs/core/line/MappedLineVis.tsx | 3 ++- packages/app/src/vis-packs/core/utils.ts | 13 ++++++++++++- packages/lib/src/vis/heatmap/HeatmapVis.tsx | 8 ++++---- packages/lib/src/vis/line/LineVis.tsx | 13 ++++--------- packages/lib/src/vis/utils.ts | 14 -------------- 6 files changed, 24 insertions(+), 31 deletions(-) diff --git a/packages/app/src/vis-packs/core/heatmap/MappedHeatmapVis.tsx b/packages/app/src/vis-packs/core/heatmap/MappedHeatmapVis.tsx index 01198d6ff..e94141bff 100644 --- a/packages/app/src/vis-packs/core/heatmap/MappedHeatmapVis.tsx +++ b/packages/app/src/vis-packs/core/heatmap/MappedHeatmapVis.tsx @@ -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'; @@ -90,7 +90,7 @@ function MappedHeatmapVis(props: Props) { ({ diff --git a/packages/app/src/vis-packs/core/utils.ts b/packages/app/src/vis-packs/core/utils.ts index e9da91795..d57b41989 100644 --- a/packages/app/src/vis-packs/core/utils.ts +++ b/packages/app/src/vis-packs/core/utils.ts @@ -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'; @@ -97,3 +97,14 @@ export function toNumArray(arr: ArrayValue): NumArray { return arr as NumArray; } + +const TYPE_STRINGS: Record = { + [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 : ''}`; +} diff --git a/packages/lib/src/vis/heatmap/HeatmapVis.tsx b/packages/lib/src/vis/heatmap/HeatmapVis.tsx index a6f41f37d..cd5b4ca8c 100644 --- a/packages/lib/src/vis/heatmap/HeatmapVis.tsx +++ b/packages/lib/src/vis/heatmap/HeatmapVis.tsx @@ -1,4 +1,4 @@ -import type { Domain, NumArray, NumericLikeType } from '@h5web/shared'; +import type { Domain, NumArray } from '@h5web/shared'; import { assertDefined, formatTooltipVal, @@ -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'; @@ -30,7 +30,7 @@ interface Props { aspect?: Aspect; showGrid?: boolean; title?: string; - dtype?: NumericLikeType; + dtype?: string; invertColorMap?: boolean; abscissaParams?: AxisParams; ordinateParams?: AxisParams; @@ -121,7 +121,7 @@ function HeatmapVis(props: Props) { {`${ordinateLabel ?? 'y'}=${formatTooltipVal(ordinate)}`}
{formatTooltipVal(dataArray.get(yi, xi))} - {dtype && {` (${formatNumLikeType(dtype)})`}} + {dtype && {` (${dtype})`}} {alpha && ` (${formatTooltipVal(alpha.array.get(yi, xi))})`}
diff --git a/packages/lib/src/vis/line/LineVis.tsx b/packages/lib/src/vis/line/LineVis.tsx index 1f1a763ca..f75410a59 100644 --- a/packages/lib/src/vis/line/LineVis.tsx +++ b/packages/lib/src/vis/line/LineVis.tsx @@ -1,9 +1,4 @@ -import type { - AxisScaleType, - Domain, - NumArray, - NumericLikeType, -} from '@h5web/shared'; +import type { AxisScaleType, Domain, NumArray } from '@h5web/shared'; import { assertDefined, assertLength, @@ -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'; @@ -42,7 +37,7 @@ interface Props { abscissaParams?: AxisParams; ordinateLabel?: string; title?: string; - dtype?: NumericLikeType; + dtype?: string; errorsArray?: NdArray; showErrors?: boolean; auxiliaries?: AuxiliaryParams[]; @@ -156,7 +151,7 @@ function LineVis(props: Props) { {formatTooltipVal(value)} {error !== undefined && ` ±${formatTooltipErr(error)}`} - {dtype && {` (${formatNumLikeType(dtype)})`}} + {dtype && {` (${dtype})`}} diff --git a/packages/lib/src/vis/utils.ts b/packages/lib/src/vis/utils.ts index cae845fd7..1779b419c 100644 --- a/packages/lib/src/vis/utils.ts +++ b/packages/lib/src/vis/utils.ts @@ -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'; @@ -351,13 +348,6 @@ export function getAxisDomain( : extendedDomain; } -const TYPE_STRINGS: Record = { - [DTypeClass.Bool]: 'bool', - [DTypeClass.Integer]: 'int', - [DTypeClass.Unsigned]: 'uint', - [DTypeClass.Float]: 'float', -}; - export const VERTEX_SHADER = ` varying vec2 coords; @@ -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, ): Record {