<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>Network | Clustering</title>
|
|
|
|
<script type="text/javascript" src="../dist/vis.js"></script>
|
|
|
|
|
|
<style type="text/css">
|
|
#mynetwork {
|
|
width: 600px;
|
|
height: 600px;
|
|
border: 1px solid lightgray;
|
|
}
|
|
|
|
p {
|
|
max-width: 600px;
|
|
}
|
|
|
|
h4 {
|
|
margin-bottom: 3px;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<div id="mynetwork"></div>
|
|
|
|
<script type="text/javascript">
|
|
// create an array with nodes
|
|
var nodes = [
|
|
{id: 4, label: '4'},
|
|
{id: 5, label: '5'},
|
|
{id: 7, label: '7'},
|
|
{id: 9, label: '9'},
|
|
{id: 10, label: '10'},
|
|
{id: 101, label: '101'},
|
|
{id: 102, label: '102'},
|
|
{id: 103, label: '103'}
|
|
];
|
|
|
|
// create an array with edges
|
|
var edges = [
|
|
{from: 10, to: 4},
|
|
{from: 7, to: 5},
|
|
{from: 9, to: 7},
|
|
{from: 10, to: 9},
|
|
{from: 101, to: 102},
|
|
{from: 102, to: 103}
|
|
];
|
|
|
|
// create a network
|
|
var container = document.getElementById('mynetwork');
|
|
var data = {
|
|
nodes: nodes,
|
|
edges: edges
|
|
};
|
|
var options = {layout: {randomSeed: 8}};
|
|
var network = new vis.Network(container, data, options);
|
|
|
|
|
|
|
|
// if we click on a node, we want to open it up!
|
|
network.on("selectNode", function (params) {
|
|
if (params.nodes.length == 1) {
|
|
if (network.isCluster(params.nodes[0]) == true) {
|
|
network.openCluster(params.nodes[0])
|
|
}
|
|
}
|
|
});
|
|
|
|
function a() {
|
|
var clusterOptionsByData = {
|
|
joinCondition: function (node) {
|
|
if (node.id == 4 || node.id == 101)
|
|
return true;
|
|
return false;
|
|
},
|
|
clusterNodeProperties: {id: "c1", label: 'c1'}
|
|
}
|
|
network.cluster(clusterOptionsByData);
|
|
}
|
|
|
|
function b() {
|
|
var clusterOptionsByData2 = {
|
|
joinCondition: function (node) {
|
|
if (node.id == 'c1' || node.id == 5)
|
|
return true;
|
|
return false;
|
|
},
|
|
clusterNodeProperties: {id: "c2", label: 'c2'}
|
|
}
|
|
network.cluster(clusterOptionsByData2);
|
|
}
|
|
|
|
a()
|
|
b()
|
|
network.openCluster("c2")
|
|
</script>
|
|
<input type="button" value="a" onclick="a()">
|
|
<input type="button" value="b" onclick="b()">
|
|
|
|
</body>
|
|
</html>
|