import { Duration } from 'moment' ; import type { Dimension , Dimensions } from '../../../../../xy/public' ; import type { DateHistogramParams , HistogramParams } from '../../../../../../visualizations/public' ; import { getSeries } from './_get_series' ; import { getAspects } from './_get_aspects' ; import { initYAxis } from './_init_y_axis' ; import { initXAxis } from './_init_x_axis' ; import { orderedDateAxis } from './_ordered_date_axis' ; import { Serie } from './_add_to_siri' ; import { Column , Table } from '../../types' ; export interface Aspect { accessor : Column [ 'id' ] ; column ? : Dimension [ 'accessor' ] ; title : Column [ 'name' ] ; format : Dimension [ 'format' ] ; params : Dimension [ 'params' ] ; } export type Aspects = { x : Aspect [ ] ; y : Aspect [ ] ; } & { [ key in keyof Dimensions ] ? : Aspect [ ] ; } ; export interface DateHistogramOrdered { interval : Duration ; intervalESUnit : DateHistogramParams [ 'intervalESUnit' ] ; intervalESValue : DateHistogramParams [ 'intervalESValue' ] ; } export interface HistogramOrdered { interval : HistogramParams [ 'interval' ] ; } type Ordered = ( DateHistogramOrdered | HistogramOrdered ) & { date ? : boolean ; min ? : number ; max ? : number ; endzones ? : boolean ; } ; export interface Chart { aspects : Aspects ; series : Serie [ ] ; xAxisOrderedValues ? : Array < string | number | object > ; xAxisFormat ? : Dimension [ 'format' ] ; xAxisLabel ? : Column [ 'name' ] ; yAxisFormat ? : Dimension [ 'format' ] ; yAxisLabel ? : Column [ 'name' ] ; zAxisFormat ? : Dimension [ 'format' ] ; zAxisLabel ? : Column [ 'name' ] ; ordered ? : Ordered ; } export type OrderedChart = Chart & { ordered : Ordered ; } ; export const buildPointSeriesData = ( table , dimensions ) => { const chart = { aspects : getAspects ( table , dimensions ) , } as Chart ; initXAxis ( chart , table ) ; initYAxis ( chart ) ; if ( 'date' in chart . aspects . x [ 0 ] . params ) { orderedDateAxis ( chart as OrderedChart ) ; } chart . series = getSeries ( table , chart ) ; delete chart . aspects ; return chart ; } ;