Skip to content

Commit

Permalink
feat: add edge hover
Browse files Browse the repository at this point in the history
  • Loading branch information
pomelo-nwu committed Jan 6, 2025
1 parent 19eba31 commit efff553
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/studio-graph/src/graph/hooks/useInit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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') {
Expand All @@ -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 });
})
Expand All @@ -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 });
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/studio-graph/src/graph/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type EventType =
| 'node:hover'
| 'canvas:click'
| 'edge:click'
| 'edge:hover'
| 'combo:click';

export type Emitter = EEmitter<Record<EventType, unknown>>;
Expand Down

0 comments on commit efff553

Please sign in to comment.