vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

89 lines
2.6 KiB

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script type="text/javascript" src="../dist/vis.js"></script>
<style>
#mynetwork {
width: 700px;
height: 450px;
border: 1px solid lightgray;
}
</style>
<script>
var network = null;
function destroy() {
if (network !== null) {
network.destroy();
network = null;
}
}
function draw() {
destroy();
var container = document.getElementById('mynetwork');
var nodes = new vis.DataSet();
var edges = new vis.DataSet();
data = {
nodes: nodes,
edges:edges
}
options = {
edges: {
arrows:{
to: true
},
smooth:{
enabled: true
}
},
layout:{
hierarchical: {
enabled: true
}
},
physics:{
enabled: true,
stabilization: true
},
manipulation:{
enabled:false,
addEdge: function (data, callback) {
setTimeout(function () {network.addEdgeMode();},0);
callback(data);
}
}
};
network = new vis.Network(container, data, options);
var layer1Cnt = 0;
var layer2Cnt = 0;
var layer3Cnt = 0;
document.getElementById("addNodeLayer1").onclick = function(e){
nodes.add({id: "layer1_"+layer1Cnt++, label: 'Layer1-'+layer1Cnt, level: 0});
network.addEdgeMode();
}
document.getElementById("addNodeLayer2").onclick = function(e){
nodes.add({id: "layer2_"+layer2Cnt++, label: 'Layer2-'+layer2Cnt, level:1});
network.addEdgeMode();
}
document.getElementById("addNodeLayer3").onclick = function(e){
nodes.add({id: "layer3_"+layer3Cnt++, label: 'Layer3-'+layer3Cnt, level:2});
network.addEdgeMode();
}
}
</script>
</head>
<body onLoad="draw()">
<button id="addNodeLayer1">Layer 1</button>
<button id="addNodeLayer2">Layer 2</button>
<button id="addNodeLayer3">Layer 3</button>
<div id="mynetwork"></div>
</body>
</html>