import { XYChartSeriesIdentifier , GeometryValue } from '@elastic/charts' ; import { ValueClickContext } from 'src/plugins/embeddable/public' ; import { X_ACCESSOR_INDEX } from '../../visualizations/constants' ; import { BUCKET_TYPES } from '../../../../common/enums' ; import { TimeseriesVisParams } from '../../../types' ; import type { TSVBTables } from './types' ; export const getClickFilterData = ( points , tables , model ) => { const data = [ ] ; points . forEach ( ( point ) => { const [ geometry ] = point ; const { specId } = point [ 1 ] ; const [ layerId , splitLabel ] = specId . split ( ':' ) ; const table = tables [ layerId ] ; const layer = model . series . filter ( ( { id } ) => id === layerId ) ; let label = splitLabel ; if ( splitLabel && layer . length && layer [ 0 ] . split_mode === BUCKET_TYPES . FILTERS ) { const filter = layer [ 0 ] ?. split_filters ?. filter ( ( { id } ) => id === splitLabel ) ; label = filter ?. [ 0 ] . label || ( filter ?. [ 0 ] . filter ?. query as string ) ; } const index = table . rows . findIndex ( ( row ) => { const condition = geometry . x === row [ X_ACCESSOR_INDEX ] && geometry . y === row [ X_ACCESSOR_INDEX + 1 ] ; return splitLabel ? condition && row [ X_ACCESSOR_INDEX + 2 ] . toString ( ) === label : condition ; } ) ; if ( index < 0 ) return ; const bucketCols = table . columns . filter ( ( col ) => col . meta . sourceParams ?. schema === 'group' ) ; const newData = bucketCols . map ( ( { id } ) => ( { table , column : parseInt ( id , 10 ) , row : index , value : table . rows [ index ] [ id ] ?? null , } ) ) ; if ( newData . length ) { data . push ( ... newData ) ; } } ) ; return data ; } ;