import moment from 'moment' ; import { calculateAuto } from './calculate_auto' ; import { unitToSeconds } from './unit_to_seconds' ; export function getBucketSize ( { start , end , minInterval , } ) { const duration = moment . duration ( end - start , 'ms' ) ; const bucketSize = Math . max ( calculateAuto . near ( 100 , duration ) . asSeconds ( ) , 1 ) ; const intervalString = `${ bucketSize }s` ; const matches = minInterval && minInterval . match ( /^([\d]+)([shmdwMy]|ms)$/ ) ; const minBucketSize = matches ? Number ( matches [ 1 ] ) * unitToSeconds ( matches [ 2 ] ) : 0 ; if ( bucketSize < minBucketSize ) { return { bucketSize : minBucketSize , intervalString : minInterval , } ; } return { bucketSize , intervalString } ; }