import { partial } from 'lodash' ; import { getPoint } from './_get_point' ; import { addToSiri , Serie } from './_add_to_siri' ; import { Chart } from './point_series' ; import { Table } from '../../types' ; export function getSeries ( table , chart ) { const aspects = chart . aspects ; const xAspect = aspects . x [ 0 ] ; const yAspect = aspects . y [ 0 ] ; const zAspect = aspects . z && aspects . z [ 0 ] ; const multiY = Array . isArray ( aspects . y ) && aspects . y . length > 1 ; const partGetPoint = partial ( getPoint , table , xAspect , aspects . series ) ; const seriesMap = new Map < string , Serie > ( ) ; table . rows . forEach ( ( row , rowIndex ) => { if ( ! multiY ) { const point = partGetPoint ( row , rowIndex , yAspect , zAspect ) ; if ( point ) { const id = `${ point . series }-${ yAspect . accessor }` ; point . seriesId = id ; addToSiri ( seriesMap , point , id , point . series , yAspect . format , zAspect && zAspect . format , zAspect && zAspect . title ) ; } return ; } aspects . y . forEach ( function ( y ) { const point = partGetPoint ( row , rowIndex , y , zAspect ) ; if ( ! point ) { return ; } let seriesId = y . accessor ; let seriesLabel = y . title ; if ( aspects . series ) { const prefix = point . series ? point . series + ': ' : '' ; seriesId = prefix + seriesId ; seriesLabel = prefix + seriesLabel ; } ( point . seriesId as string | number ) = seriesId ; addToSiri ( seriesMap , point , seriesId as string , seriesLabel , y . format , zAspect && zAspect . format , zAspect && zAspect . title ) ; } ) ; } ) ; return [ ... seriesMap . values ( ) ] ; }