zoomToFit on new graphData, not on Node repositioning (or other user interactions) #531
Unanswered
fordmaxson
asked this question in
Q&A
Replies: 1 comment
-
@fordmaxson thanks for reaching out. You could make it apply just the first time around. Something like: const [makeItFit, setMakeItFit] = useState(true);
...
onEngineStop={() => {
if (makeItFit) {
fgRef.current.zoomToFit(400);
setMakeItFit(false);
}
}} If later you want to re-enable the fitting (on new data load for instance), you just need to do |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
https://github.com/vasturiano/react-force-graph/blob/master/example/fit-to-canvas/index.html
show the use of
return <ForceGraph2D
ref={fgRef}
graphData={data}
cooldownTicks={100}
onEngineStop={() => fgRef.current.zoomToFit(400)}
/>;
for zoomToFit. While that works perfectly when new graphData is provide to render a new graph, when the user drags a node to a new location, that also cause the entire graph to zoom back out. Is there a way to control zoomToFit for initial data load versus other graph manipulation? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions