import { useRegisterEvents , useSigma } from "react-sigma-v2" ; import { FC , useEffect } from "react" ; function getMouseLayer ( ) { return document . querySelector ( ".sigma-mouse" ) ; } const GraphEventsController = ( { setHoveredNode , children } ) => { const sigma = useSigma ( ) ; const graph = sigma . getGraph ( ) ; const registerEvents = useRegisterEvents ( ) ; /**
     * Initialize here settings that require to know the graph and/or the sigma
     * instance:
     */ useEffect ( ( ) => { registerEvents ( { clickNode ( { node } ) { if ( ! graph . getNodeAttribute ( node , "hidden" ) ) { window . open ( graph . getNodeAttribute ( node , "URL" ) , "_blank" ) ; } } , enterNode ( { node } ) { setHoveredNode ( node ) ; const mouseLayer = getMouseLayer ( ) ; if ( mouseLayer ) mouseLayer . classList . add ( "mouse-pointer" ) ; } , leaveNode ( ) { setHoveredNode ( null ) ; const mouseLayer = getMouseLayer ( ) ; if ( mouseLayer ) mouseLayer . classList . remove ( "mouse-pointer" ) ; } , } ) ; } , [ ] ) ; return < > { children } < />; } ; export default GraphEventsController ;