<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>Network | Hierarchical layout</title>
|
|
|
|
<style type="text/css">
|
|
body {
|
|
font: 10pt sans;
|
|
}
|
|
|
|
#mynetwork {
|
|
width: 1700px;
|
|
height: 800px;
|
|
border: 1px solid lightgray;
|
|
}
|
|
</style>
|
|
|
|
<script type="text/javascript" src="../exampleUtil.js"></script>
|
|
<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 destroy() {
|
|
if (network !== null) {
|
|
network.destroy();
|
|
network = null;
|
|
}
|
|
}
|
|
|
|
function draw() {
|
|
destroy();
|
|
|
|
nodes = [];
|
|
edges = [];
|
|
// randomly create some nodes and edges
|
|
var nodeCount = document.getElementById('nodeCount').value;
|
|
for (var i = 0; i < 19; i++) {
|
|
nodes.push({id: i, label: String(i)});
|
|
}
|
|
edges.push({from: 0, to: 1});
|
|
edges.push({from: 0, to: 6});
|
|
edges.push({from: 0, to: 13});
|
|
edges.push({from: 0, to: 11});
|
|
edges.push({from: 1, to: 2});
|
|
edges.push({from: 2, to: 3});
|
|
edges.push({from: 2, to: 4});
|
|
edges.push({from: 3, to: 5});
|
|
edges.push({from: 1, to: 10});
|
|
edges.push({from: 1, to: 7});
|
|
edges.push({from: 2, to: 8});
|
|
edges.push({from: 2, to: 9});
|
|
edges.push({from: 3, to: 14});
|
|
edges.push({from: 1, to: 12});
|
|
edges.push({from: 16, to: 15});
|
|
edges.push({from: 15, to: 17});
|
|
edges.push({from: 18, to: 17});
|
|
|
|
var container = document.getElementById('mynetwork');
|
|
var data = {
|
|
nodes: nodes,
|
|
edges: edges
|
|
};
|
|
var directionInput = document.getElementById("direction").value;
|
|
var options = {
|
|
layout: {
|
|
hierarchical: {
|
|
sortMethod: 'hubsize',
|
|
direction: directionInput
|
|
}
|
|
},
|
|
physics:false
|
|
};
|
|
network = new vis.Network(container, data, options);
|
|
fireall()
|
|
// add event listeners
|
|
network.on('select', function (params) {
|
|
document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes;
|
|
});
|
|
}
|
|
|
|
function fireall() {
|
|
if (callbackIndex < CALLBACKS.length -1) {
|
|
CALLBACKS[callbackIndex]();
|
|
callbackIndex++;
|
|
fireall()
|
|
}
|
|
}
|
|
function fireCallback() {
|
|
if (callbackIndex < CALLBACKS.length -1) {
|
|
CALLBACKS[callbackIndex]();
|
|
callbackIndex++;
|
|
}
|
|
else {
|
|
alert("no more callbacks");
|
|
}
|
|
|
|
}
|
|
|
|
var callbackIndex = 0;
|
|
var CALLBACKS = [];
|
|
|
|
</script>
|
|
<script src="../../googleAnalytics.js"></script>
|
|
</head>
|
|
|
|
<body onload="draw();">
|
|
<h2>Hierarchical Layout - Scale-Free-Network</h2>
|
|
|
|
<div style="width:700px; font-size:14px; text-align: justify;">
|
|
This example shows the randomly generated <b>scale-free-network</b> set of nodes and connected edges from example 2.
|
|
In this example, hierarchical layout has been enabled and the vertical levels are determined automatically.
|
|
</div>
|
|
<br/>
|
|
|
|
<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>
|
|
<p>
|
|
<input type="button" id="btn-UD" value="Up-Down">
|
|
<input type="button" id="btn-DU" value="Down-Up">
|
|
<input type="button" id="btn-LR" value="Left-Right">
|
|
<input type="button" id="btn-RL" value="Right-Left">
|
|
<input type="hidden" id='direction' value="UD">
|
|
</p>
|
|
|
|
<script language="javascript">
|
|
var directionInput = document.getElementById("direction");
|
|
var btnUD = document.getElementById("btn-UD");
|
|
btnUD.onclick = function () {
|
|
directionInput.value = "UD";
|
|
draw();
|
|
}
|
|
var btnDU = document.getElementById("btn-DU");
|
|
btnDU.onclick = function () {
|
|
directionInput.value = "DU";
|
|
draw();
|
|
};
|
|
var btnLR = document.getElementById("btn-LR");
|
|
btnLR.onclick = function () {
|
|
directionInput.value = "LR";
|
|
draw();
|
|
};
|
|
var btnRL = document.getElementById("btn-RL");
|
|
btnRL.onclick = function () {
|
|
directionInput.value = "RL";
|
|
draw();
|
|
};
|
|
</script>
|
|
<br>
|
|
|
|
<div id="mynetwork"></div>
|
|
|
|
<p id="selection"></p>
|
|
</body>
|
|
</html>
|