-
Notifications
You must be signed in to change notification settings - Fork 8
/
demo.html
175 lines (148 loc) · 4.44 KB
/
demo.html
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE>
<html>
<head>
<title>cytoscape-avsdf.js demo</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<script src="https://unpkg.com/cytoscape/dist/cytoscape.min.js"></script>
<!--polyfills are needed for this extension for old browsers like IE -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.5.7/shim.min.js"></script>
<script src="https://unpkg.com/layout-base/layout-base.js"></script>
<script src="https://unpkg.com/avsdf-base/avsdf-base.js"></script>
<script src="cytoscape-avsdf.js"></script>
<style>
body {
font-family: helvetica;
font-size: 15px;
}
#cy {
width: 100%;
height: 90%;
z-index: 999;
}
h1 {
opacity: 0.5;
font-size: 1em;
font-weight: bold;
}
button {
font-size: 15px;
margin-right: 10px;
}
.line {
clear:left;
height:25px;
margin-top:6px;
margin-right:6px;
margin-bottom:6px;
}
.radio {
margin-left:25px;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function(){
var cy = window.cy = cytoscape({
container: document.getElementById('cy'),
layout: {
name: 'avsdf',
nodeSeparation: 120
},
style: [
{
selector: 'node',
style: {
'label': 'data(id)',
'text-valign': 'center',
'color': '#000000',
'background-color': '#3a7ecf'
}
},
{
selector: 'edge',
style: {
'width': 2,
'line-color': '#3a7ecf',
'opacity': 0.5
}
}
],
elements: {
nodes: [
{ data: { id: 'v1', weight: 1} },
{ data: { id: 'v2', weight: 2} },
{ data: { id: 'v3', weight: 3} },
{ data: { id: 'v4', weight: 4} },
{ data: { id: 'v5', weight: 5} },
{ data: { id: 'v6', weight: 6} },
{ data: { id: 'v7', weight: 7} }
],
edges: [
{ data: { source: 'v1', target: 'v2', directed: 'false'} },
{ data: { source: 'v1', target: 'v4', directed: 'false'} },
{ data: { source: 'v1', target: 'v5', directed: 'false'} },
{ data: { source: 'v2', target: 'v4', directed: 'false'} },
{ data: { source: 'v2', target: 'v6', directed: 'false'} },
{ data: { source: 'v3', target: 'v4', directed: 'false'} },
{ data: { source: 'v3', target: 'v7', directed: 'false'} },
{ data: { source: 'v4', target: 'v5', directed: 'false'} },
{ data: { source: 'v4', target: 'v7', directed: 'false'} },
{ data: { source: 'v5', target: 'v6', directed: 'false'} },
{ data: { source: 'v6', target: 'v7', directed: 'false'} },
{ data: { source: 'v6', target: 'v3', directed: 'false'} }
]
}
});
document.getElementById("layoutButton").addEventListener("click", function(){
if(document.getElementById("end").checked) {
var layout = cy.layout({
name: 'avsdf',
animate: "end",
animationDuration: 1000,
animationEasing: 'ease-in-out',
nodeSeparation: 120
});
} else{
var layout = cy.layout({
name: 'avsdf',
refresh: 1,
animate: "during",
animationDuration: 1000,
animationEasing: 'ease-in-out',
nodeSeparation: 120
});
}
layout.run();
});
document.getElementById("randomize").addEventListener("click", function(){
cy.nodes().forEach(function(ele){
ele.data().weight = Math.floor((Math.random() * 10) + 1);
});
var layout = cy.layout({
name: 'circle',
animate: true,
sort: function(a, b){ return a.data('weight') - b.data('weight') },
radius: 120,
animationDuration: 1000,
animationEasing: 'ease-in-out'
});
layout.run();
});
});
</script>
</head>
<body>
<h1>cytoscape-avsdf demo</h1>
<div class="line">
Animation Type:
<input type="radio" name="radio" id="end" class="radio" value="end" checked> End
<input type="radio" name="radio" id="during" class="radio" value="during"> During <br>
</div>
<a data-toggle="tooltip" data-placement="auto" title="Places the nodes circularly as a randomly permuted sequence">
<button id="randomize" type="button">Randomize</button>
</a>
<a data-toggle="tooltip" data-placement="auto" title="Places the nodes circularly with respect to AVSDF layout">
<button id="layoutButton" type="button">AVSDF</button>
</a>
<div id="cy"></div>
</body>
</html>