-
Notifications
You must be signed in to change notification settings - Fork 29
Assert values of enum datasets and other tweaks #1743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0c1d17b
fdc7328
b40728a
6ccd4ea
de6a4bd
897720f
8f69365
e6ce7a2
79a5e03
fc10e8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,12 @@ import { | |
| isNumericType, | ||
| } from '@h5web/shared/guards'; | ||
| import { | ||
| type BooleanType, | ||
| type ComplexType, | ||
| type CompoundType, | ||
| DTypeClass, | ||
| type NumericType, | ||
| type PrintableType, | ||
| type ScalarValue, | ||
| } from '@h5web/shared/hdf5-models'; | ||
| import { type ValueFormatter } from '@h5web/shared/vis-models'; | ||
| import { | ||
|
|
@@ -23,7 +23,7 @@ import { format } from 'd3-format'; | |
|
|
||
| export function createNumericFormatter( | ||
| notation: Notation, | ||
| ): ValueFormatter<NumericType> { | ||
| ): (val: ScalarValue<NumericType>) => string { | ||
loichuder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| switch (notation) { | ||
| case Notation.FixedPoint: | ||
| return format('.3f'); | ||
|
|
@@ -36,7 +36,7 @@ export function createNumericFormatter( | |
|
|
||
| export function createMatrixComplexFormatter( | ||
| notation: Notation, | ||
| ): ValueFormatter<ComplexType> { | ||
| ): (val: ScalarValue<ComplexType>) => string { | ||
| const formatStr = | ||
| notation === Notation.FixedPoint | ||
| ? '.2f' | ||
|
|
@@ -48,24 +48,29 @@ export function createMatrixComplexFormatter( | |
| export function getFormatter( | ||
| type: PrintableType, | ||
| notation: Notation, | ||
| ): ValueFormatter<PrintableType> { | ||
| if (isComplexType(type)) { | ||
| return createMatrixComplexFormatter(notation); | ||
| } | ||
| ): (val: ScalarValue<PrintableType>) => string; // override distributivity of `ValueFormatter` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This simplifies typing the formatter factories, like However, the consumers of
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What a can of worms 😅 |
||
|
|
||
| export function getFormatter( | ||
| type: PrintableType, | ||
| notation: Notation, | ||
| ): ValueFormatter<PrintableType> { | ||
| if (isNumericType(type)) { | ||
| return createNumericFormatter(notation); | ||
| } | ||
|
|
||
| if (isBoolType(type)) { | ||
| return formatBool as ValueFormatter<BooleanType>; | ||
| return formatBool; | ||
| } | ||
|
|
||
| if (isEnumType(type)) { | ||
| return createEnumFormatter(type.mapping); | ||
| } | ||
|
|
||
| return (val) => (val as string).toString(); // call `toString()` for safety, in case type cast is wrong | ||
| if (isComplexType(type)) { | ||
| return createMatrixComplexFormatter(notation); | ||
| } | ||
|
|
||
| return (val: string) => val.toString(); // call `toString()` for safety, in case type cast is wrong | ||
| } | ||
|
|
||
| export function getCellWidth( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.