Skip to content

Commit

Permalink
update CartesianChart with custom interval labeling support
Browse files Browse the repository at this point in the history
  • Loading branch information
KSDaemon committed Sep 24, 2024
1 parent a160b4a commit 5bbe309
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { ChartType, TimeDimensionGranularity } from '@cubejs-client/core';
import {
ChartType,
TimeDimensionGranularity,
granularityFor,
minGranularityForIntervals,
isPredefinedGranularity
} from '@cubejs-client/core';
import { UseCubeQueryResult } from '@cubejs-client/react';
import { Skeleton, Tag, tasty } from '@cube-dev/ui-kit';
import formatDate from 'date-fns/format';
Expand Down Expand Up @@ -113,7 +119,12 @@ function CartesianChart({
return (key as string).split('.').length === 3;
}
) as string;
const granularity = granularityField?.split('.')[2];
let granularity = granularityField?.split('.')[2];

if (!isPredefinedGranularity(granularity)) {
const granularityInfo = resultSet?.loadResponse.results[0].annotation.timeDimensions[granularityField]?.granularity;
granularity = minGranularityForIntervals(granularityInfo.interval, granularityInfo.offset || granularityFor(granularityInfo.origin));
}

const formatDate = useMemo(() => {
if (dateFormat) {
Expand Down

0 comments on commit 5bbe309

Please sign in to comment.