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
3.5 KiB

  1. <!doctype html>
  2. <html>
  3. <head><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script>
  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. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  17. <script type="text/javascript">
  18. var nodes = null;
  19. var edges = null;
  20. var network = null;
  21. function destroy() {
  22. if (network !== null) {
  23. network.destroy();
  24. network = null;
  25. }
  26. }
  27. function draw() {
  28. destroy();
  29. nodes = [];
  30. edges = [];
  31. // randomly create some nodes and edges
  32. var nodeCount = parseInt(document.getElementById('nodeCount').value);
  33. for (var i = 0; i < nodeCount; i++) {
  34. nodes.push({
  35. id: i,
  36. label: String(i)
  37. });
  38. }
  39. for (var i = 0; i < nodeCount; i++) {
  40. var from = i;
  41. var to = i;
  42. to = i;
  43. while (to == i) {
  44. to = Math.floor(Math.random() * (nodeCount));
  45. }
  46. edges.push({
  47. from: from,
  48. to: to
  49. });
  50. }
  51. // create a network
  52. var clusteringOn = document.getElementById('clustering').checked;
  53. var container = document.getElementById('mynetwork');
  54. var data = {
  55. nodes: nodes,
  56. edges: edges
  57. };
  58. var options = {
  59. physics: {barnesHut:{springLength:120}}, // this is the correct way to set the length of the springs
  60. clustering: {
  61. enabled: clusteringOn
  62. },
  63. stabilize: false
  64. };
  65. network = new vis.Network(container, data, options);
  66. // add event listeners
  67. network.on('select', function(params) {
  68. document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes;
  69. });
  70. }
  71. </script>
  72. </head>
  73. <body onload="draw();">
  74. <h2>Clustering - Fully random network</h2>
  75. <div style="width:700px; font-size:14px; text-align: justify;">
  76. This example shows a fully randomly generated set of nodes and connected edges.
  77. By clicking the checkbox you can turn clustering on and off. If you increase the number of nodes to
  78. a value higher than 100, automatic clustering is used before the initial draw (assuming the checkbox is checked).
  79. <br />
  80. <br />
  81. 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
  82. will be created and the cluster contents will only be simulated in there. Double click will also open a cluster.
  83. <br />
  84. <br />
  85. Try values of 500 and 5000 with and without clustering. All thresholds can be changed to suit your dataset.
  86. </div>
  87. <br />
  88. <form onsubmit="draw(); return false;">
  89. <label for="nodeCount">Number of nodes:</label>
  90. <input id="nodeCount" type="text" value="50" style="width: 50px;">
  91. <label for="clustering">Enable Clustering:</label>
  92. <input id="clustering" type="checkbox" onChange="draw()" checked="true">
  93. <input type="submit" value="Go">
  94. </form>
  95. <br>
  96. <div id="mynetwork"></div>
  97. <p id="selection"></p>
  98. </body>
  99. </html>