import { BrushAxis } from '../../../../specs' ; import { GlobalChartState } from '../../../../state/chart_state' ; import { createCustomCachedSelector } from '../../../../state/create_selector' ; import { getSettingsSpecSelector } from '../../../../state/selectors/get_settings_specs' ; import { clamp } from '../../../../utils/common' ; import { Dimensions } from '../../../../utils/dimensions' ; import { computeChartElementSizesSelector } from './compute_chart_dimensions' ; import { getBrushedHighlightedShapesSelector } from './get_brushed_highlighted_shapes' ; const getMouseDownPosition = ( state ) => state . interactions . pointer . down ; const getIsDragging = ( state ) => state . interactions . pointer . dragging ; const getCurrentPointerPosition = ( state ) => state . interactions . pointer . current . position ; internal export const getBrushAreaSelector = createCustomCachedSelector ( [ getIsDragging , getMouseDownPosition , getCurrentPointerPosition , getSettingsSpecSelector , computeChartElementSizesSelector , getBrushedHighlightedShapesSelector , ] , ( isDragging , mouseDownPosition , end , { brushAxis } , dims , dragShape ) : Dimensions | null => { if ( ! isDragging || ! mouseDownPosition || ! dragShape ) { return null ; } const start = { x : mouseDownPosition . position . x - dims . grid . left , y : mouseDownPosition . position . y , } ; const clampedEndY = clamp ( end . y , 0 , dims . grid . height ) ; switch ( brushAxis ) { case BrushAxis . Both : return { top : start . y , left : start . x , width : end . x - start . x - dims . grid . left , height : clampedEndY - start . y , } ; default : return { top : start . y , left : start . x , width : end . x - start . x - dims . grid . left , height : clampedEndY - start . y , } ; } } ) ;