import { Scale , ScaleContinuous } from '../../../../scales' ; import { XDomain } from '../../domains/types' ; import { AxisLabelFormatter } from '../../state/selectors/axis_tick_formatter' ; import { GetMeasuredTicks } from '../../state/selectors/visible_ticks' ; import { AxisTick } from '../../utils/axis_utils' ; import { rasters , TimeBin , TimeRaster } from './rasters' ; const MAX_TIME_TICK_COUNT = 50 ; const WIDTH_FUDGE = 1.05 ; const MAX_TIME_GRID_COUNT = 12 ; internal export const notTooDense = ( domainFrom , domainTo , binWidth , cartesianWidth , maxTickCount = MAX_TIME_TICK_COUNT ) => ( raster ) => { const domainInSeconds = domainTo - domainFrom ; const pixelsPerSecond = cartesianWidth / domainInSeconds ; return ( pixelsPerSecond > raster . minimumPixelsPerSecond && raster . approxWidthInMs * WIDTH_FUDGE >= binWidth && ( domainInSeconds * 1000 ) / maxTickCount <= raster . approxWidthInMs ) ; } ; internal export function multilayerAxisEntry ( xDomain , extendByOneBin , range , timeAxisLayerCount , scale , getMeasuredTicks ) { const rasterSelector = rasters ( { minimumTickPixelDistance : 24 , locale : 'en-US' } , xDomain . timeZone ) ; const domainValues = xDomain . domain ; const domainFromS = Number ( domainValues [ 0 ] ) / 1000 ; const binWidth = xDomain . minInterval ; const domainExtension = extendByOneBin ? binWidth : 0 ; const domainToS = ( ( Number ( domainValues [ domainValues . length - 1 ] ) || NaN ) + domainExtension ) / 1000 ; const layers = rasterSelector ( notTooDense ( domainFromS , domainToS , binWidth , Math . abs ( range [ 1 ] - range [ 0 ] ) ) ) ; let layerIndex = - 1 ; const fillLayerTimeslip = ( layer , detailedLayer , timeTicks , labelFormat , showGrid ) => { return { entry : getMeasuredTicks ( scale , timeTicks , layer , detailedLayer , labelFormat as AxisLabelFormatter , showGrid ) , fallbackAskedTickCount : NaN , } ; } ; return layers . reduce ( ( combinedEntry , l , detailedLayerIndex ) => { if ( l . labeled ) layerIndex ++ ; if ( layerIndex >= timeAxisLayerCount ) return combinedEntry ; const binWidthS = binWidth / 1000 ; const { entry } = fillLayerTimeslip ( layerIndex , detailedLayerIndex , [ ... l . binStarts ( domainFromS - binWidthS , domainToS + binWidthS ) ] . filter ( ( b ) => b . nextTimePointSec > domainFromS && b . timePointSec <= domainToS ) . map ( ( b ) => 1000 * b . timePointSec ) , ! l . labeled ? ( ) => '' : layerIndex === timeAxisLayerCount - 1 ? l . detailedLabelFormat : l . minorTickLabelFormat , notTooDense ( domainFromS , domainToS , binWidth , Math . abs ( range [ 1 ] - range [ 0 ] ) , MAX_TIME_GRID_COUNT ) ( l ) ) ; const minLabelGap = 4 ; const lastTick = entry . ticks [ entry . ticks . length - 1 ] ; if ( lastTick && lastTick . position + entry . labelBox . maxLabelBboxWidth > range [ 1 ] ) { lastTick . label = '' ; } return { ... entry , ... combinedEntry , ticks : ( combinedEntry . ticks || [ ] ) . concat ( entry . ticks . filter ( ( tick , i , a ) => i > 0 || ! a [ 1 ] || a [ 1 ] . domainClampedPosition - tick . domainClampedPosition >= entry . labelBox . maxLabelBboxWidth + minLabelGap ) ) , } ; } , { ticks : [ ] } ) ; }