Skip to content

Commit

Permalink
Upgrade h5wasm and improve boolean and vlen support
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Aug 7, 2024
1 parent 0d57ca9 commit 8dd7e5b
Show file tree
Hide file tree
Showing 16 changed files with 309 additions and 112 deletions.
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
"wait-on": "7.2.0"
},
"pnpm": {
"packageExtensions": {
"@typescript-eslint/eslint-plugin": {
"dependencies": {
"typescript": "5.0.3"
}
}
},
"peerDependencyRules": {
"allowedVersions": {
"@phenomnomnominal/tsquery>typescript": "5.x",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,37 @@ exports[`test file matches snapshot 1`] = `
1,
],
},
{
"name": "vlen_float32_1D",
"rawType": {
"base": {
"class": 1,
"dtype": "<f4",
"order": 0,
"size": 4,
},
"class": 9,
"dtype": "|O",
"size": 16,
},
"shape": [
2,
],
"type": {
"base": {
"class": "Float",
"endianness": "little-endian",
"size": 32,
},
"class": "Array (variable length)",
},
"value": [
[]
[
0,
],
],
},
{
"name": "vlen_int64_1D",
"rawType": {
Expand Down
15 changes: 13 additions & 2 deletions packages/app/src/vis-packs/core/matrix/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Notation } from '@h5web/lib';
import { isComplexType, isEnumType, isNumericType } from '@h5web/shared/guards';
import {
isBoolType,
isComplexType,
isEnumType,
isNumericType,
} from '@h5web/shared/guards';
import type {
BooleanType,
ComplexType,
NumericType,
PrintableCompoundType,
Expand All @@ -11,6 +17,7 @@ import type { ValueFormatter } from '@h5web/shared/vis-models';
import {
createComplexFormatter,
createEnumFormatter,
formatBool,
} from '@h5web/shared/vis-utils';
import { format } from 'd3-format';

Expand Down Expand Up @@ -50,11 +57,15 @@ export function getFormatter(
return createNumericFormatter(notation);
}

if (isBoolType(type)) {
return formatBool as ValueFormatter<BooleanType>;
}

if (isEnumType(type)) {
return createEnumFormatter(type.mapping);
}

return (val) => (val as string | boolean).toString();
return (val) => (val as string).toString(); // call `toString()` for safety, in case type cast is wrong
}

export function getCellWidth(
Expand Down
10 changes: 8 additions & 2 deletions packages/app/src/vis-packs/core/scalar/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { hasComplexType, hasEnumType } from '@h5web/shared/guards';
import { hasBoolType, hasComplexType, hasEnumType } from '@h5web/shared/guards';
import type {
ArrayShape,
BooleanType,
Dataset,
PrintableType,
} from '@h5web/shared/hdf5-models';
import type { ValueFormatter } from '@h5web/shared/vis-models';
import {
createEnumFormatter,
formatBool,
formatScalarComplex,
} from '@h5web/shared/vis-utils';

Expand All @@ -17,9 +19,13 @@ export function getFormatter(
return formatScalarComplex;
}

if (hasBoolType(dataset)) {
return formatBool as ValueFormatter<BooleanType>;
}

if (hasEnumType(dataset)) {
return createEnumFormatter(dataset.type.mapping);
}

return (val) => (val as number | string | boolean).toString();
return (val) => (val as number | string).toString();
}
2 changes: 1 addition & 1 deletion packages/h5wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"dependencies": {
"comlink": "4.4.1",
"h5wasm": "0.7.5",
"h5wasm": "0.7.6",
"nanoid": "5.0.7"
},
"devDependencies": {
Expand Down
155 changes: 133 additions & 22 deletions packages/h5wasm/src/__snapshots__/h5wasm-api.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ exports[`test file matches snapshot 1`] = `
},
"value": [
[
true,
1,
[
1,
2,
Expand Down Expand Up @@ -1680,6 +1680,13 @@ exports[`test file matches snapshot 1`] = `
"size": 8,
"type": 9,
"vlen": false,
"vlen_type": {
"littleEndian": true,
"signed": false,
"size": 8,
"type": 0,
"vlen": false,
},
},
],
"nmembers": 2,
Expand Down Expand Up @@ -1710,7 +1717,9 @@ exports[`test file matches snapshot 1`] = `
},
"vlen": {
"base": {
"class": "Unknown",
"class": "Integer (unsigned)",
"endianness": "little-endian",
"size": 64,
},
"class": "Array (variable length)",
},
Expand All @@ -1722,21 +1731,30 @@ exports[`test file matches snapshot 1`] = `
0,
1,
],
"Uint8Array (unstable)",
[
0,
],
],
[
[
2,
3,
],
"Uint8Array (unstable)",
[
0,
1,
],
],
[
[
4,
5,
],
"Uint8Array (unstable)",
[
0,
1,
2,
],
],
],
},
Expand Down Expand Up @@ -1820,7 +1838,7 @@ exports[`test file matches snapshot 1`] = `
"type": {
"class": "Boolean",
},
"value": false,
"value": 0,
},
{
"name": "bool_true_scalar",
Expand All @@ -1844,7 +1862,7 @@ exports[`test file matches snapshot 1`] = `
"type": {
"class": "Boolean",
},
"value": true,
"value": 1,
},
{
"name": "bool_2D",
Expand All @@ -1871,15 +1889,15 @@ exports[`test file matches snapshot 1`] = `
"type": {
"class": "Boolean",
},
"value": [
true,
false,
true,
true,
false,
false,
true,
false,
"value": Int8Array [
1,
0,
1,
1,
0,
0,
1,
0,
],
},
{
Expand Down Expand Up @@ -2064,15 +2082,62 @@ exports[`test file matches snapshot 1`] = `
"total_size": 1,
"type": 9,
"vlen": false,
"vlen_type": {
"littleEndian": true,
"signed": true,
"size": 1,
"type": 0,
"vlen": false,
},
},
"shape": [],
"type": {
"base": {
"class": "Unknown",
"class": "Integer",
"endianness": "little-endian",
"size": 8,
},
"class": "Array (variable length)",
},
"value": "Uint8Array (unstable)",
"value": Int8Array [
0,
1,
],
},
{
"name": "vlen_float32_1D",
"rawType": {
"littleEndian": true,
"signed": false,
"size": 8,
"total_size": 3,
"type": 9,
"vlen": false,
"vlen_type": {
"littleEndian": true,
"signed": false,
"size": 4,
"type": 1,
"vlen": false,
},
},
"shape": [
2,
],
"type": {
"base": {
"class": "Float",
"endianness": "little-endian",
"size": 32,
},
"class": "Array (variable length)",
},
"value": [
Float32Array []
Float32Array [
0,
],
],
},
{
"name": "vlen_int64_1D",
Expand All @@ -2083,17 +2148,39 @@ exports[`test file matches snapshot 1`] = `
"total_size": 3,
"type": 9,
"vlen": false,
"vlen_type": {
"littleEndian": true,
"signed": true,
"size": 8,
"type": 0,
"vlen": false,
},
},
"shape": [
3,
],
"type": {
"base": {
"class": "Unknown",
"class": "Integer",
"endianness": "little-endian",
"size": 64,
},
"class": "Array (variable length)",
},
"value": "Uint8Array (unstable)",
"value": [
[
0,
],
[
0,
1,
],
[
0,
1,
2,
],
],
},
{
"name": "vlen_utf8_1D",
Expand All @@ -2104,17 +2191,41 @@ exports[`test file matches snapshot 1`] = `
"total_size": 3,
"type": 9,
"vlen": false,
"vlen_type": {
"cset": 1,
"littleEndian": true,
"signed": false,
"size": 4,
"strpad": 0,
"type": 3,
"vlen": true,
},
},
"shape": [
3,
],
"type": {
"base": {
"class": "Unknown",
"charSet": "UTF-8",
"class": "String",
"strPad": "null-terminated",
},
"class": "Array (variable length)",
},
"value": "Uint8Array (unstable)",
"value": [
[
"a",
],
[
"a",
"bc",
],
[
"a",
"bc",
"def",
],
],
},
]
`;
Loading

0 comments on commit 8dd7e5b

Please sign in to comment.