import { IndexPattern } from 'src/plugins/data/public' ; import { IESAggSource } from '../../sources/es_agg_source' ; import { IVectorSource } from '../../sources/vector_source' ; import { AGG_TYPE , FIELD_ORIGIN } from '../../../../common/constants' ; import { TileMetaFeature } from '../../../../common/descriptor_types' ; import { ITooltipProperty , TooltipProperty } from '../../tooltips/tooltip_property' ; import { ESAggTooltipProperty } from '../../tooltips/es_agg_tooltip_property' ; import { IESAggField , CountAggFieldParams } from './agg_field_types' ; export class CountAggField implements IESAggField { protected readonly _source : IESAggSource ; private readonly _origin : FIELD_ORIGIN ; protected readonly _label ? : string ; constructor ( { label , source , origin } ) { this . _source = source ; this . _origin = origin ; this . _label = label ; } supportsFieldMetaFromEs ( ) { return false ; } supportsFieldMetaFromLocalData ( ) { return true ; } _getAggType ( ) { return AGG_TYPE . COUNT ; } getSource ( ) { return this . _source ; } getOrigin ( ) { return this . _origin ; } getName ( ) { return this . _source . getAggKey ( this . _getAggType ( ) , this . getRootName ( ) ) ; } getMbFieldName ( ) { return this . _source . isMvt ( ) ? '_count' : this . getName ( ) ; } getRootName ( ) { return '' ; } async getLabel ( ) { return this . _label ? this . _label : this . _source . getAggLabel ( AGG_TYPE . COUNT , '' ) ; } isValid ( ) { return true ; } async getDataType ( ) { return 'number' ; } async createTooltipProperty ( value ) { const indexPattern = await this . _source . getIndexPattern ( ) ; const tooltipProperty = new TooltipProperty ( this . getName ( ) , await this . getLabel ( ) , value ) ; return new ESAggTooltipProperty ( tooltipProperty , indexPattern , this , this . _getAggType ( ) , this . _source . getApplyGlobalQuery ( ) ) ; } getValueAggDsl ( indexPattern ) { return null ; } getBucketCount ( ) { return 0 ; } isCount ( ) { return true ; } canValueBeFormatted ( ) { return false ; } async getExtendedStatsFieldMetaRequest ( ) { return null ; } async getPercentilesFieldMetaRequest ( percentiles ) { return null ; } async getCategoricalFieldMetaRequest ( size ) { return null ; } isEqual ( field ) { return field . getName ( ) === this . getName ( ) ; } pluckRangeFromTileMetaFeature ( metaFeature ) { const minField = `aggregations._count.min` ; const maxField = `aggregations._count.max` ; return metaFeature . properties && typeof metaFeature . properties [ minField ] === 'number' && typeof metaFeature . properties [ maxField ] === 'number' ? { min : metaFeature . properties [ minField ] as number , max : metaFeature . properties [ maxField ] as number , } : null ; } }