import moment from 'moment' ; import { UI_SETTINGS } from '../../../../common/constants' ; import { TimeRange } from '../../../../common/query' ; import { TimeBuckets } from '../buckets/lib/time_buckets' ; import { toAbsoluteDates } from './date_interval_utils' ; import { autoInterval } from '../buckets/_interval_options' ; export function getCalculateAutoTimeExpression ( getConfig ) { return function calculateAutoTimeExpression ( range ) { const dates = toAbsoluteDates ( range ) ; if ( ! dates ) { return ; } const buckets = new TimeBuckets ( { 'histogram:maxBars' : getConfig ( UI_SETTINGS . HISTOGRAM_MAX_BARS ) , 'histogram:barTarget' : getConfig ( UI_SETTINGS . HISTOGRAM_BAR_TARGET ) , dateFormat : getConfig ( 'dateFormat' ) , 'dateFormat:scaled' : getConfig ( 'dateFormat:scaled' ) , } ) ; buckets . setInterval ( autoInterval ) ; buckets . setBounds ( { min : moment ( dates . from ) , max : moment ( dates . to ) , } ) ; return buckets . getInterval ( ) . expression ; } ; }