forked from compas-teaching/COMPAS-II-FS2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path524_partial_order.py
56 lines (38 loc) · 1010 Bytes
/
524_partial_order.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from compas.datastructures import Network
from compas_plotters import Plotter
n = Network()
n.add_edge(1, 2)
n.add_edge(1, 3)
n.add_edge(1, 5)
n.add_edge(1, 7)
n.add_edge(2, 4)
n.add_edge(2, 6)
n.add_edge(2, 10)
n.add_edge(3, 6)
n.add_edge(3, 9)
n.add_edge(4, 8)
n.add_edge(5, 10)
print(n.summary())
visited = set()
def layout(node, y=1):
if node in visited:
return
visited.add(node)
nodes_in_row = list(n.nodes_where({"y": y}))
n.node_attributes(node, "xyz", [len(nodes_in_row), y, 0])
for nb in n.neighbors_out(node):
layout(nb, y + 1)
root = 1
layout(root)
plotter = Plotter(figsize=(12, 7.5))
artist = plotter.add(n)
artist.node_size = 2
# Workaround until this is merged: https://github.com/compas-dev/compas/pull/1029
artist._nodecollection.remove()
artist._edgecollection.remove()
artist._nodecollection = None
artist._edgecollection = None
artist.draw()
artist.draw_nodelabels(dict(zip(n.nodes(), n.nodes())))
plotter.zoom_extents()
plotter.show()