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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
<!doctype html>
<html>
<head>
<title>Network | Animation</title>
<style type="text/css">
body {
font: 10pt sans;
}
#mynetwork {
width: 600px;
height: 600px;
border: 1px solid lightgray;
}
div.left {
position:relative;
float:left;
width:300px;
border: 1px #c7c7c7 solid;
height:590px;
padding:5px;
}
div.right {
padding-left:10px;
float:left;
width:600px;
}
div.bottom {
position:absolute;
bottom:5px;
}
</style>
<script type="text/javascript" src="../exampleUtil.js"></script>
<script type="text/javascript" src="../../../dist/vis.js"></script>
<link href="../../../dist/vis-network.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var nodes = null;
var edges = null;
var network = null;
var offsetx, offsety, scale, positionx, positiony, duration, easingFunction, doButton, focusButton, showButton;
var statusUpdateSpan;
var finishMessage = '';
var showInterval = false;
var showPhase = 1;
var amountOfNodes = 25;
function destroy() {
if (network !== null) {
network.destroy();
network = null;
}
}
function updateValues() {
offsetx = parseInt(document.getElementById('offsetx').value);
offsety = parseInt(document.getElementById('offsety').value);
duration = parseInt(document.getElementById('duration').value);
scale = parseFloat(document.getElementById('scale').value);
positionx = parseInt(document.getElementById('positionx').value);
positiony = parseInt(document.getElementById('positiony').value);
easingFunction = document.getElementById('easingFunction').value;
}
function draw() {
destroy();
statusUpdateSpan = document.getElementById('statusUpdate');
doButton = document.getElementById('btnDo');
focusButton = document.getElementById('btnFocus');
showButton = document.getElementById('btnShow');
// randomly create some nodes and edges
var data = getScaleFreeNetwork(amountOfNodes);
// create a network
var container = document.getElementById('mynetwork');
var options = {
physics: {
stabilization: {
iterations: 1200
}
}
};
network = new vis.Network(container, data, options);
// add event listeners
network.on('select', function(params) {
document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes;
});
network.on('stabilized', function (params) {
document.getElementById('stabilization').innerHTML = 'Stabilization took ' + params.iterations + ' iterations.';
});
network.on('animationFinished', function() {
statusUpdateSpan.innerHTML = finishMessage;
})
}
function fitAnimated() {
updateValues();
var options = {offset: {x:offsetx,y:offsety},
duration: duration,
easingFunction: easingFunction
};
statusUpdateSpan.innerHTML = 'Doing fit() Animation.';
finishMessage = 'Animation finished.';
network.fit({animation:options});
}
function doDefaultAnimation() {
updateValues();
var options = {
position: {x:positionx,y:positiony},
scale: scale,
offset: {x:offsetx,y:offsety},
animation: true // default duration is 1000ms and default easingFunction is easeInOutQuad.
};
statusUpdateSpan.innerHTML = 'Doing Animation.';
finishMessage = 'Animation finished.';
network.moveTo(options);
}
function doAnimation() {
updateValues();
var options = {
position: {x:positionx,y:positiony},
scale: scale,
offset: {x:offsetx,y:offsety},
animation: {
duration: duration,
easingFunction: easingFunction
}
};
statusUpdateSpan.innerHTML = 'Doing Animation.';
finishMessage = 'Animation finished.';
network.moveTo(options);
}
function focusRandom() {
updateValues();
var nodeId = Math.floor(Math.random() * amountOfNodes);
var options = {
// position: {x:positionx,y:positiony}, // this is not relevant when focusing on nodes
scale: scale,
offset: {x:offsetx,y:offsety},
animation: {
duration: duration,
easingFunction: easingFunction
}
};
statusUpdateSpan.innerHTML = 'Focusing on node: ' + nodeId;
finishMessage = 'Node: ' + nodeId + ' in focus.';
network.focus(nodeId, options);
}
function startShow() {
updateValues();
if (showInterval !== false) {
showInterval = false;
showButton.value = 'Start a show!';
network.fit();
}
else {
showButton.value = 'Stop the show!';
focusRandom();
setTimeout(doTheShow, duration);
showInterval = true;
}
}
function doTheShow() {
updateValues();
if (showInterval == true) {
if (showPhase == 0) {
focusRandom();
showPhase = 1;
}
else {
fitAnimated();
showPhase = 0;
}
setTimeout(doTheShow, duration);
}
}
</script>
<script src="../../googleAnalytics.js"></script>
</head>
<body onload="draw();">
<h2>Camera animations</h2>
<div style="width:700px; font-size:14px;">
You can move the view around programmatically using the .moveTo(options) function. The options supplied to this function can
also be (partially) supplied to the .fit() and .focusOnNode() methods. These are explained in the docs.
<br /><br/>
The buttons below take the fields from the table when they can. For instance, the "Animate with default settings." takes the position, scale and offset while using
the default animation values for duration and easing function. The focusOnNode takes everything except the position and the fit takes only the duration and easing function.
<br/><br/>
Here you can see a full description of the options you can supply to moveTo:
</div>
<pre>
var moveToOptions = {
position: {x:x, y:x}, // position to animate to (Numbers)
scale: 1.0, // scale to animate to (Number)
offset: {x:x, y:y}, // offset from the center in DOM pixels (Numbers)
animation: { // animation object, can also be Boolean
duration: 1000, // animation duration in milliseconds (Number)
easingFunction: "easeInOutQuad" // Animation easing function, available are:
} // linear, easeInQuad, easeOutQuad, easeInOutQuad,
} // easeInCubic, easeOutCubic, easeInOutCubic,
// easeInQuart, easeOutQuart, easeInOutQuart,
// easeInQuint, easeOutQuint, easeInOutQuint
</pre>
<div class="left">
<table>
<tr>
<td>position x</td><td><input type="text" value="300" id="positionx" style="width:170px;"></td>
</tr>
<tr>
<td>position y</td><td><input type="text" value="300" id="positiony" style="width:170px;"></td>
</tr>
<tr>
<td>scale</td><td><input type="text" value="1.0" id="scale" style="width:170px;"></td>
</tr>
<tr>
<td>offset x</td><td><input type="text" value="0" id="offsetx" style="width:170px;"> px</td>
</tr>
<tr>
<td>offset y</td><td><input type="text" value="0" id="offsety" style="width:170px;"> px</td>
</tr>
<tr>
<td>duration</td><td><input type="text" value="1000" id="duration" style="width:170px;"> ms</td>
</tr>
<tr>
<td>easingFunction</td><td>
<select id="easingFunction" style="width:174px;">
<option value="linear">linear</option>
<option value="easeInQuad">easeInQuad</option>
<option value="easeOutQuad">easeOutQuad</option>
<option value="easeInOutQuad" selected="selected">easeInOutQuad</option>
<option value="easeInCubic">easeInCubic</option>
<option value="easeOutCubic">easeOutCubic</option>
<option value="easeInOutCubic">easeInOutCubic</option>
<option value="easeInQuart">easeInQuart</option>
<option value="easeOutQuart">easeOutQuart</option>
<option value="easeInOutQuart">easeInOutQuart</option>
<option value="easeInQuint">easeInQuint</option>
<option value="easeOutQuint">easeOutQuint</option>
<option value="easeInOutQuint">easeInOutQuint</option>
</select>
</td>
</tr>
</table>
<div class="bottom">
<span id="statusUpdate"></span><br />
Examples:
<input type="button" onclick="doAnimation();" value="Animate with above settings." style="width:300px;" id="btnDo"> <br/>
<input type="button" onclick="doDefaultAnimation();" value="Animate with default settings." style="width:300px;" id="btnDoDefault"> <br/>
<input type="button" onclick="fitAnimated();" value="Animated fit()." style="width:300px;" id="btnZoom"> <br/>
<input type="button" onclick="focusRandom();" value="Focus on random node." style="width:300px;" id="btnFocus"><br/>
<input type="button" onclick="startShow();" value="Start a show!" style="width:300px;" id="btnShow"><br/>
</div>
</div>
<div class="right">
<div id="mynetwork"></div>
<p id="selection"></p>
<p id="stabilization"></p>
</div>
</body>
</html>
|