import { TooltipPortalSettings } from '../../../components/portal' ; import { Rotation } from '../../../utils/common' ; import { Dimensions } from '../../../utils/dimensions' ; import { AnnotationId } from '../../../utils/ids' ; import { Point } from '../../../utils/point' ; import { AnnotationSpec , isRectAnnotation } from '../utils/specs' ; import { getRectAnnotationTooltipState } from './rect/tooltip' ; import { AnnotationRectProps } from './rect/types' ; import { AnnotationDimensions , AnnotationTooltipState } from './types' ; internal export function computeRectAnnotationTooltipState ( cursorPosition , annotationDimensions , annotationSpecs , chartRotation , chartDimensions ) { const sortedAnnotationSpecs = annotationSpecs . filter ( isRectAnnotation ) . sort ( ( { zIndex : a = Number . MIN_SAFE_INTEGER } , { zIndex : b = Number . MIN_SAFE_INTEGER } ) => a - b ) ; for ( let i = 0 ; i < sortedAnnotationSpecs . length ; i ++ ) { const spec = sortedAnnotationSpecs [ i ] ; const annotationDimension = annotationDimensions . get ( spec . id ) ; if ( spec . hideTooltips || ! annotationDimension ) { continue ; } const { customTooltip , customTooltipDetails } = spec ; const tooltipSettings = getTooltipSettings ( spec ) ; const rectAnnotationTooltipState = getRectAnnotationTooltipState ( cursorPosition , annotationDimension as AnnotationRectProps [ ] , chartRotation , chartDimensions , spec . id ) ; if ( rectAnnotationTooltipState ) { return { ... rectAnnotationTooltipState , tooltipSettings , customTooltip , customTooltipDetails : customTooltipDetails ?? spec . renderTooltip , } ; } } return null ; } internal export function computeMultipleRectAnnotationTooltipState ( cursorPosition , annotationDimensions , annotationSpecs , chartRotation , chartDimensions ) { const sortedAnnotationSpecs = annotationSpecs . filter ( isRectAnnotation ) . sort ( ( { zIndex : a = Number . MIN_SAFE_INTEGER } , { zIndex : b = Number . MIN_SAFE_INTEGER } ) => a - b ) ; return sortedAnnotationSpecs . reduce < AnnotationTooltipState [ ] > ( ( acc , spec ) => { const annotationDimension = annotationDimensions . get ( spec . id ) ; if ( ! spec . hideTooltips && annotationDimension ) { const { customTooltip , customTooltipDetails } = spec ; const tooltipSettings = getTooltipSettings ( spec ) ; const rectAnnotationTooltipState = getRectAnnotationTooltipState ( cursorPosition , annotationDimension as AnnotationRectProps [ ] , chartRotation , chartDimensions , spec . id ) ; if ( rectAnnotationTooltipState ) { acc . push ( { ... rectAnnotationTooltipState , tooltipSettings , customTooltip , customTooltipDetails : customTooltipDetails ?? spec . renderTooltip , } ) ; } } return acc ; } , [ ] as AnnotationTooltipState [ ] ) ; } function getTooltipSettings ( { placement , fallbackPlacements , boundary , offset , } ) { return { placement , fallbackPlacements , boundary , offset , } ; }