From 79fb0595d890e592da0561d7d3b48b9fb87bc8a2 Mon Sep 17 00:00:00 2001 From: Daulet Amirkhanov Date: Thu, 9 Oct 2025 15:22:23 +0100 Subject: [PATCH] feat: fix zoomToFit method usage GraphVisualization --- .../src/app/(graph)/GraphVisualization.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cognee-frontend/src/app/(graph)/GraphVisualization.tsx b/cognee-frontend/src/app/(graph)/GraphVisualization.tsx index 6f66264ca..6846e3aee 100644 --- a/cognee-frontend/src/app/(graph)/GraphVisualization.tsx +++ b/cognee-frontend/src/app/(graph)/GraphVisualization.tsx @@ -217,10 +217,24 @@ export default function GraphVisualization({ ref, data, graphControls, className const [graphShape, setGraphShape] = useState(); + const zoomToFit: ForceGraphMethods["zoomToFit"] = ( + durationMs?: number, + padding?: number, + nodeFilter?: (node: NodeObject) => boolean + ) => { + if (!graphRef.current) { + console.warn("GraphVisualization: graphRef not ready yet"); + return undefined as any; + } + + return graphRef.current.zoomToFit?.(durationMs, padding, nodeFilter); + }; + useImperativeHandle(ref, () => ({ - zoomToFit: graphRef.current!.zoomToFit, - setGraphShape: setGraphShape, + zoomToFit, + setGraphShape, })); + return (