File tree Expand file tree Collapse file tree
src/Shared/Components/Charts Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,22 +69,26 @@ export type TypeAndDatasetsType =
6969 */
7070 datasets : SimpleDatasetForPie
7171 onChartClick ?: OnChartClickHandler
72+ yScaleTickFormat ?: never
7273 } & Never < XYAxisMax > )
7374 | ( {
7475 type : 'line'
7576 datasets : SimpleDatasetForLineAndArea [ ]
7677 onChartClick ?: never
78+ yScaleTickFormat ?: ( value : number ) => string
7779 } & XYAxisMax )
7880 | ( {
7981 type : 'area'
8082 datasets : SimpleDatasetForLineAndArea
8183 /* onChartClick is not applicable for area charts */
8284 onChartClick ?: never
85+ yScaleTickFormat ?: ( value : number ) => string
8386 } & XYAxisMax )
8487 | ( {
8588 type : Exclude < ChartType , 'pie' | 'line' | 'area' >
8689 datasets : SimpleDataset [ ]
8790 onChartClick ?: OnChartClickHandler
91+ yScaleTickFormat ?: ( value : number ) => string
8892 } & XYAxisMax )
8993
9094export type ChartProps = {
Original file line number Diff line number Diff line change @@ -181,6 +181,7 @@ export const getDefaultOptions = ({
181181 yAxisMax,
182182 xScaleTitle,
183183 yScaleTitle,
184+ yScaleTickFormat,
184185 } = chartProps
185186 const baseOptions : ChartOptions = {
186187 responsive : true ,
@@ -244,16 +245,28 @@ export const getDefaultOptions = ({
244245 } ,
245246 } satisfies ScaleOptions < 'linear' >
246247
248+ const ticksWithCallback = {
249+ ...commonScaleConfig . ticks ,
250+ callback : ( value ) => yScaleTickFormat ( Number ( value ) ) ,
251+ } satisfies ScaleOptions < 'linear' > [ 'ticks' ]
252+
247253 const commonXScaleConfig = {
248254 ...commonScaleConfig ,
249255 max : xAxisMax ,
250256 title : getScaleTickTitleConfig ( xScaleTitle , appTheme ) ,
257+ ...( typeof yScaleTickFormat === 'function' && type === 'stackedBarHorizontal'
258+ ? { ticks : ticksWithCallback }
259+ : { } ) ,
251260 } satisfies ScaleOptions < 'linear' >
252261
253262 const commonYScaleConfig = {
254263 ...commonScaleConfig ,
255264 max : yAxisMax ,
256265 title : getScaleTickTitleConfig ( yScaleTitle , appTheme ) ,
266+ // for stackedBarHorizon
267+ ...( typeof yScaleTickFormat === 'function' && type !== 'stackedBarHorizontal'
268+ ? { ticks : ticksWithCallback }
269+ : { } ) ,
257270 } satisfies ScaleOptions < 'linear' >
258271
259272 switch ( type ) {
You can’t perform that action at this time.
0 commit comments