From 9f3fa1d6e2ca47280fc2fd238794fdec8e364044 Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Tue, 8 Jan 2019 13:37:35 +0100
Subject: [PATCH] feat: sliceview resize dynamically fixes #101 chore:
 housekeeping

---
 src/atlasViewer/atlasViewer.template.html     |  1 -
 .../nehubaContainer.component.ts              | 20 +++++++++++++++++--
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/atlasViewer/atlasViewer.template.html b/src/atlasViewer/atlasViewer.template.html
index 04f4b488d..85b14f2af 100644
--- a/src/atlasViewer/atlasViewer.template.html
+++ b/src/atlasViewer/atlasViewer.template.html
@@ -174,7 +174,6 @@
   </layout-floating-container>
 
   <div pluginFactoryDirective>
-
   </div>
 
 </div>
diff --git a/src/ui/nehubaContainer/nehubaContainer.component.ts b/src/ui/nehubaContainer/nehubaContainer.component.ts
index 9c8496ccf..095e983f2 100644
--- a/src/ui/nehubaContainer/nehubaContainer.component.ts
+++ b/src/ui/nehubaContainer/nehubaContainer.component.ts
@@ -349,7 +349,15 @@ export class NehubaContainer implements OnInit, OnDestroy{
 
     /* order of subscription will determine the order of execution */
     this.subscriptions.push(
-      this.newViewer$.subscribe((state)=>{
+      this.newViewer$.pipe(
+        map(state => {
+          const deepCopiedState = JSON.parse(JSON.stringify(state))
+          const navigation = deepCopiedState.templateSelected.nehubaConfig.dataset.initialNgState.navigation
+          navigation.zoomFactor = calculateSliceZoomFactor(navigation.zoomFactor)
+          deepCopiedState.templateSelected.nehubaConfig.dataset.initialNgState.navigation = navigation
+          return deepCopiedState
+        })
+      ).subscribe((state)=>{
 
         this.nehubaViewerSubscriptions.forEach(s=>s.unsubscribe())
 
@@ -652,6 +660,10 @@ export class NehubaContainer implements OnInit, OnDestroy{
 
   private createNewNehuba(template:any){
 
+    /**
+     * TODO if plugin subscribes to viewerHandle, and then new template is selected, changes willl not be be sent
+     * could be considered as a bug. 
+     */
     this.apiService.interactiveViewer.viewerHandle = null
 
     this.viewerLoaded = true
@@ -1049,4 +1061,8 @@ export const userLmUnchanged = (oldlms, newlms) => {
 
   return oldlms.every(lm => singleLmUnchanged(lm, newmap as Map<string,[number,number,number]>))
     && newlms.every(lm => singleLmUnchanged(lm, oldmap as Map<string, [number,number,number]>))
-}
\ No newline at end of file
+}
+
+export const calculateSliceZoomFactor = (originalZoom) => originalZoom
+  ? 700 * originalZoom / Math.min(window.innerHeight, window.innerWidth)
+  : 1e7
\ No newline at end of file
-- 
GitLab