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.

100 lines
3.3 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Fully random nodes clustering</title>
  5. <style type="text/css">
  6. body {
  7. font: 10pt sans;
  8. }
  9. #mynetwork {
  10. width: 600px;
  11. height: 600px;
  12. border: 1px solid lightgray;
  13. }
  14. </style>
  15. <script type="text/javascript" src="../../dist/vis.js"></script>
  16. <script type="text/javascript">
  17. var nodes = null;
  18. var edges = null;
  19. var network = null;
  20. function draw() {
  21. nodes = [];
  22. edges = [];
  23. // randomly create some nodes and edges
  24. var nodeCount = parseInt(document.getElementById('nodeCount').value);
  25. for (var i = 0; i < nodeCount; i++) {
  26. nodes.push({
  27. id: i,
  28. label: String(i)
  29. });
  30. }
  31. for (var i = 0; i < nodeCount; i++) {
  32. var from = i;
  33. var to = i;
  34. to = i;
  35. while (to == i) {
  36. to = Math.floor(Math.random() * (nodeCount));
  37. }
  38. edges.push({
  39. from: from,
  40. to: to
  41. });
  42. }
  43. // create a network
  44. var clusteringOn = document.getElementById('clustering').checked;
  45. var container = document.getElementById('mynetwork');
  46. var data = {
  47. nodes: nodes,
  48. edges: edges
  49. };
  50. var options = {
  51. physics: {barnesHut:{springLength:120}}, // this is the correct way to set the length of the springs
  52. clustering: {
  53. enabled: clusteringOn
  54. },
  55. stabilize: false
  56. };
  57. network = new vis.Network(container, data, options);
  58. // add event listeners
  59. network.on('select', function(params) {
  60. document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes;
  61. });
  62. }
  63. </script>
  64. </head>
  65. <body onload="draw();">
  66. <h2>Clustering - Fully random network</h2>
  67. <div style="width:700px; font-size:14px; text-align: justify;">
  68. This example shows a fully randomly generated set of nodes and connected edges.
  69. By clicking the checkbox you can turn clustering on and off. If you increase the number of nodes to
  70. a value higher than 100, automatic clustering is used before the initial draw (assuming the checkbox is checked).
  71. <br />
  72. <br />
  73. Clustering is done automatically when zooming out. When zooming in over the cluster, the cluster pops open. When the cluster is very big, a special instance
  74. will be created and the cluster contents will only be simulated in there. Double click will also open a cluster.
  75. <br />
  76. <br />
  77. Try values of 500 and 5000 with and without clustering. All thresholds can be changed to suit your dataset.
  78. </div>
  79. <br />
  80. <form onsubmit="draw(); return false;">
  81. <label for="nodeCount">Number of nodes:</label>
  82. <input id="nodeCount" type="text" value="50" style="width: 50px;">
  83. <label for="clustering">Enable Clustering:</label>
  84. <input id="clustering" type="checkbox" onChange="draw()" checked="true">
  85. <input type="submit" value="Go">
  86. </form>
  87. <br>
  88. <div id="mynetwork"></div>
  89. <p id="selection"></p>
  90. </body>
  91. </html>