Browse Source

Updates to visualization for JuPYter

Yentl Van Tendeloo 7 years ago
parent
commit
ebc6fc4131
2 changed files with 35 additions and 11 deletions
  1. 19 2
      Untitled.ipynb
  2. 16 9
      wrappers/modelverse.py

File diff suppressed because it is too large
+ 19 - 2
Untitled.ipynb


+ 16 - 9
wrappers/modelverse.py

@@ -687,10 +687,13 @@ def show(model_name):
 
     defined_attributes = {}
     names = {}
-    group_counter = 0
     todo_edges = []
     locations = {}
     text_skip = 15
+    past_x = 3
+    past_y = 3
+    max_x = 0
+    max_y = 0
 
     if is_scd:
         for elem in result:
@@ -716,8 +719,6 @@ def show(model_name):
             else:
                 attrs[key] = value
         max_text = 0
-        max_x = 0
-        max_y = 0
 
         if is_edge:
             edge_edge = len([x for x in result if (x["__id"] == element_source or x["__id"] == element_target) and "__source" in x]) > 0
@@ -729,9 +730,9 @@ def show(model_name):
                 todo_edges.append({"source": element_source, "target": element_target, "source_x": 0 if edge_edge else 100, "source_y": 0 if edge_edge else 30, "target_x": 100, "target_y": 30})
         else:
             # Add the group
-            x, y = 30 + (group_counter * 250) % 1000, 30 + ((group_counter // 4) * 250)
+            x = past_x
+            y = past_y
             locations[element_id] = (x, y)
-            group_counter += 1
 
             # Add the text elements
             # First the header
@@ -759,7 +760,7 @@ def show(model_name):
                     else:
                         text = "%s = ^%s" % (key, value['AL'])
                 else:
-                    text = ("%s = %s" % (key, value)) if value is not None else ("(%s)" % key)
+                    text = ("%s = %s" % (key, json.dumps(value))) if value is not None else ("(%s)" % key)
                 texts.append({"text": text, "x": x + 10, "y": y + text_skip * 2.5 + text_counter * text_skip})
                 max_text = max(len(text), max_text)
                 text_counter += 1
@@ -771,10 +772,16 @@ def show(model_name):
             edges.append({"sx": x, "sy": y_loc_edge, "tx": x + max_text * 9 + 10, "ty": y_loc_edge})
             edges.append({"sx": x, "sy": y + 20, "tx": x + max_text * 9 + 10, "ty": y + 20})
 
-        max_x = max(max_x, x + max_text * 9 + 10)
-        max_y = max(max_y, y + text_skip * 3 + text_counter * text_skip)
+            past_x = x + max_text * 9 + 30
+            if past_x > 1000:
+                max_x = max(max_x, past_x)
+                past_x = 0
+                past_y = max_y + 30
 
-    data_content = '<svg width="%s" height="%s">' % (max_x + 30, max_y + 30)
+            max_x = max(max_x, past_x)
+            max_y = max(max_y, past_y + text_skip * 3 + text_counter * text_skip)
+
+    data_content = '<svg width="%s" height="%s">' % (max_x + 3, max_y + 3)
 
     for edge in todo_edges:
         data_content += '<line x1="%s" y1="%s" x2="%s" y2="%s" stroke="black"/>' % (locations[edge["source"]][0] + edge["source_x"], locations[edge["source"]][1] + edge["source_y"], locations[edge["target"]][0] + edge["target_x"], locations[edge["target"]][1] + edge["target_y"])