Просмотр исходного кода

Various fixes to notebook version

Yentl Van Tendeloo 7 лет назад
Родитель
Сommit
02495b53c5
2 измененных файлов с 45 добавлено и 137 удалено
  1. 25 124
      Untitled.ipynb
  2. 20 13
      wrappers/modelverse.py

Разница между файлами не показана из-за своего большого размера
+ 25 - 124
Untitled.ipynb


+ 20 - 13
wrappers/modelverse.py

@@ -690,6 +690,7 @@ def show(model_name):
     group_counter = 0
     todo_edges = []
     locations = {}
+    text_skip = 15
 
     if is_scd:
         for elem in result:
@@ -715,6 +716,8 @@ 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
@@ -726,13 +729,13 @@ 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, y = 30 + (group_counter * 250) % 1000, 30 + ((group_counter // 4) * 250)
             locations[element_id] = (x, y)
             group_counter += 1
 
             # Add the text elements
             # First the header
-            texts.append({"text": "%s : %s" % (element_id, element_type), "x": x + 10, "y": y + 10})
+            texts.append({"text": "%s : %s" % (element_id, element_type), "x": x + 10, "y": y + text_skip})
             max_text = max(len(texts[-1]["text"]), max_text)
             # Then the attributes
             text_counter = 1
@@ -741,13 +744,14 @@ def show(model_name):
                 text = "%s : %s" % (name, names.get(attr_type, "(%s)" % attr_type))
                 if optional:
                     text = text.replace(" : ", " ?: ")
-                texts.append({"text": text, "x": x + 10, "y": y + 25 + text_counter * 11})
+                texts.append({"text": text, "x": x + 10, "y": y + text_skip * 1.25 + text_counter * text_skip})
                 max_text = max(len(text), max_text)
                 text_counter += 1
 
             if text_counter > 1:
                 text_counter += 1
 
+            y_loc_edge = y + text_skip + text_counter * text_skip
             for key, value in attrs.items():
                 if isinstance(value, dict):
                     if value["AL"] == "":
@@ -756,28 +760,31 @@ def show(model_name):
                         text = "%s = ^%s" % (key, value['AL'])
                 else:
                     text = ("%s = %s" % (key, value)) if value is not None else ("(%s)" % key)
-                texts.append({"text": text, "x": x + 10, "y": y + 25 + text_counter * 11})
+                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
 
             # Add the rectangle
-            rectangles.append({"x": x, "y": y, "width": max_text * 8, "height": 35 + text_counter * 11})
+            rectangles.append({"x": x, "y": y, "width": max_text * 9 + 10, "height": text_skip * 3 + text_counter * text_skip})
 
             # Add the line
-            edges.append({"sx": x, "sy": y + 20, "tx": x + max_text * 8, "ty": y + 20})
+            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})
 
-    for edge in todo_edges:
-        edges.append({"sx": locations[edge["source"]][0] + edge["source_x"], "sy": locations[edge["source"]][1] + edge["source_y"], "tx": locations[edge["target"]][0] + edge["target_x"], "ty": locations[edge["target"]][1]})
+        max_x = max(max_x, x + max_text * 9 + 10)
+        max_y = max(max_y, y + text_skip * 3 + text_counter * text_skip)
+
+    data_content = '<svg width="%s" height="%s">' % (max_x + 30, max_y + 30)
 
-    print("Got rectangles: " + str(rectangles))
-    print("Got edges: " + str(edges))
-    print("Got text: " + str(texts))
+    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"])
 
-    data_content = '<svg width="1000" height="800">'
     for rec in rectangles:
         data_content += '<rect x="%s" y="%s" width="%s" height="%s" fill="white" stroke="black"/>' % (rec["x"], rec["y"], rec["width"], rec["height"])
+
     for edge in edges:
-        data_content += '<line x1="%s" y1="%s" x2="%s" y2="%s" fill="black"/>' % (edge["sx"], edge["sy"], edge["tx"], edge["ty"])
+        data_content += '<line x1="%s" y1="%s" x2="%s" y2="%s" stroke="black"/>' % (edge["sx"], edge["sy"], edge["tx"], edge["ty"])
+
     for text in texts:
         data_content += '<text x="%s" y="%s" fill="black">%s</text>' % (text["x"], text["y"], text["text"])