import { TooltipPortalSettings } from '../../../../components/portal/types' ; import { TooltipInfo } from '../../../../components/tooltip/types' ; import { DOMElement } from '../../../../state/actions/dom_element' ; import { GlobalChartState } from '../../../../state/chart_state' ; import { createCustomCachedSelector } from '../../../../state/create_selector' ; import { getChartRotationSelector } from '../../../../state/selectors/get_chart_rotation' ; import { Rotation } from '../../../../utils/common' ; import { Dimensions } from '../../../../utils/dimensions' ; import { AnnotationId } from '../../../../utils/ids' ; import { Point } from '../../../../utils/point' ; import { AnnotationLineProps } from '../../annotations/line/types' ; import { AnnotationRectProps } from '../../annotations/rect/types' ; import { computeRectAnnotationTooltipState } from '../../annotations/tooltip' ; import { AnnotationTooltipState , AnnotationDimensions } from '../../annotations/types' ; import { AxisSpec , AnnotationSpec , AnnotationType } from '../../utils/specs' ; import { ComputedGeometries } from '../utils/types' ; import { computeAnnotationDimensionsSelector } from './compute_annotations' ; import { computeChartDimensionsSelector } from './compute_chart_dimensions' ; import { computeSeriesGeometriesSelector } from './compute_series_geometries' ; import { getAxisSpecsSelector , getAnnotationSpecsSelector } from './get_specs' ; import { getTooltipInfoSelector } from './get_tooltip_values_highlighted_geoms' ; const getCurrentPointerPosition = ( state ) => state . interactions . pointer . current . position ; const getHoveredDOMElement = ( state ) => state . interactions . hoveredDOMElement ; internal export const getAnnotationTooltipStateSelector = createCustomCachedSelector ( [ getCurrentPointerPosition , computeChartDimensionsSelector , computeSeriesGeometriesSelector , getChartRotationSelector , getAnnotationSpecsSelector , getAxisSpecsSelector , computeAnnotationDimensionsSelector , getTooltipInfoSelector , getHoveredDOMElement , ] , getAnnotationTooltipState ) ; function getAnnotationTooltipState ( cursorPosition , { chartDimensions , } , geometries , chartRotation , annotationSpecs , axesSpecs , annotationDimensions , tooltip , hoveredDOMElement ) { const hoveredTooltip = getTooltipStateForDOMElements ( chartDimensions , annotationSpecs , annotationDimensions , hoveredDOMElement ) ; if ( hoveredTooltip ) { return hoveredTooltip ; } if ( cursorPosition . x < 0 || cursorPosition . y < 0 ) { return null ; } const { xScale , yScales } = geometries . scales ; if ( ! xScale || ! yScales ) { return null ; } const tooltipState = computeRectAnnotationTooltipState ( cursorPosition , annotationDimensions , annotationSpecs , chartRotation , chartDimensions ) ; const isChartTooltipDisplayed = tooltip . values . some ( ( { isHighlighted } ) => isHighlighted ) ; if ( tooltipState && tooltipState . isVisible && tooltipState . annotationType === AnnotationType . Rectangle && isChartTooltipDisplayed ) { return null ; } return tooltipState ; } internal export function getTooltipStateForDOMElements ( chartDimensions , annotationSpecs , annotationDimensions , hoveredDOMElement ) { if ( ! hoveredDOMElement ) { return null ; } const spec = annotationSpecs . find ( ( { id } ) => id === hoveredDOMElement . createdBySpecId ) ; if ( ! spec || spec . hideTooltips ) { return null ; } const dimension = ( annotationDimensions . get ( hoveredDOMElement . createdBySpecId ) ?? [ ] ) . filter ( isAnnotationLineProps ) . find ( ( { id } ) => id === hoveredDOMElement . id ) ; if ( ! dimension ) { return null ; } return { id : spec . id , isVisible : true , annotationType : AnnotationType . Line , datum : dimension . datum , anchor : { y : ( dimension . markers [ 0 ] ?. position . top ?? 0 ) + dimension . panel . top + chartDimensions . top , x : ( dimension . markers [ 0 ] ?. position . left ?? 0 ) + dimension . panel . left + chartDimensions . left , width : 0 , height : 0 , } , customTooltipDetails : spec . customTooltipDetails , customTooltip : spec . customTooltip , tooltipSettings : getTooltipSettings ( spec ) , } ; } function isAnnotationLineProps ( prop ) { return 'linePathPoints' in prop ; } function getTooltipSettings ( { placement , fallbackPlacements , boundary , offset , } ) { return { placement , fallbackPlacements , boundary , offset , } ; }