Skip to content

Commit 5bbe309

Browse files
committed
update CartesianChart with custom interval labeling support
1 parent a160b4a commit 5bbe309

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/cubejs-playground/src/QueryBuilderV2/components/ChartRenderer.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { ChartType, TimeDimensionGranularity } from '@cubejs-client/core';
1+
import {
2+
ChartType,
3+
TimeDimensionGranularity,
4+
granularityFor,
5+
minGranularityForIntervals,
6+
isPredefinedGranularity
7+
} from '@cubejs-client/core';
28
import { UseCubeQueryResult } from '@cubejs-client/react';
39
import { Skeleton, Tag, tasty } from '@cube-dev/ui-kit';
410
import formatDate from 'date-fns/format';
@@ -113,7 +119,12 @@ function CartesianChart({
113119
return (key as string).split('.').length === 3;
114120
}
115121
) as string;
116-
const granularity = granularityField?.split('.')[2];
122+
let granularity = granularityField?.split('.')[2];
123+
124+
if (!isPredefinedGranularity(granularity)) {
125+
const granularityInfo = resultSet?.loadResponse.results[0].annotation.timeDimensions[granularityField]?.granularity;
126+
granularity = minGranularityForIntervals(granularityInfo.interval, granularityInfo.offset || granularityFor(granularityInfo.origin));
127+
}
117128

118129
const formatDate = useMemo(() => {
119130
if (dateFormat) {

0 commit comments

Comments
 (0)