@@ -138,15 +138,11 @@ export const ForceGraph = forwardRef<any, ForceGraphProps>(
|
||||
}
|
||||
};
|
||||
|
||||
// Fit zoom on engine stop
|
||||
useEffect(() => {
|
||||
if (ref && typeof ref === "object" && ref.current) {
|
||||
const timer = setTimeout(() => {
|
||||
ref.current?.zoomToFit(400);
|
||||
}, 100);
|
||||
return () => clearTimeout(timer);
|
||||
const handleEngineStop = () => {
|
||||
if (typeof ref !== "function" && ref && "current" in ref && ref.current) {
|
||||
ref.current.zoomToFit(400);
|
||||
}
|
||||
}, [data, ref]);
|
||||
};
|
||||
|
||||
return (
|
||||
<div ref={containerRef} className="w-full h-full relative">
|
||||
@@ -180,6 +176,7 @@ export const ForceGraph = forwardRef<any, ForceGraphProps>(
|
||||
d3AlphaDecay={0.03}
|
||||
d3VelocityDecay={0.4}
|
||||
warmupTicks={50}
|
||||
onEngineStop={handleEngineStop}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user