import { Scale } from '../../../scales' ; import { SettingsSpec } from '../../../specs' ; import { Rotation , Position } from '../../../utils/common' ; import { Dimensions } from '../../../utils/dimensions' ; import { AnnotationId , AxisId , GroupId } from '../../../utils/ids' ; import { Point } from '../../../utils/point' ; import { AxisStyle } from '../../../utils/themes/theme' ; import { SmallMultipleScales } from '../state/selectors/compute_small_multiple_scales' ; import { getAxesSpecForSpecId } from '../state/utils/spec' ; import { ComputedGeometries } from '../state/utils/types' ; import { AnnotationDomainType , AnnotationSpec , AxisSpec , isLineAnnotation } from '../utils/specs' ; import { computeLineAnnotationDimensions } from './line/dimensions' ; import { computeRectAnnotationDimensions } from './rect/dimensions' ; import { AnnotationDimensions } from './types' ; internal export function getAnnotationAxis ( axesSpecs , groupId , domainType , chartRotation ) { const { xAxis , yAxis } = getAxesSpecForSpecId ( axesSpecs , groupId , chartRotation ) ; const isXDomainAnnotation = isXDomain ( domainType ) ; return isXDomainAnnotation ? xAxis ?. position : yAxis ?. position ; } internal export function isXDomain ( domainType ) { return domainType === AnnotationDomainType . XDomain ; } internal export function getTransformedCursor ( cursorPosition , chartDimensions , chartRotation , /**
 * getTransformedCursor to account for projected cursor position relative to chart dimensions
 */ projectArea = false ) { const { height , width , left , top } = chartDimensions ; let { x , y } = cursorPosition ; if ( projectArea ) { x = cursorPosition . x - left ; y = cursorPosition . y - top ; } if ( chartRotation === null ) { return { x , y } ; } switch ( chartRotation ) { case 90 : return { x : y , y : width - x } ; case - 90 : return { x : height - y , y : x } ; case 180 : return { x : width - x , y : height - y } ; case 0 : default : return { x , y } ; } } internal export function invertTransformedCursor ( cursorPosition , chartDimensions , chartRotation , /**
 * Used to account for projected cursor position relative to chart dimensions
 */ projectArea = false ) { const { height , width , left , top } = chartDimensions ; let { x , y } = cursorPosition ; switch ( chartRotation ) { case 0 : case null : break ; case 90 : x = width - cursorPosition . y ; y = cursorPosition . x ; break ; case - 90 : y = height - cursorPosition . x ; x = cursorPosition . y ; break ; case 180 : default : y = height - cursorPosition . y ; x = width - cursorPosition . x ; } if ( projectArea ) { x += left ; y += top ; } return { x , y } ; } internal export function computeAnnotationDimensions ( annotations , { rotation : chartRotation } , { scales : { xScale , yScales } } , axesSpecs , isHistogramModeEnabled , smallMultipleScales , getAxisStyle ) { return annotations . reduce < Map < AnnotationId , AnnotationDimensions > > ( ( annotationDimensions , annotationSpec ) => { const { id } = annotationSpec ; if ( isLineAnnotation ( annotationSpec ) ) { const { groupId , domainType } = annotationSpec ; const annotationAxisPosition = getAnnotationAxis ( axesSpecs , groupId , domainType , chartRotation ) ; const dimensions = computeLineAnnotationDimensions ( annotationSpec , chartRotation , yScales , xScale , smallMultipleScales , isHistogramModeEnabled , annotationAxisPosition ) ; if ( dimensions ) { annotationDimensions . set ( id , dimensions ) ; } return annotationDimensions ; } else { const dimensions = computeRectAnnotationDimensions ( annotationSpec , yScales , xScale as Scale < number > , axesSpecs , smallMultipleScales , chartRotation , getAxisStyle , isHistogramModeEnabled ) ; if ( dimensions ) { annotationDimensions . set ( id , dimensions ) ; } return annotationDimensions ; } } , new Map ( ) ) ; }