<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>Graph | Random nodes</title>
|
|
|
|
<style type="text/css">
|
|
body {
|
|
font: 10pt sans;
|
|
}
|
|
#mygraph {
|
|
width: 600px;
|
|
height: 600px;
|
|
border: 1px solid lightgray;
|
|
}
|
|
</style>
|
|
|
|
<script type="text/javascript" src="../../dist/vis.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
var nodes = null;
|
|
var edges = null;
|
|
var graph = null;
|
|
|
|
function draw() {
|
|
nodes = [];
|
|
edges = [];
|
|
var connectionCount = [];
|
|
|
|
// randomly create some nodes and edges
|
|
var nodeCount = document.getElementById('nodeCount').value;
|
|
for (var i = 0; i < nodeCount; i++) {
|
|
nodes.push({
|
|
id: i,
|
|
label: String(i)
|
|
});
|
|
|
|
connectionCount[i] = 0;
|
|
|
|
// create edges in a scale-free-graph 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 graph
|
|
var container = document.getElementById('mygraph');
|
|
var data = {
|
|
nodes: nodes,
|
|
edges: edges
|
|
};
|
|
/*
|
|
var options = {
|
|
nodes: {
|
|
shape: 'circle'
|
|
},
|
|
edges: {
|
|
length: 50
|
|
},
|
|
stabilize: false
|
|
};
|
|
*/
|
|
var options = {
|
|
edges: {
|
|
},
|
|
stabilize: false
|
|
};
|
|
graph = new vis.Graph(container, data, options);
|
|
|
|
// add event listeners
|
|
graph.on('select', function(params) {
|
|
document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes;
|
|
});
|
|
}
|
|
</script>
|
|
</head>
|
|
|
|
<body onload="draw();">
|
|
<form onsubmit="draw(); return false;">
|
|
<label for="nodeCount">Number of nodes:</label>
|
|
<input id="nodeCount" type="text" value="25" style="width: 50px;">
|
|
<input type="submit" value="Go">
|
|
</form>
|
|
<input type="radio" name="physicsMethod" value="Barnes Hut" checked="checked">Barnes Hut <br />
|
|
<input type="radio" name="physicsMethod" value="Repulsion">Repulsion <br />
|
|
<input type="radio" name="physicsMethod" value="Hierarchical Repulsion">Hierarchical Repulsion <br />
|
|
<table class="graphPhysicsTable">
|
|
<tr>
|
|
<td><b>Barnes Hut</b></td>
|
|
</tr>
|
|
<tr>
|
|
<td>gravitationalConstant</td><td>-500</td><td><input type="range" min="500" max="20000" value="2000" step="50" style="width:300px"></td><td>-20000</td><td><input value="2000"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>centralGravity</td><td>0.0</td><td><input type="range" min="0" max="3" value="0.3" step="0.1" style="width:300px"></td><td>3</td><td><input value="0.03"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>springLength</td><td>0</td><td><input type="range" min="0" max="500" value="100" step="1" style="width:300px"></td><td>500</td><td><input value="100"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>springConstant</td><td>0</td><td><input type="range" min="0" max="0.5" value="0.05" step="0.01" style="width:300px"></td><td>0.5</td><td><input value="0.05"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>damping</td><td>0</td><td><input type="range" min="0" max="0.3" value="0.09" step="0.01" style="width:300px"></td><td>0.3</td><td><input value="0.09"></td>
|
|
</tr>
|
|
</table>
|
|
<table class="graphPhysicsTable">
|
|
<tr>
|
|
<td><b>Repulsion</b></td>
|
|
</tr>
|
|
<tr>
|
|
<td>nodeDistance</td><td>0</td><td><input type="range" min="0" max="300" value="100" step="50" style="width:300px"></td><td>300</td><td><input value="100"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>centralGravity</td><td>0.0</td><td><input type="range" min="0" max="3" value="0.1" step="0.1" style="width:300px"></td><td>3</td><td><input value="0.01"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>springLength</td><td>0</td><td><input type="range" min="0" max="500" value="200" step="1" style="width:300px"></td><td>500</td><td><input value="200"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>springConstant</td><td>0</td><td><input type="range" min="0" max="0.5" value="0.05" step="0.01" style="width:300px"></td><td>0.5</td><td><input value="0.05"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>damping</td><td>0</td><td><input type="range" min="0" max="0.3" value="0.09" step="0.01" style="width:300px"></td><td>0.3</td><td><input value="0.09"></td>
|
|
</tr>
|
|
</table>
|
|
<table class="graphPhysicsTable">
|
|
<tr>
|
|
<td><b>Hierarchical Repulsion</b></td>
|
|
</tr>
|
|
<tr>
|
|
<td>nodeDistance</td><td>0</td><td><input type="range" min="0" max="300" value="60" step="50" style="width:300px"></td><td>300</td><td><input value="60"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>centralGravity</td><td>0.0</td><td><input type="range" min="0" max="3" value="0" step="0.1" style="width:300px"></td><td>3</td><td><input value="0"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>springLength</td><td>0</td><td><input type="range" min="0" max="500" value="100" step="1" style="width:300px"></td><td>500</td><td><input value="100"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>springConstant</td><td>0</td><td><input type="range" min="0" max="0.5" value="0.01" step="0.01" style="width:300px"></td><td>0.5</td><td><input value="0.01"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>damping</td><td>0</td><td><input type="range" min="0" max="0.3" value="0.09" step="0.01" style="width:300px"></td><td>0.3</td><td><input value="0.09"></td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
|
|
<div id="mygraph"></div>
|
|
|
|
<p id="selection"></p>
|
|
</body>
|
|
</html>
|