@@ -190,7 +190,13 @@ export const getDefaultOptions = ({
190190 xScaleTitle,
191191 yScaleTitle,
192192 yScaleTickFormat,
193+ xScaleTickFormat,
194+ xAxisLabels,
195+ tooltipConfig,
193196 } = chartProps
197+
198+ const { datasetValueFormatter } = tooltipConfig ?? { }
199+
194200 const baseOptions : ChartOptions = {
195201 responsive : true ,
196202 devicePixelRatio : 3 ,
@@ -211,6 +217,16 @@ export const getDefaultOptions = ({
211217 enabled : false ,
212218 position : 'nearest' ,
213219 external : externalTooltipHandler ,
220+ ...( datasetValueFormatter
221+ ? {
222+ callbacks : {
223+ label ( { dataset, raw } ) {
224+ // only number values are expected in raw as input in our types for yAxisValues is number[]
225+ return `${ dataset . label } : ${ datasetValueFormatter ( raw as number ) } `
226+ } ,
227+ } ,
228+ }
229+ : { } ) ,
214230 } ,
215231 } ,
216232 elements : {
@@ -253,28 +269,42 @@ export const getDefaultOptions = ({
253269 } ,
254270 } satisfies ScaleOptions < 'linear' >
255271
256- const ticksWithCallback = {
257- ...commonScaleConfig . ticks ,
258- callback : ( value ) => yScaleTickFormat ( Number ( value ) ) ,
259- } satisfies ScaleOptions < 'linear' > [ 'ticks' ]
260-
261272 const commonXScaleConfig = {
262273 ...commonScaleConfig ,
263274 max : xAxisMax ,
264275 title : getScaleTickTitleConfig ( xScaleTitle , appTheme ) ,
265- ...( typeof yScaleTickFormat === 'function' && type === 'stackedBarHorizontal'
266- ? { ticks : ticksWithCallback }
267- : { } ) ,
276+ ticks : {
277+ ...commonScaleConfig . ticks ,
278+ ...( ( type !== 'stackedBarHorizontal' && typeof xScaleTickFormat === 'function' ) ||
279+ ( type === 'stackedBarHorizontal' && typeof yScaleTickFormat === 'function' )
280+ ? {
281+ callback :
282+ type === 'stackedBarHorizontal'
283+ ? ( value , index ) => yScaleTickFormat ( Number ( value ) , index )
284+ : ( _ , index ) => xScaleTickFormat ( xAxisLabels [ index ] , index ) ,
285+ }
286+ : { } ) ,
287+ autoSkip : false ,
288+ } ,
268289 } satisfies ScaleOptions < 'linear' >
269290
270291 const commonYScaleConfig = {
271292 ...commonScaleConfig ,
272293 max : yAxisMax ,
273294 title : getScaleTickTitleConfig ( yScaleTitle , appTheme ) ,
274295 // for stackedBarHorizon
275- ...( typeof yScaleTickFormat === 'function' && type !== 'stackedBarHorizontal'
276- ? { ticks : ticksWithCallback }
277- : { } ) ,
296+ ticks : {
297+ ...commonScaleConfig . ticks ,
298+ ...( ( type === 'stackedBarHorizontal' && typeof xScaleTickFormat === 'function' ) ||
299+ ( type !== 'stackedBarHorizontal' && typeof yScaleTickFormat === 'function' )
300+ ? {
301+ callback :
302+ type !== 'stackedBarHorizontal'
303+ ? ( value , index ) => yScaleTickFormat ( Number ( value ) , index )
304+ : ( _ , index ) => xScaleTickFormat ( xAxisLabels [ index ] , index ) ,
305+ }
306+ : { } ) ,
307+ } ,
278308 } satisfies ScaleOptions < 'linear' >
279309
280310 switch ( type ) {
@@ -555,7 +585,7 @@ export const buildChartTooltipFromContext = ({
555585 < div className = "flexbox-col dc__gap-2" >
556586 { titleLines . map ( ( titleLine , index ) => (
557587 // eslint-disable-next-line react/no-array-index-key
558- < h6 key = { index } className = "m-0 fs-12 fw-6 lh-20 dc__truncate " >
588+ < h6 key = { index } className = "m-0 fs-12 fw-6 lh-20 dc__word-break-all " >
559589 { titleLine }
560590 </ h6 >
561591 ) ) }
0 commit comments