import { LayerValue , SettingsSpec , Spec } from '../specs' ; import { PointerStates } from '../state/chart_state' ; import { isClicking } from '../state/utils' ; import { SeriesIdentifier } from './series_id' ; internal export const getOnElementClickSelector = ( prev ) => ( spec , lastClick , settings , pickedShapes ) : void => { if ( ! spec ) { return ; } if ( ! settings . onElementClick ) { return ; } const nextPickedShapesLength = pickedShapes . length ; if ( nextPickedShapesLength > 0 && isClicking ( prev . click , lastClick ) && settings && settings . onElementClick ) { const elements = pickedShapes . map < [ Array < LayerValue > , SeriesIdentifier ] > ( ( values ) => [ values , { specId : spec . id , key : `spec{${ spec . id }}` , } , ] ) ; settings . onElementClick ( elements ) ; } prev . click = lastClick ; } ; internal export const getOnElementOutSelector = ( prev ) => ( spec , pickedShapes , settings ) : void => { if ( ! spec ) { return ; } if ( ! settings . onElementOut ) { return ; } const nextPickedShapes = pickedShapes . length ; if ( prev . pickedShapes !== null && prev . pickedShapes > 0 && nextPickedShapes === 0 ) { settings . onElementOut ( ) ; } prev . pickedShapes = nextPickedShapes ; } ; function isOverElement ( prevPickedShapes = [ ] , nextPickedShapes ) { if ( nextPickedShapes . length === 0 ) { return ; } if ( nextPickedShapes . length !== prevPickedShapes . length ) { return true ; } return ! nextPickedShapes . every ( ( nextPickedShapeValues , index ) => { const prevPickedShapeValues = prevPickedShapes [ index ] ; if ( prevPickedShapeValues === null ) { return false ; } if ( prevPickedShapeValues . length !== nextPickedShapeValues . length ) { return false ; } return nextPickedShapeValues . every ( ( layerValue , i ) => { const prevPickedValue = prevPickedShapeValues [ i ] ; if ( ! prevPickedValue ) { return false ; } return layerValue . value === prevPickedValue . value && layerValue . groupByRollup === prevPickedValue . groupByRollup ; } ) ; } ) ; } internal export const getOnElementOverSelector = ( prev ) => ( spec , nextPickedShapes , settings ) : void => { if ( ! spec ) { return ; } if ( ! settings . onElementOver ) { return ; } if ( isOverElement ( prev . pickedShapes , nextPickedShapes ) ) { const elements = nextPickedShapes . map < [ Array < LayerValue > , SeriesIdentifier ] > ( ( values ) => [ values , { specId : spec . id , key : `spec{${ spec . id }}` , } , ] ) ; settings . onElementOver ( elements ) ; } prev . pickedShapes = nextPickedShapes ; } ;