import { getColumnByAccessor } from './accessor' ; import { DatatableColumn , Datatable } from '../../../../expressions/public' ; import { BucketColumns , PieVisParams } from '../../common/types' ; export const getColumns = ( visParams , visData ) : { metricColumn : DatatableColumn ; bucketColumns : Array < Partial < BucketColumns > > ; } => { if ( visParams . dimensions . buckets && visParams . dimensions . buckets . length > 0 ) { const bucketColumns = visParams . dimensions . buckets . map ( ( { accessor , format } ) => ( { ... getColumnByAccessor ( accessor , visData . columns ) , format , } ) ) ; const lastBucketId = bucketColumns [ bucketColumns . length - 1 ] . id ; const matchingIndex = visData . columns . findIndex ( ( col ) => col . id === lastBucketId ) ; return { bucketColumns , metricColumn : visData . columns [ matchingIndex + 1 ] , } ; } const metricAccessor = visParams ?. dimensions ?. metric . accessor ?? 0 ; const metricColumn = getColumnByAccessor ( metricAccessor , visData . columns ) ; return { metricColumn , bucketColumns : [ { name : metricColumn . name , } , ] , } ; } ;