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.

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