From cebfbc2ce39befaa5c2454a740a3250286b676de Mon Sep 17 00:00:00 2001
From: madelinegr <mgriswold99@gmail.com>
Date: Thu, 13 Jun 2019 20:07:05 -0400
Subject: zoom partial work

---
 .../collectionFreeForm/CollectionFreeFormView.tsx    | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

(limited to 'src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx')

diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 1a1614ac7..dc1bb5866 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -271,10 +271,30 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument) {
         newState.initializers[id] = { panX: newPanX, panY: newPanY };
         HistoryUtil.pushState(newState);
         this.setPan(newPanX, newPanY);
+        this.setScaleToZoom(doc);
         this.props.Document.panTransformType = "Ease";
         this.props.focus(this.props.Document);
     }
 
+    setScaleToZoom = (doc: Doc) => {
+        let p = this.props;
+        let PanelHeight = p.PanelHeight();
+        let panelWidth = p.PanelWidth();
+        // let heightDif: number = PanelHeight - NumCast(doc.height);
+        // let widthDif: number = panelWidth - NumCast(doc.width);
+        let docHeight = NumCast(doc.height);
+        let docWidth = NumCast(doc.width);
+        let targetHeight = 0.8 * PanelHeight;
+        let targetWidth = 0.8 * panelWidth;
+
+        let maxScaleX: number = targetWidth / docWidth;
+        let maxScaleY: number = targetHeight / docHeight;
+        // let maxScaleX: number = NumCast(doc.width) / (panelWidth - 10);
+        // let maxScaleY: number = NumCast(doc.height) / (PanelHeight - 10);
+        let maxApplicableScale = Math.min(maxScaleX, maxScaleY);
+        this.Document.scale = maxApplicableScale;
+    }
+
 
     getDocumentViewProps(document: Doc): DocumentViewProps {
         return {
-- 
cgit v1.2.3-70-g09d2

