diff --git a/packages/app/src/vis-packs/core/matrix/utils.ts b/packages/app/src/vis-packs/core/matrix/utils.ts index 2b0c54b97..ac7634e58 100644 --- a/packages/app/src/vis-packs/core/matrix/utils.ts +++ b/packages/app/src/vis-packs/core/matrix/utils.ts @@ -3,8 +3,8 @@ import { isBoolType, isComplexType, isEnumType, + isFloatType, isIntegerType, - isNumericType, } from '@h5web/shared/guards'; import { type ComplexType, @@ -22,7 +22,18 @@ import { } from '@h5web/shared/vis-utils'; import { format } from 'd3-format'; -export function createNumericFormatter( +export function createIntegerFormatter( + notation: Notation, +): (val: ScalarValue) => string { + if (notation === Notation.Scientific) { + const formatter = format('.3e'); + return (val) => formatter(Number(val)); + } + + return (val) => val.toString(); +} + +export function createFloatFormatter( notation: Notation, ): (val: number) => string { switch (notation) { @@ -35,19 +46,6 @@ export function createNumericFormatter( } } -export function createBigIntFormatter( - notation: Notation, -): (val: ScalarValue) => string { - switch (notation) { - case Notation.Scientific: { - const formatter = createNumericFormatter(notation); - return (val) => formatter(Number(val)); - } - default: - return (val) => val.toString(); - } -} - export function createMatrixComplexFormatter( notation: Notation, ): (val: ScalarValue) => string { @@ -68,12 +66,12 @@ export function getFormatter( type: PrintableType, notation: Notation, ): ValueFormatter { - if (isIntegerType(type) && type.size === 64) { - return createBigIntFormatter(notation); + if (isIntegerType(type)) { + return createIntegerFormatter(notation); } - if (isNumericType(type)) { - return createNumericFormatter(notation); + if (isFloatType(type)) { + return createFloatFormatter(notation); } if (isBoolType(type)) {