1
1
import * as React from 'react' ;
2
- import { D3Scale } from '../models/axis' ;
2
+ import { AxisConfig , D3Scale } from '../models/axis' ;
3
3
import { isBandScale } from '../internals/isBandScale' ;
4
4
5
5
export interface TickParams {
@@ -80,7 +80,7 @@ export type TickItemType = {
80
80
export function useTicks (
81
81
options : {
82
82
scale : D3Scale ;
83
- valueFormatter ?: ( value : any ) => string ;
83
+ valueFormatter ?: AxisConfig [ 'valueFormatter' ] ;
84
84
} & Pick < TickParams , 'tickNumber' | 'tickInterval' | 'tickPlacement' | 'tickLabelPlacement' > ,
85
85
) : TickItemType [ ] {
86
86
const {
@@ -102,7 +102,7 @@ export function useTicks(
102
102
return [
103
103
...domain . map ( ( value ) => ( {
104
104
value,
105
- formattedValue : valueFormatter ?.( value ) ?? `${ value } ` ,
105
+ formattedValue : valueFormatter ?.( value , { location : 'tick' } ) ?? `${ value } ` ,
106
106
offset :
107
107
scale ( value ) ! -
108
108
( scale . step ( ) - scale . bandwidth ( ) ) / 2 +
@@ -133,7 +133,7 @@ export function useTicks(
133
133
134
134
return filteredDomain . map ( ( value ) => ( {
135
135
value,
136
- formattedValue : valueFormatter ?.( value ) ?? `${ value } ` ,
136
+ formattedValue : valueFormatter ?.( value , { location : 'tick' } ) ?? `${ value } ` ,
137
137
offset : scale ( value ) ! ,
138
138
labelOffset : 0 ,
139
139
} ) ) ;
@@ -142,7 +142,8 @@ export function useTicks(
142
142
const ticks = typeof tickInterval === 'object' ? tickInterval : scale . ticks ( tickNumber ) ;
143
143
return ticks . map ( ( value : any ) => ( {
144
144
value,
145
- formattedValue : valueFormatter ?.( value ) ?? scale . tickFormat ( tickNumber ) ( value ) ,
145
+ formattedValue :
146
+ valueFormatter ?.( value , { location : 'tick' } ) ?? scale . tickFormat ( tickNumber ) ( value ) ,
146
147
offset : scale ( value ) ,
147
148
labelOffset : 0 ,
148
149
} ) ) ;
0 commit comments