import { uniq } from 'lodash' ; import moment from 'moment' ; import { Chart } from './point_series' ; import { Table } from '../../types' ; export function initXAxis ( chart , table ) { const { format , title , params , accessor } = chart . aspects . x [ 0 ] ; chart . xAxisOrderedValues = accessor === - 1 && 'defaultValue' in params ? [ params . defaultValue ] : uniq ( table . rows . map ( ( r ) => r [ accessor ] ) ) ; chart . xAxisFormat = format ; chart . xAxisLabel = title ; if ( 'interval' in params ) { if ( 'date' in params ) { const { intervalESUnit , intervalESValue } = params ; chart . ordered = { interval : moment . duration ( intervalESValue , intervalESUnit as any ) , intervalESUnit , intervalESValue , } ; } else { chart . ordered = { interval : params . interval , } ; } } }