From e9eea220256d592dff95258173a9ae2927f28398 Mon Sep 17 00:00:00 2001
From: Michael Hartung <michi@Michaels-MacBook-Pro.local>
Date: Thu, 29 Jul 2021 10:31:48 +0200
Subject: [PATCH] query node in analysis network

---
 .../analysis-panel.component.ts               |  2 +-
 .../explorer-page.component.html              |  2 +-
 .../explorer-page/explorer-page.component.ts  | 26 +++++++++++--------
 3 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/src/app/components/analysis-panel/analysis-panel.component.ts b/src/app/components/analysis-panel/analysis-panel.component.ts
index f4dd3052..73d7e1d0 100644
--- a/src/app/components/analysis-panel/analysis-panel.component.ts
+++ b/src/app/components/analysis-panel/analysis-panel.component.ts
@@ -79,7 +79,7 @@ export class AnalysisPanelComponent implements OnInit, OnChanges {
   public myConfig: IConfig = JSON.parse(JSON.stringify(defaultConfig));
 
 
-  private network: any;
+  public network: any;
   private nodeData: { nodes: any, edges: any } = {nodes: null, edges: null};
   private drugNodes: any[] = [];
   private drugEdges: any[] = [];
diff --git a/src/app/pages/explorer-page/explorer-page.component.html b/src/app/pages/explorer-page/explorer-page.component.html
index 97633a5b..af08aff3 100644
--- a/src/app/pages/explorer-page/explorer-page.component.html
+++ b/src/app/pages/explorer-page/explorer-page.component.html
@@ -100,7 +100,7 @@
               <span class="icon">
                 <i class="fas fa-search" aria-hidden="true"></i>
               </span>
-              Query Protein/Gene
+              Query Node
             </p>
             <a
               (click)="collapseQuery = !collapseQuery"
diff --git a/src/app/pages/explorer-page/explorer-page.component.ts b/src/app/pages/explorer-page/explorer-page.component.ts
index 8785ee6f..d70e8800 100644
--- a/src/app/pages/explorer-page/explorer-page.component.ts
+++ b/src/app/pages/explorer-page/explorer-page.component.ts
@@ -28,6 +28,7 @@ import {defaultConfig, EdgeGroup, IConfig, InteractionDatabase, NodeGroup} from
 import {NetexControllerService} from 'src/app/services/netex-controller/netex-controller.service';
 import {removeDuplicateObjectsFromList} from '../../utils'
 import * as merge from 'lodash/fp/merge';
+import { AnalysisPanelComponent } from 'src/app/components/analysis-panel/analysis-panel.component';
 
 // import * as 'vis' from 'vis-network';
 // import {DataSet} from 'vis-data';
@@ -180,6 +181,9 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit {
   @ViewChild('network', {static: false}) networkEl: ElementRef;
   @ViewChild('networkWithLegend', {static: false}) networkWithLegendEl: ElementRef;
 
+  @ViewChild(AnalysisPanelComponent, { static: false })
+  private analysisPanel: AnalysisPanelComponent;
+
   constructor(
     public omnipath: OmnipathControllerService,
     public analysis: AnalysisService,
@@ -315,8 +319,11 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit {
   }
 
   private zoomToNode(id: string) {
+    // get network object, depending on whether analysis is open or not
+    const network = this.selectedAnalysisToken ? this.analysisPanel.network : this.networkInternal;
+
     this.nodeData.nodes.getIds();
-    const coords = this.networkInternal.getPositions(id)[id];
+    const coords = network.getPositions(id)[id];
     if (!coords) {
       return;
     }
@@ -326,7 +333,7 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit {
     } else {
       zoomScale = 3.0;
     }
-    this.networkInternal.moveTo({
+    network.moveTo({
       position: {x: coords.x, y: coords.y},
       scale: zoomScale,
       animation: true,
@@ -399,18 +406,15 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit {
       this.closeSummary();
     });
 
-    // // this might be not necessary, positions get saved right before reloding network
-    // this.networkInternal.on('stabilizationIterationsDone', () => {
-    //   this.networkPositions = this.networkInternal.getPositions();
-    // });
-    // this.networkInternal.stabilize();
-
     if (this.selectedWrapper) {
       this.zoomToNode(this.selectedWrapper.id);
     }
 
+    this.currentViewNodes = this.nodeData.nodes;
+    this.currentViewEdges = this.nodeData.edges;
+
     this.queryItems = [];
-    this.fillQueryItems(this.proteins);
+    this.fillQueryItems(this.currentViewNodes);
     if (this.selectedWrapper) {
       this.networkInternal.selectNodes([this.selectedWrapper.id]);
     }
@@ -422,8 +426,7 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit {
       this.queryItems.push(getWrapperFromNode(protein));
     });
 
-    this.currentViewNodes = this.nodeData.nodes;
-    this.currentViewEdges = this.nodeData.edges;
+
     this.currentViewProteins = this.proteins;
   }
 
@@ -587,6 +590,7 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit {
       this.currentViewProteins = this.proteins;
       this.currentViewSelectedTissue = this.selectedTissue;
     }
+    this.fillQueryItems(this.currentViewNodes);
   }
 
   gProfilerLink(): string {
-- 
GitLab