From e7835fc640e3ce0d50a98a55392a21ef8658af4f Mon Sep 17 00:00:00 2001
From: Kristóf Marussy <kristof@marussy.com>
Date: Mon, 4 Sep 2023 22:03:40 +0200
Subject: refactor: disable all animations for large graphs

---
 subprojects/frontend/src/graph/ZoomCanvas.tsx | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

(limited to 'subprojects/frontend/src/graph/ZoomCanvas.tsx')

diff --git a/subprojects/frontend/src/graph/ZoomCanvas.tsx b/subprojects/frontend/src/graph/ZoomCanvas.tsx
index 2bb7f139..0254bc59 100644
--- a/subprojects/frontend/src/graph/ZoomCanvas.tsx
+++ b/subprojects/frontend/src/graph/ZoomCanvas.tsx
@@ -34,10 +34,11 @@ export type ChangeZoomCallback = (factor: number) => void;
 
 export type SetFitZoomCallback = (fitZoom: boolean) => void;
 
-export type FitZoomCallback = (newSize?: {
+export type FitZoomCallback = ((newSize?: {
   width: number;
   height: number;
-}) => void;
+}) => void) &
+  ((newSize: boolean) => void);
 
 export default function ZoomCanvas({
   children,
@@ -79,7 +80,7 @@ export default function ZoomCanvas({
       }
       let width = 0;
       let height = 0;
-      if (newSize === undefined) {
+      if (newSize === undefined || typeof newSize === 'boolean') {
         const elementRect = elementRef.current.getBoundingClientRect();
         const currentFactor = d3.zoomTransform(canvasRef.current).k;
         width = elementRect.width / currentFactor;
@@ -96,8 +97,11 @@ export default function ZoomCanvas({
         (canvasRect.width - 2 * fitPaddingOrDefault) / width,
         (canvasRect.height - 2 * fitPaddingOrDefault) / height,
       );
-      const zoomTransition = makeTransition(canvasRef.current);
-      zoomRef.current.transform(zoomTransition, d3.zoomIdentity.scale(factor));
+      const target =
+        newSize === false
+          ? d3.select(canvasRef.current)
+          : makeTransition(canvasRef.current);
+      zoomRef.current.transform(target, d3.zoomIdentity.scale(factor));
     },
     [fitPaddingOrDefault, makeTransition],
   );
-- 
cgit v1.2.3-54-g00ecf

