-
Notifications
You must be signed in to change notification settings - Fork 289
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
how to get a graph with less spacing? #510
Comments
@dcsan one thing that you can try is set a maximum distance for the repelling force that acts between every pair of nodes. This force has the intent of spreading the graph out, but when you have disconnected groups it can cause them to drift apart. Setting a max distance of influence can counter act this. You need to calibrate the many-body d3Force. Something like: myGraphRef.current.d3Force('charge').distanceMax(100); // adjust to taste |
@vasturiano For others coming by you need these bits. const graphRef = useRef<any>(null);
useEffect(() => {
graphRef?.current?.d3Force('charge').distanceMax(40); // adjust to taste
}, [])
// then in the graph component
return (
<ForceGraph2D
ref={graphRef} I was thinking I might be able to modify other props. eg // works:
graphRef?.current?.d3Force('charge').distanceMax(40);
// works with a glitch
setTimeout(() => {
graphRef?.current?.zoomToFit();
}, 500)
// doesn't work!
graphRef?.current?.d3Force('gravity').strength(0.1); tried various permutations and digging into the source to try and see how to set this: also the client side debugger -> it maybe worth turning this into a discussion as having access to the d3 settings opens a lot of other possibilities! |
@dcsan there is no force called "gravity" by default in the system. The only 3 forces active by default are "charge", "link" and "center". You can read a bit more about it in the docs here: https://github.com/vasturiano/react-force-graph?tab=readme-ov-file#force-engine-configuration |
I have some graphs that end up looking like the below. are there any parameters to draw the force-graph nodes tighter together, especially for un-connected nodes?
I can't just make the nodes bigger as that will create overlaps on connected items.
The text was updated successfully, but these errors were encountered: