From 9b171f071c50b0e41c769b122e496193c62f5dee Mon Sep 17 00:00:00 2001
From: unknown <david.hoksza@gmail.com>
Date: Tue, 29 Oct 2019 16:18:06 +0100
Subject: [PATCH] handling compoartments overlaps

---
 talent/layout_merge.py | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/talent/layout_merge.py b/talent/layout_merge.py
index c31229d..58cfd13 100644
--- a/talent/layout_merge.py
+++ b/talent/layout_merge.py
@@ -299,12 +299,7 @@ def resolve_compartments_overlap(g_cc: nx.MultiGraph, gs: List[nx.MultiGraph], c
                 lt.pan(gs[ix], min_shift)
 
 
-
-
-
-def handle_overlaps(g_cc: nx.MultiGraph, gs: List[nx.MultiGraph]):
-
-    #First we group the connected components by compartment name
+def get_compartment_dict(gs: List[nx.MultiGraph]) -> Dict[str, List[int]]:
     cmp_ix: Dict[str, List[int]] = {}
     for i in range(len(gs)):
         cmp_name: str = gu.get_first_species(gs[i]).get_compartment_name()
@@ -312,6 +307,16 @@ def handle_overlaps(g_cc: nx.MultiGraph, gs: List[nx.MultiGraph]):
             cmp_ix[cmp_name] = []
         cmp_ix[cmp_name].append(i)
 
+    return cmp_ix
+
+
+
+def handle_overlaps(g_cc: nx.MultiGraph, gs: List[nx.MultiGraph], cmp_ix: Dict[str, List[int]]):
+
+
+    #First we group the connected components by compartment name
+
+
     cmp_names = list(cmp_ix)
     for i in range(len(cmp_ix)):
         cmp_name1 = cmp_names[i]
@@ -323,14 +328,19 @@ def handle_overlaps(g_cc: nx.MultiGraph, gs: List[nx.MultiGraph]):
             if bb1.intersects_rectangle(bb2):
                 resolve_compartments_overlap(g_cc, gs, cmp_ix[cmp_name1], cmp_ix[cmp_name2], bb1, bb2)
 
-def optimize_layout(g_cc, gs):
+def clear_spaces(g_cc, gs):
+    NotImplemented
+
+def optimize_layout(g_cc, gs, cmp_ix):
     NotImplemented
 
 
 def layout_ccs(g_cc: nx.MultiGraph, gs: List[nx.MultiGraph]):
     # https://pypi.org/project/forcelayout/
     initial_layout(g_cc, gs)
-    handle_overlaps(g_cc, gs)
+    cmp_ix = get_compartment_dict(gs)
+    handle_overlaps(g_cc, gs, cmp_ix)
+    clear_spaces(g_cc, gs, cmp_ix)
     optimize_layout(g_cc, gs)
     # layout = fl.draw_spring_layout(dataset=dataset, algorithm=fl.SpringForce)
 
-- 
GitLab