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.

110 lines
2.5 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Clustering</title>
  5. <script type="text/javascript" src="../dist/vis.js"></script>
  6. <style type="text/css">
  7. #mynetwork {
  8. width: 600px;
  9. height: 600px;
  10. border: 1px solid lightgray;
  11. }
  12. p {
  13. max-width: 600px;
  14. }
  15. h4 {
  16. margin-bottom: 3px;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div id="mynetwork"></div>
  22. <script type="text/javascript">
  23. // create an array with nodes
  24. var nodes = [
  25. {id: 4, label: '4'},
  26. {id: 5, label: '5'},
  27. {id: 7, label: '7'},
  28. {id: 9, label: '9'},
  29. {id: 10, label: '10'},
  30. {id: 101, label: '101'},
  31. {id: 102, label: '102'},
  32. {id: 103, label: '103'}
  33. ];
  34. // create an array with edges
  35. var edges = [
  36. {from: 10, to: 4},
  37. {from: 7, to: 5},
  38. {from: 9, to: 7},
  39. {from: 10, to: 9},
  40. {from: 101, to: 102},
  41. {from: 102, to: 103}
  42. ];
  43. // create a network
  44. var container = document.getElementById('mynetwork');
  45. var data = {
  46. nodes: nodes,
  47. edges: edges
  48. };
  49. var options = {layout: {randomSeed: 8}};
  50. var network = new vis.Network(container, data, options);
  51. // if we click on a node, we want to open it up!
  52. network.on("selectNode", function (params) {
  53. if (params.nodes.length == 1) {
  54. if (network.isCluster(params.nodes[0]) == true) {
  55. network.openCluster(params.nodes[0])
  56. }
  57. }
  58. });
  59. setTimeout(function() {
  60. // alert("clustering 4 and 101")
  61. var clusterOptionsByData = {
  62. joinCondition: function(node) {
  63. if (node.id == 4 || node.id == 101)
  64. return true;
  65. return false;
  66. },
  67. clusterNodeProperties: {id:"c1", label:'c1'}
  68. }
  69. network.cluster(clusterOptionsByData);
  70. network.stabilize()
  71. },500)
  72. setTimeout(function() {
  73. // alert("clustering c1 and 5")
  74. var clusterOptionsByData2 = {
  75. joinCondition: function(node) {
  76. if (node.id == 'c1' || node.id == 5)
  77. return true;
  78. return false;
  79. },
  80. clusterNodeProperties: {id:"c2", label:'c2'}
  81. }
  82. network.cluster(clusterOptionsByData2);
  83. },2000)
  84. /*
  85. setTimeout(function () {
  86. alert("opening c2")
  87. network.openCluster("c2")
  88. },3000)
  89. */
  90. </script>
  91. </body>
  92. </html>