From efff5533e193c6f23aa6504a5a9c286f61891107 Mon Sep 17 00:00:00 2001 From: pomelo-nwu Date: Mon, 6 Jan 2025 10:36:26 +0800 Subject: [PATCH] feat: add edge hover --- packages/studio-graph/src/graph/hooks/useInit.tsx | 11 ++++++++++- packages/studio-graph/src/graph/types.ts | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/studio-graph/src/graph/hooks/useInit.tsx b/packages/studio-graph/src/graph/hooks/useInit.tsx index 769940f2..b6c06cec 100644 --- a/packages/studio-graph/src/graph/hooks/useInit.tsx +++ b/packages/studio-graph/src/graph/hooks/useInit.tsx @@ -24,7 +24,7 @@ export const useInit = () => { const height = containerRef.current.offsetHeight; let graph: ForceGraphInstance | ForceGraph3DInstance | null = null; engineStopped.current = false; - console.log('init.......'); + if (render === '2D') { graph = ForceGraph()(containerRef.current); graph @@ -45,6 +45,9 @@ export const useInit = () => { }) .onLinkClick(edge => { emitterRef.current?.emit('edge:click', edge); + }) + .onLinkHover(edge => { + emitterRef.current?.emit('edge:hover', edge); }); } if (render === '3D') { @@ -55,6 +58,9 @@ export const useInit = () => { .onNodeClick(node => { emitterRef.current?.emit('node:click', node); }) + .onNodeHover((node, prevNode) => { + emitterRef.current?.emit('node:hover', { node, prevNode }); + }) .onNodeRightClick((node, evt) => { emitterRef.current?.emit('node:contextmenu', { node, evt }); }) @@ -63,6 +69,9 @@ export const useInit = () => { }) .onLinkClick(edge => { emitterRef.current?.emit('edge:click', edge); + }) + .onLinkHover((edge, prevEdge) => { + emitterRef.current?.emit('edge:hover', { edge, prevEdge }); }); } diff --git a/packages/studio-graph/src/graph/types.ts b/packages/studio-graph/src/graph/types.ts index bc069df9..b06f66e3 100644 --- a/packages/studio-graph/src/graph/types.ts +++ b/packages/studio-graph/src/graph/types.ts @@ -9,6 +9,7 @@ export type EventType = | 'node:hover' | 'canvas:click' | 'edge:click' + | 'edge:hover' | 'combo:click'; export type Emitter = EEmitter>;