clicking on nodes in the graph is enabled

This commit is contained in:
Shoofle 2024-12-18 14:17:15 -05:00
parent 796afba4f5
commit 8bc89d502f

View File

@ -10,6 +10,21 @@ import { fetchGraph } from '../apiTools.jsx';
import ForceSupervisor from 'graphology-layout-force/worker'; import ForceSupervisor from 'graphology-layout-force/worker';
function GraphEvents() {
const navigate = useNavigate();
const registerEvents = useRegisterEvents();
useEffect(() => {
// Register the events
registerEvents({
// node events
clickNode: (event) => navigate(`/${event.node}`),
});
}, [registerEvents]);
return null;
}
export default function GraphRender() { export default function GraphRender() {
const { isPending, error, data } = useQuery({ // fetch the currrent values const { isPending, error, data } = useQuery({ // fetch the currrent values
queryKey: ['graph'], queryKey: ['graph'],
@ -26,27 +41,14 @@ export default function GraphRender() {
} }
}, [data]); }, [data]);
/*
const navigate = useNavigate();
const registerEvents = useRegisterEvents();
useEffect(() => {
console.log("register events");
// Register the events
registerEvents({
// node events
clickNode: (event) => navigate(`/${event.node}`),
});
}, [registerEvents]);
*/
if (isPending) return "Loading..."; if (isPending) return "Loading...";
else if (error) return `Error encountered: ${error}`; else if (error) return `Error encountered: ${error}`;
else return ( else return (
<SigmaContainer <SigmaContainer
settings={{allowInvalidContainer: true}} settings={{allowInvalidContainer: true}}
graph={data} graph={data}
style={{height: "400px", width: "100%", background: 'rgba(0,0,0,0)'}} style={{height: "400px", width: "100%", background: 'rgba(0,0,0,0)'}}>
/> <GraphEvents/>
</SigmaContainer>
); );
} }