import { Colors } from '../../../../common/colors' ; import { TooltipInfo } from '../../../../components/tooltip/types' ; import { createCustomCachedSelector } from '../../../../state/create_selector' ; import { BandViewModel } from '../../layout/types/viewmodel_types' ; import { getSpecOrNull } from './goal_spec' ; import { getPickedShapes } from './picked_shapes' ; const EMPTY_TOOLTIP = Object . freeze ( { header : null , values : [ ] , } ) ; const getBandColor = ( value , bands ) => bands . find ( ( { value : v } ) => { return v >= value ; } ) ?. fillColor ?? Colors . White . keyword ; internal export const getTooltipInfoSelector = createCustomCachedSelector ( [ getSpecOrNull , getPickedShapes ] , ( spec , pickedShapes ) : TooltipInfo => { if ( ! spec ) { return EMPTY_TOOLTIP ; } const { tooltipValueFormatter , id } = spec ; const tooltipInfo = { header : null , values : [ ] , } ; pickedShapes . forEach ( ( { actual : value , bands } ) => { tooltipInfo . values . push ( { label : 'Actual' , color : getBandColor ( value , bands ) , isHighlighted : false , isVisible : true , seriesIdentifier : { specId : id , key : id , } , value , formattedValue : tooltipValueFormatter ( value ) , datum : value , } ) ; } ) ; return tooltipInfo ; } ) ;