import { SeriesKey } from '../../../../common/series_id' ; import { XDomain } from '../../domains/types' ; import { isDatumFilled } from '../../rendering/utils' ; import { DataSeries , getSeriesKey , XYChartSeriesIdentifier } from '../../utils/series' ; import { StackMode } from '../../utils/specs' ; import { LastValues } from './types' ; internal param dataSeries param xDomain export function getLastValues ( dataSeries , xDomain ) { const lastValues = new Map < SeriesKey , LastValues > ( ) ; dataSeries . forEach ( ( series ) => { if ( series . data . length === 0 ) { return ; } const last = series . data [ series . data . length - 1 ] ; if ( ! last ) { return ; } if ( isDatumFilled ( last ) ) { return ; } if ( last . x !== xDomain . domain [ xDomain . domain . length - 1 ] ) { return ; } const { y0 , y1 , initialY0 , initialY1 } = last ; const seriesKey = getSeriesKey ( series as XYChartSeriesIdentifier , series . groupId ) ; if ( series . stackMode === StackMode . Percentage ) { const y1InPercentage = y1 === null || y0 === null ? null : y1 - y0 ; lastValues . set ( seriesKey , { y0 , y1 : y1InPercentage } ) ; return ; } if ( initialY0 !== null || initialY1 !== null ) { lastValues . set ( seriesKey , { y0 : initialY0 , y1 : initialY1 } ) ; } } ) ; return lastValues ; }