From 237e077afc0fdeef3b968efd5af937a9f64879b0 Mon Sep 17 00:00:00 2001 From: Alex Dawes Date: Wed, 19 Aug 2020 11:26:22 +0100 Subject: [PATCH] Improve the way that zoom level is calculated in the fitView function --- src/store/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/store/index.ts b/src/store/index.ts index 208df4ee..b9b287df 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -403,8 +403,9 @@ export const storeModel: StoreModel = { } const bounds = getRectOfNodes(nodes); - const maxBoundsSize = Math.max(bounds.width, bounds.height); - const zoom = Math.min(width, height) / (maxBoundsSize + maxBoundsSize * padding); + const xZoom = width / (bounds.width * (1 + padding)); + const yZoom = height / (bounds.height * (1 + padding)); + const zoom = Math.min(xZoom, yZoom); const clampedZoom = clamp(zoom, minZoom, maxZoom); const boundsCenterX = bounds.x + bounds.width / 2; const boundsCenterY = bounds.y + bounds.height / 2;