-
-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathusage-multiple-instances.py
127 lines (121 loc) · 4.4 KB
/
usage-multiple-instances.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""
Original Demo: http://js.cytoscape.org/demos/multiple-instances/
"""
import dash
from dash import html
import dash_cytoscape as cyto
app = dash.Dash(__name__)
server = app.server
elements = [
{"data": {"id": "a", "foo": 3, "bar": 5, "baz": 7}},
{"data": {"id": "b", "foo": 7, "bar": 1, "baz": 3}},
{"data": {"id": "c", "foo": 2, "bar": 7, "baz": 6}},
{"data": {"id": "d", "foo": 9, "bar": 5, "baz": 2}},
{"data": {"id": "e", "foo": 2, "bar": 4, "baz": 5}},
{"data": {"id": "ae", "weight": 1, "source": "a", "target": "e"}},
{"data": {"id": "ab", "weight": 3, "source": "a", "target": "b"}},
{"data": {"id": "be", "weight": 4, "source": "b", "target": "e"}},
{"data": {"id": "bc", "weight": 5, "source": "b", "target": "c"}},
{"data": {"id": "ce", "weight": 6, "source": "c", "target": "e"}},
{"data": {"id": "cd", "weight": 2, "source": "c", "target": "d"}},
{"data": {"id": "de", "weight": 7, "source": "d", "target": "e"}},
]
# App
app.layout = html.Div(
[
cyto.Cytoscape(
id="cytoscape-top",
elements=elements,
layout={"name": "circle", "padding": 10},
stylesheet=[
{
"selector": "node",
"style": {
"background-color": "#B3767E",
"width": "mapData(baz, 0, 10, 10, 40)",
"height": "mapData(baz, 0, 10, 10, 40)",
"content": "data(id)",
},
},
{
"selector": "edge",
"style": {
"line-color": "#F2B1BA",
"target-arrow-color": "#F2B1BA",
"width": 2,
"target-arrow-shape": "circle",
"opacity": 0.8,
},
},
{
"selector": ":selected",
"style": {
"background-color": "black",
"line-color": "black",
"target-arrow-color": "black",
"source-arrow-color": "black",
"opacity": 1,
},
},
{"selector": ".faded", "style": {"opacity": 0.25, "text-opacity": 0}},
],
style={
"width": "100%",
"height": "50%",
"position": "absolute",
"background-color": "#FAEDEF",
"left": 0,
"top": 0,
},
),
cyto.Cytoscape(
id="cytoscape-bottom",
elements=elements,
layout={"name": "breadthfirst", "directed": True, "padding": 10},
stylesheet=[
{
"selector": "node",
"style": {
"background-color": "#6272A3",
"shape": "rectangle",
"width": "mapData(foo, 0, 10, 10, 30)",
"height": "mapData(bar, 0, 10, 10, 50)",
"content": "data(id)",
},
},
{
"selector": "edge",
"style": {
"width": "mapData(weight, 0, 10, 3, 9)",
"line-color": "#B1C1F2",
"target-arrow-color": "#B1C1F2",
"target-arrow-shape": "triangle",
"opacity": 0.8,
},
},
{
"selector": ":selected",
"style": {
"background-color": "black",
"line-color": "black",
"target-arrow-color": "black",
"source-arrow-color": "black",
"opacity": 1,
},
},
{"selector": ".faded", "style": {"opacity": 0.25, "text-opacity": 0}},
],
style={
"width": "100%",
"height": "50%",
"position": "absolute",
"background-color": "#EDF1FA",
"left": 0,
"top": "50%",
"border-top": "1px solid #ccc",
},
),
]
)
if __name__ == "__main__":
app.run(debug=True)