-
-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathnetwork_graph.py
More file actions
40 lines (28 loc) · 921 Bytes
/
network_graph.py
File metadata and controls
40 lines (28 loc) · 921 Bytes
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
import random
import reactpy
react_cytoscapejs = reactpy.web.module_from_template(
"react",
"react-cytoscapejs",
fallback="⌛",
)
Cytoscape = reactpy.web.export(react_cytoscapejs, "default")
@reactpy.component
def RandomNetworkGraph():
return Cytoscape(
{
"style": {"width": "100%", "height": "200px"},
"elements": random_network(20),
"layout": {"name": "cose"},
}
)
def random_network(number_of_nodes):
conns = []
nodes = [{"data": {"id": 0, "label": 0}}]
for src_node_id in range(1, number_of_nodes + 1):
tgt_node = random.choice(nodes)
src_node = {"data": {"id": src_node_id, "label": src_node_id}}
new_conn = {"data": {"source": src_node_id, "target": tgt_node["data"]["id"]}}
nodes.append(src_node)
conns.append(new_conn)
return nodes + conns
reactpy.run(RandomNetworkGraph)