Browse Source

fixed maxZoom

zsviczian 2 years ago
parent
commit
b82a0749b1
1 changed files with 20 additions and 30 deletions
  1. 20 30
      src/renderer/renderElement.ts

+ 20 - 30
src/renderer/renderElement.ts

@@ -108,42 +108,32 @@ export const cappedElementCanvasSize = (
   if (isLinearElement(element) || isFreeDrawElement(element)) {
   if (isLinearElement(element) || isFreeDrawElement(element)) {
     const [x1, y1, x2, y2] = getElementAbsoluteCoords(element);
     const [x1, y1, x2, y2] = getElementAbsoluteCoords(element);
 
 
-    let width =
-      distance(x1, x2) * window.devicePixelRatio * zoomValue +
-      padding * zoomValue * 2;
-    let height =
-      distance(y1, y2) * window.devicePixelRatio * zoomValue +
-      padding * zoomValue * 2;
-
-    const size = width * height;
+    let width = distance(x1, x2) * window.devicePixelRatio + padding * 2;
+    let height = distance(y1, y2) * window.devicePixelRatio + padding * 2;
+
+    const size = width * height * zoomValue * zoomValue;
     if (size > sizelimit) {
     if (size > sizelimit) {
-      zoomValue = Math.sqrt(sizelimit / size) as NormalizedZoomValue;
-      width =
-        distance(x1, x2) * window.devicePixelRatio * zoomValue +
-        padding * zoomValue * 2;
-      height =
-        distance(y1, y2) * window.devicePixelRatio * zoomValue +
-        padding * zoomValue * 2;
+      zoomValue = Math.sqrt(
+        sizelimit / (width * height),
+      ) as NormalizedZoomValue;
+      width = distance(x1, x2) * window.devicePixelRatio + padding * 2;
+      height = distance(y1, y2) * window.devicePixelRatio + padding * 2;
     }
     }
+    width *= zoomValue;
+    height *= zoomValue;
     return { width, height, zoomValue };
     return { width, height, zoomValue };
   }
   }
-  let width =
-    element.width * window.devicePixelRatio * zoomValue +
-    padding * zoomValue * 2;
-  let height =
-    element.height * window.devicePixelRatio * zoomValue +
-    padding * zoomValue * 2;
-
-  const size = width * height;
+  let width = element.width * window.devicePixelRatio + padding * 2;
+  let height = element.height * window.devicePixelRatio + padding * 2;
+
+  const size = width * height * zoomValue * zoomValue;
   if (size > sizelimit) {
   if (size > sizelimit) {
-    zoomValue = Math.sqrt(sizelimit / size) as NormalizedZoomValue;
-    width =
-      element.width * window.devicePixelRatio * zoomValue +
-      padding * zoomValue * 2;
-    height =
-      element.height * window.devicePixelRatio * zoomValue +
-      padding * zoomValue * 2;
+    zoomValue = Math.sqrt(sizelimit / (width * height)) as NormalizedZoomValue;
+    width = element.width * window.devicePixelRatio + padding * 2;
+    height = element.height * window.devicePixelRatio + padding * 2;
   }
   }
+  width *= zoomValue;
+  height *= zoomValue;
   return { width, height, zoomValue };
   return { width, height, zoomValue };
 };
 };