File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { ScaleType , VisCanvas } from '@h5web/lib' ;
2
2
import { type Meta , type StoryFn , type StoryObj } from '@storybook/react' ;
3
+ import { format } from 'd3-format' ;
3
4
4
5
import FillHeight from './decorators/FillHeight' ;
5
6
@@ -34,6 +35,23 @@ export const NiceDomains = {
34
35
} ,
35
36
} satisfies Story ;
36
37
38
+ export const TickFormatters = {
39
+ args : {
40
+ abscissaConfig : {
41
+ visDomain : [ - 1.2 , 2.8 ] ,
42
+ showGrid : true ,
43
+ formatTick : ( val ) => {
44
+ return Math . round ( val ) === val ? val . toString ( ) : val . toFixed ( 3 ) ;
45
+ } ,
46
+ } ,
47
+ ordinateConfig : {
48
+ visDomain : [ 50 , 100 ] ,
49
+ showGrid : true ,
50
+ formatTick : format ( '.2e' ) ,
51
+ } ,
52
+ } ,
53
+ } satisfies Story ;
54
+
37
55
export const LogScales = {
38
56
args : {
39
57
abscissaConfig : {
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ export interface AxisConfig {
42
42
label ?: string ;
43
43
flip ?: boolean ;
44
44
nice ?: boolean ;
45
+ formatTick ?: ( val : number ) => string ;
45
46
}
46
47
47
48
export type VisScaleType = ColorScaleType | [ ScaleType . Gamma , number ] ;
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ function Axis(props: Props) {
49
49
showGrid,
50
50
label,
51
51
nice = false ,
52
+ formatTick,
52
53
} = config ;
53
54
// Restrain ticks scales to visible domains
54
55
const scale = createScale ( scaleType , {
@@ -76,7 +77,9 @@ function Axis(props: Props) {
76
77
>
77
78
< AxisComponent
78
79
scale = { scale }
79
- tickFormat = { getTickFormatter ( domain , axisLength , scaleType ) }
80
+ tickFormat = {
81
+ formatTick || getTickFormatter ( domain , axisLength , scaleType )
82
+ }
80
83
label = { label }
81
84
labelOffset = { offset - ( isAbscissa ? 32 : 36 ) }
82
85
hideAxisLine = { showGrid }
You can’t perform that action at this time.
0 commit comments