import { Datum , DatumFocusStatus , DatumStyles , Series , SeriesFocusStatus , SeriesStyles , } from '../types' ; export function getSeriesStatus < TDatum > ( series , focusedDatum ) { if ( focusedDatum ?. seriesId === series . id ) { return 'focused' ; } return 'none' ; } export function getDatumStatus < TDatum > ( datum , focusedDatum ) { if ( datum === focusedDatum ) { return 'focused' ; } if ( datum . tooltipGroup ?. some ( groupDatum => { groupDatum . seriesId === focusedDatum ?. seriesId && groupDatum . index === focusedDatum ?. index ; } ) ) { return 'groupFocused' ; } return 'none' ; } const elementTypes = [ 'area' , 'line' , 'rectangle' , 'circle' ] as const ; export function materializeStyles ( style = { } , defaults = { } ) { style = normalizeColor ( style , defaults ) ; for ( let i = 0 ; i < elementTypes . length ; i ++ ) { const type = elementTypes [ i ] ; if ( style [ type ] && defaults [ type ] ) { style [ type ] = materializeStyles ( style [ type ] , defaults ) ; } } return style ; } export function translate ( x , y ) { return `translate3d(${ Math . round ( x ) }px, ${ Math . round ( y ) }px, 0)` ; } function normalizeColor ( style , defaults ) { return { ... style , stroke : style . stroke || style . color || defaults . stroke || defaults . color , fill : style . fill || style . color || defaults . fill || defaults . color , } ; } export function isDefined ( num ) { return typeof num === 'number' && ! Number . isNaN ( num ) ; }