@@ -10,6 +10,10 @@ import {
1010 ResponseJSON ,
1111} from '@hyperdx/common-utils/dist/clickhouse' ;
1212import { isMetricChartConfig } from '@hyperdx/common-utils/dist/core/renderChartConfig' ;
13+ import {
14+ convertDateRangeToGranularityString ,
15+ Granularity ,
16+ } from '@hyperdx/common-utils/dist/core/utils' ;
1317import {
1418 AggregateFunction as AggFnV2 ,
1519 ChartConfigWithDateRange ,
@@ -98,24 +102,6 @@ export const getMetricAggFns = (
98102 ] ;
99103} ;
100104
101- export enum Granularity {
102- FifteenSecond = '15 second' ,
103- ThirtySecond = '30 second' ,
104- OneMinute = '1 minute' ,
105- FiveMinute = '5 minute' ,
106- TenMinute = '10 minute' ,
107- FifteenMinute = '15 minute' ,
108- ThirtyMinute = '30 minute' ,
109- OneHour = '1 hour' ,
110- TwoHour = '2 hour' ,
111- SixHour = '6 hour' ,
112- TwelveHour = '12 hour' ,
113- OneDay = '1 day' ,
114- TwoDay = '2 day' ,
115- SevenDay = '7 day' ,
116- ThirtyDay = '30 day' ,
117- }
118-
119105export const DEFAULT_CHART_CONFIG : Omit <
120106 SavedChartConfig ,
121107 'source' | 'connection'
@@ -141,7 +127,7 @@ export const isGranularity = (value: string): value is Granularity => {
141127
142128export function useTimeChartSettings ( chartConfig : ChartConfigWithDateRange ) {
143129 const autoGranularity = useMemo ( ( ) => {
144- return convertDateRangeToGranularityString ( chartConfig . dateRange , 80 ) ;
130+ return convertDateRangeToGranularityString ( chartConfig . dateRange ) ;
145131 } , [ chartConfig . dateRange ] ) ;
146132
147133 const granularity =
@@ -233,50 +219,6 @@ export function TableToggle({
233219 ) ;
234220}
235221
236- export function convertDateRangeToGranularityString (
237- dateRange : [ Date , Date ] ,
238- maxNumBuckets : number ,
239- ) : Granularity {
240- const start = dateRange [ 0 ] . getTime ( ) ;
241- const end = dateRange [ 1 ] . getTime ( ) ;
242- const diffSeconds = Math . floor ( ( end - start ) / 1000 ) ;
243- const granularitySizeSeconds = Math . ceil ( diffSeconds / maxNumBuckets ) ;
244-
245- if ( granularitySizeSeconds <= 15 ) {
246- return Granularity . FifteenSecond ;
247- } else if ( granularitySizeSeconds <= 30 ) {
248- return Granularity . ThirtySecond ;
249- } else if ( granularitySizeSeconds <= 60 ) {
250- return Granularity . OneMinute ;
251- } else if ( granularitySizeSeconds <= 5 * 60 ) {
252- return Granularity . FiveMinute ;
253- } else if ( granularitySizeSeconds <= 10 * 60 ) {
254- return Granularity . TenMinute ;
255- } else if ( granularitySizeSeconds <= 15 * 60 ) {
256- return Granularity . FifteenMinute ;
257- } else if ( granularitySizeSeconds <= 30 * 60 ) {
258- return Granularity . ThirtyMinute ;
259- } else if ( granularitySizeSeconds <= 3600 ) {
260- return Granularity . OneHour ;
261- } else if ( granularitySizeSeconds <= 2 * 3600 ) {
262- return Granularity . TwoHour ;
263- } else if ( granularitySizeSeconds <= 6 * 3600 ) {
264- return Granularity . SixHour ;
265- } else if ( granularitySizeSeconds <= 12 * 3600 ) {
266- return Granularity . TwelveHour ;
267- } else if ( granularitySizeSeconds <= 24 * 3600 ) {
268- return Granularity . OneDay ;
269- } else if ( granularitySizeSeconds <= 2 * 24 * 3600 ) {
270- return Granularity . TwoDay ;
271- } else if ( granularitySizeSeconds <= 7 * 24 * 3600 ) {
272- return Granularity . SevenDay ;
273- } else if ( granularitySizeSeconds <= 30 * 24 * 3600 ) {
274- return Granularity . ThirtyDay ;
275- }
276-
277- return Granularity . ThirtyDay ;
278- }
279-
280222export const ChartKeyJoiner = ' · ' ;
281223export const PreviousPeriodSuffix = ' (previous)' ;
282224
0 commit comments