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.

115 lines
3.0 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: 1, label: '1'},
  26. {id: 2, label: '2'},
  27. {id: 3, label: '3'},
  28. {id: 4, label: '4'},
  29. {id: 'a', label: 'a'},
  30. {id: 'b', label: 'b'},
  31. {id: 'c', label: 'c'},
  32. {id: 'd', label: 'd'}
  33. ];
  34. // create an array with edges
  35. var edges = [
  36. {from: '1', to: '2', arrows:'to'},
  37. {from: '2', to: '3', arrows:'to'},
  38. {from: '3', to: '4', arrows:'to'},
  39. {from: 'a', to: 'b', arrows:'to'},
  40. {from: 'b', to: 'c', arrows:'to'},
  41. {from: 'c', to: 'd', arrows:'to'}
  42. ];
  43. // create a network
  44. var container = document.getElementById('mynetwork');
  45. var data = {
  46. nodes: nodes,
  47. edges: edges
  48. };
  49. var options = {
  50. interaction: {
  51. navigationButtons: true
  52. },
  53. layout: {randomSeed: 8}
  54. };
  55. var network = new vis.Network(container, data, options);
  56. // if we click on a node, we want to open it up!
  57. network.on("selectNode", function (params) {
  58. if (params.nodes.length == 1) {
  59. if (network.isCluster(params.nodes[0]) == true) {
  60. network.openCluster(params.nodes[0])
  61. }
  62. }
  63. });
  64. setTimeout(function() {
  65. // alert("Clustering 2 and 'b'");
  66. var clusterOptionsByData = {
  67. joinCondition: function(node) {
  68. if (node.id == '2' || node.id == 'b')
  69. return true;
  70. return false;
  71. },
  72. clusterNodeProperties: {id:"c1", label:'c1'}
  73. }
  74. network.cluster(clusterOptionsByData);
  75. }, 1)
  76. setTimeout(function() {
  77. // alert("Clustering 4 and 'd'");
  78. var clusterOptionsByData = {
  79. joinCondition: function(node) {
  80. if (node.id == '4' || node.id == 'd')
  81. return true;
  82. return false;
  83. },
  84. clusterNodeProperties: {id:"c2", label:'c2'}
  85. }
  86. network.cluster(clusterOptionsByData);
  87. }, 100)
  88. setTimeout(function() {
  89. // alert('Changing to UD layout');
  90. customLayout = { hierarchical: { direction: "UD" } };
  91. network.setOptions({layout: customLayout});
  92. }, 300)
  93. // setTimeout(function() {
  94. // alert('Changing to DEFAULT layout, but does not work');
  95. // customLayout = {};
  96. // network.setOptions({"layout": {
  97. // "hierarchical": {
  98. // "enabled": false
  99. // }
  100. // }});
  101. // }, 15000)
  102. </script>
  103. </body>
  104. </html>