Update useXAxis.ts

This commit is contained in:
Nate Kelley 2025-02-06 12:46:41 -07:00
parent a519a772ee
commit f1381bdf50
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
1 changed files with 20 additions and 2 deletions

View File

@ -4,7 +4,8 @@ import {
ChartType,
BusterChartProps,
IColumnLabelFormat,
ComboChartAxis
ComboChartAxis,
XAxisConfig
} from '@/components/charts/interfaces';
import { useMemoizedFn } from 'ahooks';
import { useMemo } from 'react';
@ -145,6 +146,14 @@ export const useXAxis = ({
};
}, [xAxisLabelRotation]);
const timeUnit = useMemo(() => {
if (type === 'time' && xAxisTimeInterval) {
const isValidTimeUnit = arrayOfValidTimeUnits.includes(xAxisTimeInterval);
return isValidTimeUnit ? xAxisTimeInterval : false;
}
return false;
}, [type, xAxisTimeInterval]);
const memoizedXAxisOptions: DeepPartial<ScaleChartOptions<'bar'>['scales']['x']> | undefined =
useMemo(() => {
if (isPieChart) return undefined;
@ -165,7 +174,7 @@ export const useXAxis = ({
autoSkipPadding: 3,
align: 'center',
time: {
unit: xAxisTimeInterval
unit: timeUnit
},
source: 'auto'
},
@ -184,9 +193,18 @@ export const useXAxis = ({
stacked,
type,
grid,
timeUnit,
rotation,
tickCallback
]);
return memoizedXAxisOptions;
};
const arrayOfValidTimeUnits: XAxisConfig['xAxisTimeInterval'][] = [
'day',
'week',
'month',
'quarter',
'year'
];