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.

91 lines
2.6 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Random nodes</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. #message {
  15. color:darkred;
  16. max-width:600px;
  17. font-size:16px;
  18. cursor:pointer;
  19. text-decoration: underline;
  20. }
  21. </style>
  22. <script type="text/javascript" src="../exampleUtil.js"></script>
  23. <script type="text/javascript" src="../../../dist/vis.js"></script>
  24. <link href="../../../dist/vis-network.min.css" rel="stylesheet" type="text/css" />
  25. <script type="text/javascript">
  26. var nodes = null;
  27. var edges = null;
  28. var network = null;
  29. var setSmooth = false;
  30. function destroy() {
  31. if (network !== null) {
  32. network.destroy();
  33. network = null;
  34. }
  35. }
  36. function draw() {
  37. destroy();
  38. var nodeCount = document.getElementById('nodeCount').value;
  39. if (nodeCount > 100) {
  40. document.getElementById("message").innerHTML = '<a onclick="disableSmoothCurves()">You may want to disable dynamic smooth curves for better performance with a large amount of nodes and edges. Click here to disable them.</a>';
  41. }
  42. else if (setSmooth === false) {
  43. document.getElementById("message").innerHTML = '';
  44. }
  45. // create a network
  46. var container = document.getElementById('mynetwork');
  47. var data = getScaleFreeNetwork(nodeCount);
  48. var options = {
  49. physics: { stabilization: false }
  50. };
  51. network = new vis.Network(container, data, options);
  52. }
  53. function disableSmoothCurves() {
  54. setSmooth = true;
  55. network.setOptions({edges:{smooth:{type:'continuous'}}});
  56. document.getElementById("message").innerHTML = '<a onclick="enableSmoothCurves()">Click here to reenable the dynamic smooth curves.</a>';
  57. }
  58. function enableSmoothCurves() {
  59. setSmooth = false;
  60. document.getElementById("message").innerHTML = '<a onclick="disableSmoothCurves()">You may want to disable dynamic smooth curves for better performance with a large amount of nodes and edges. Click here to disable them.</a>';
  61. network.setOptions({edges:{smooth:{type:'dynamic'}}});
  62. }
  63. </script>
  64. </head>
  65. <body onload="draw();">
  66. <p>
  67. Generate a random network with nodes and edges.
  68. </p>
  69. <p>
  70. <form onsubmit="draw(); return false;">
  71. <label for="nodeCount">Number of nodes:</label>
  72. <input id="nodeCount" type="text" value="25" style="width: 50px;">
  73. <input type="button" value="Go" onclick="draw()">
  74. </form>
  75. </p>
  76. <span id="message"></span>
  77. <div id="mynetwork"></div>
  78. </body>
  79. </html>