import { createCustomCachedSelector } from '../../../../state/create_selector' ; import { getLastDragSelector } from '../../../../state/selectors/get_last_drag' ; import { PickDragFunction } from '../../layout/types/viewmodel_types' ; import { computeChartElementSizesSelector } from './compute_chart_dimensions' ; import { getHeatmapGeometries } from './geometries' ; internal export const getPickedCells = createCustomCachedSelector ( [ getHeatmapGeometries , getLastDragSelector , computeChartElementSizesSelector ] , ( geoms , dragState , dims ) : ReturnType < PickDragFunction > | null => { if ( ! dragState ) { return null ; } if ( dragState . start . position . x < dims . grid . left && dragState . end . position . x < dims . grid . left ) { const fittedDragStateStart = { x : dims . grid . left , y : dragState . start . position . y } ; const { y , cells } = geoms . pickDragArea ( [ fittedDragStateStart , dragState . end . position ] ) ; return { x : [ ] , y , cells } ; } if ( dragState . start . position . y > dims . grid . height && dragState . end . position . y > dims . grid . height ) { const fittedDragStateStart = { x : dragState . start . position . x , y : dims . grid . height } ; const { x , cells } = geoms . pickDragArea ( [ fittedDragStateStart , dragState . end . position ] ) ; return { x , y : [ ] , cells } ; } return geoms . pickDragArea ( [ dragState . start . position , dragState . end . position ] ) ; } ) ;