<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>Network | Playing with Physics</title>
|
|
|
|
<style type="text/css">
|
|
body {
|
|
font: 10pt sans;
|
|
}
|
|
#mynetwork {
|
|
width: 600px;
|
|
height: 600px;
|
|
border: 1px solid lightgray;
|
|
}
|
|
</style>
|
|
|
|
<script type="text/javascript" src="../../dist/vis.js"></script>
|
|
<link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
|
|
|
|
<script type="text/javascript">
|
|
var nodes = null;
|
|
var edges = null;
|
|
var network = null;
|
|
|
|
function draw() {
|
|
nodes = [];
|
|
edges = [];
|
|
var connectionCount = [];
|
|
|
|
// randomly create some nodes and edges
|
|
var nodeCount = 60;
|
|
for (var i = 0; i < nodeCount; i++) {
|
|
nodes.push({
|
|
id: i,
|
|
label: String(i)
|
|
});
|
|
|
|
connectionCount[i] = 0;
|
|
|
|
// create edges in a scale-free-network way
|
|
if (i == 1) {
|
|
var from = i;
|
|
var to = 0;
|
|
edges.push({
|
|
from: from,
|
|
to: to
|
|
});
|
|
connectionCount[from]++;
|
|
connectionCount[to]++;
|
|
}
|
|
else if (i > 1) {
|
|
var conn = edges.length * 2;
|
|
var rand = Math.floor(Math.random() * conn);
|
|
var cum = 0;
|
|
var j = 0;
|
|
while (j < connectionCount.length && cum < rand) {
|
|
cum += connectionCount[j];
|
|
j++;
|
|
}
|
|
|
|
|
|
var from = i;
|
|
var to = j;
|
|
edges.push({
|
|
from: from,
|
|
to: to
|
|
});
|
|
connectionCount[from]++;
|
|
connectionCount[to]++;
|
|
}
|
|
}
|
|
|
|
// create a network
|
|
var container = document.getElementById('mynetwork');
|
|
var data = {
|
|
nodes: nodes,
|
|
edges: edges
|
|
};
|
|
|
|
var options = {
|
|
stabilize: false,
|
|
configurePhysics:true
|
|
};
|
|
network = new vis.Network(container, data, options);
|
|
|
|
// add event listeners
|
|
network.on('select', function(params) {
|
|
document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes;
|
|
});
|
|
}
|
|
</script>
|
|
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></head>
|
|
|
|
<body onload="draw();">
|
|
|
|
<h2>Playing with Physics</h2>
|
|
<div style="width: 700px; font-size:14px; text-align: justify;">
|
|
Every dataset is different. Nodes can have different sizes based on content, interconnectivity can be high or low etc. Because of this, network has a special option
|
|
that the user can use to explore which settings may be good for him or her. This is ment to be used during the development phase when you are implementing vis.js. Once you have found
|
|
settings you are happy with, you can supply them to network using the documented physics options.
|
|
|
|
On start, the default settings will be loaded. Keep in mind that selecting the hierarchical simulation mode <b>disables</b> smooth curves. These will not be enabled again afterwards.
|
|
</div>
|
|
<br />
|
|
<div id="mynetwork"></div>
|
|
|
|
<p id="selection"></p>
|
|
</body>
|
|
</html>
|