Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about handling onNodeClick function #329

Open
Yass525 opened this issue Aug 8, 2023 · 1 comment
Open

Question about handling onNodeClick function #329

Yass525 opened this issue Aug 8, 2023 · 1 comment

Comments

@Yass525
Copy link

Yass525 commented Aug 8, 2023

Hello!

I'm currently using the force-graph library in my project and I'm trying to understand how the onNodeClick function is being handled internally. I'm having trouble locating where the event listener or function call for this event is in the codebase.

I've reviewed the documentation and source code, but I couldn't find the exact location where the onNodeClick or others (onNodeRightClick, onLickClick ...) function is being triggered. Could you please provide some guidance on this? I want to understand the internals better to customize the behavior to my project's requirements.

Thank you for your help!

@vasturiano
Copy link
Owner

container.addEventListener('pointerup', ev => {
state.isPointerPressed = false;
if (state.isPointerDragging) {
state.isPointerDragging = false;
return; // don't trigger click events after pointer drag (pan / node drag functionality)
}
const cbEvents = [ev, state.pointerDownEvent];
requestAnimationFrame(() => { // trigger click events asynchronously, to allow hoverObj to be set (on frame)
if (ev.button === 0) { // mouse left-click or touch
if (state.hoverObj) {
const fn = state[`on${state.hoverObj.type}Click`];
fn && fn(state.hoverObj.d, ...cbEvents);
} else {
state.onBackgroundClick && state.onBackgroundClick(...cbEvents);
}
}
if (ev.button === 2) { // mouse right-click
if (state.hoverObj) {
const fn = state[`on${state.hoverObj.type}RightClick`];
fn && fn(state.hoverObj.d, ...cbEvents);
} else {
state.onBackgroundRightClick && state.onBackgroundRightClick(...cbEvents);
}
}
});
}, { passive: true });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants