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 11import { ScaleType , VisCanvas } from '@h5web/lib' ;
22import { type Meta , type StoryFn , type StoryObj } from '@storybook/react' ;
3+ import { format } from 'd3-format' ;
34
45import FillHeight from './decorators/FillHeight' ;
56
@@ -34,6 +35,23 @@ export const NiceDomains = {
3435 } ,
3536} satisfies Story ;
3637
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+
3755export const LogScales = {
3856 args : {
3957 abscissaConfig : {
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ export interface AxisConfig {
4242 label ?: string ;
4343 flip ?: boolean ;
4444 nice ?: boolean ;
45+ formatTick ?: ( val : number ) => string ;
4546}
4647
4748export type VisScaleType = ColorScaleType | [ ScaleType . Gamma , number ] ;
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ function Axis(props: Props) {
4949 showGrid,
5050 label,
5151 nice = false ,
52+ formatTick,
5253 } = config ;
5354 // Restrain ticks scales to visible domains
5455 const scale = createScale ( scaleType , {
@@ -76,7 +77,9 @@ function Axis(props: Props) {
7677 >
7778 < AxisComponent
7879 scale = { scale }
79- tickFormat = { getTickFormatter ( domain , axisLength , scaleType ) }
80+ tickFormat = {
81+ formatTick || getTickFormatter ( domain , axisLength , scaleType )
82+ }
8083 label = { label }
8184 labelOffset = { offset - ( isAbscissa ? 32 : 36 ) }
8285 hideAxisLine = { showGrid }
You can’t perform that action at this time.
0 commit comments