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.

107 lines
2.4 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. function a() {
  60. var clusterOptionsByData = {
  61. joinCondition: function (node) {
  62. if (node.id == 4 || node.id == 101)
  63. return true;
  64. return false;
  65. },
  66. clusterNodeProperties: {id: "c1", label: 'c1'}
  67. }
  68. network.cluster(clusterOptionsByData);
  69. }
  70. function b() {
  71. var clusterOptionsByData2 = {
  72. joinCondition: function (node) {
  73. if (node.id == 'c1' || node.id == 5)
  74. return true;
  75. return false;
  76. },
  77. clusterNodeProperties: {id: "c2", label: 'c2'}
  78. }
  79. network.cluster(clusterOptionsByData2);
  80. }
  81. a()
  82. b()
  83. network.openCluster("c2")
  84. </script>
  85. <input type="button" value="a" onclick="a()">
  86. <input type="button" value="b" onclick="b()">
  87. </body>
  88. </html>