3
3
isBoolType ,
4
4
isComplexType ,
5
5
isEnumType ,
6
+ isFloatType ,
6
7
isIntegerType ,
7
- isNumericType ,
8
8
} from '@h5web/shared/guards' ;
9
9
import {
10
10
type ComplexType ,
@@ -22,7 +22,18 @@ import {
22
22
} from '@h5web/shared/vis-utils' ;
23
23
import { format } from 'd3-format' ;
24
24
25
- export function createNumericFormatter (
25
+ export function createIntegerFormatter (
26
+ notation : Notation ,
27
+ ) : ( val : ScalarValue < NumericType > ) => string {
28
+ if ( notation === Notation . Scientific ) {
29
+ const formatter = format ( '.3e' ) ;
30
+ return ( val ) => formatter ( Number ( val ) ) ;
31
+ }
32
+
33
+ return ( val ) => val . toString ( ) ;
34
+ }
35
+
36
+ export function createFloatFormatter (
26
37
notation : Notation ,
27
38
) : ( val : number ) => string {
28
39
switch ( notation ) {
@@ -35,19 +46,6 @@ export function createNumericFormatter(
35
46
}
36
47
}
37
48
38
- export function createBigIntFormatter (
39
- notation : Notation ,
40
- ) : ( val : ScalarValue < NumericType > ) => string {
41
- switch ( notation ) {
42
- case Notation . Scientific : {
43
- const formatter = createNumericFormatter ( notation ) ;
44
- return ( val ) => formatter ( Number ( val ) ) ;
45
- }
46
- default :
47
- return ( val ) => val . toString ( ) ;
48
- }
49
- }
50
-
51
49
export function createMatrixComplexFormatter (
52
50
notation : Notation ,
53
51
) : ( val : ScalarValue < ComplexType > ) => string {
@@ -68,12 +66,12 @@ export function getFormatter(
68
66
type : PrintableType ,
69
67
notation : Notation ,
70
68
) : ValueFormatter < PrintableType > {
71
- if ( isIntegerType ( type ) && type . size === 64 ) {
72
- return createBigIntFormatter ( notation ) ;
69
+ if ( isIntegerType ( type ) ) {
70
+ return createIntegerFormatter ( notation ) ;
73
71
}
74
72
75
- if ( isNumericType ( type ) ) {
76
- return createNumericFormatter ( notation ) ;
73
+ if ( isFloatType ( type ) ) {
74
+ return createFloatFormatter ( notation ) ;
77
75
}
78
76
79
77
if ( isBoolType ( type ) ) {
0 commit comments