-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathusage-initialisation.py
105 lines (96 loc) · 3.13 KB
/
usage-initialisation.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
"""
Original Demo: http://js.cytoscape.org/demos/initialisation/
Note: The click-and-drag functionality is broken in this Dash implementation
because the example requires a function referring to the "cy" property, i.e.
```
cy.on('tap', 'node', function(e){
var node = e.cyTarget;
var neighborhood = node.neighborhood().add(node);
cy.elements().addClass('faded');
neighborhood.removeClass('faded');
});
cy.on('tap', function(e){
if( e.cyTarget === cy ){
cy.elements().removeClass('faded');
}
});
```
"""
import dash
from dash import html
import dash_cytoscape as cyto
app = dash.Dash(__name__)
server = app.server
elements = [
{"data": {"id": "j", "name": "Jerry"}},
{"data": {"id": "e", "name": "Elaine"}},
{"data": {"id": "k", "name": "Kramer"}},
{"data": {"id": "g", "name": "George"}},
{"data": {"source": "j", "target": "e"}},
{"data": {"source": "j", "target": "k"}},
{"data": {"source": "j", "target": "g"}},
{"data": {"source": "e", "target": "j"}},
{"data": {"source": "e", "target": "k"}},
{"data": {"source": "k", "target": "j"}},
{"data": {"source": "k", "target": "e"}},
{"data": {"source": "k", "target": "g"}},
{"data": {"source": "g", "target": "j"}},
]
# App
app.layout = html.Div(
[
cyto.Cytoscape(
id="cytoscape",
boxSelectionEnabled=False,
autounselectify=True,
elements=elements,
layout={"name": "grid", "padding": 10},
stylesheet=[
{
"selector": "node",
"style": {
"content": "data(name)",
"text-valign": "center",
"color": "white",
"text-outline-width": 2,
"background-color": "#999",
"text-outline-color": "#999",
},
},
{
"selector": "edge",
"style": {
"curve-style": "bezier",
"target-arrow-shape": "triangle",
"target-arrow-color": "#ccc",
"line-color": "#ccc",
"width": 1,
},
},
{
"selector": ":selected",
"style": {
"background-color": "black",
"line-color": "black",
"target-arrow-color": "black",
"source-arrow-color": "black",
},
},
{
"selector": "edge.questionable",
"style": {"line-style": "dotted", "target-arrow-shape": "diamond"},
},
{"selector": ".faded", "style": {"opacity": 0.25, "text-opacity": 0}},
],
style={
"width": "100%",
"height": "100%",
"position": "absolute",
"left": 0,
"top": 0,
},
)
]
)
if __name__ == "__main__":
app.run(debug=True)