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.

117 lines
3.0 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Hierarchical layout difference</title>
  5. <style type="text/css">
  6. body {
  7. font: 10pt sans;
  8. }
  9. #mynetwork {
  10. width: 800px;
  11. height: 500px;
  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 network = null;
  19. var layoutMethod = "hubsize";
  20. function destroy() {
  21. if (network !== null) {
  22. network.destroy();
  23. network = null;
  24. }
  25. }
  26. function draw() {
  27. destroy();
  28. var nodes = [];
  29. var edges = [];
  30. // randomly create some nodes and edges
  31. for (var i = 0; i < 20; i++) {
  32. nodes.push({id: i, label: String(i)});
  33. }
  34. edges.push({from: 0, to: 1});
  35. edges.push({from: 0, to: 6});
  36. edges.push({from: 0, to: 13});
  37. edges.push({from: 0, to: 11});
  38. edges.push({from: 1, to: 2});
  39. edges.push({from: 2, to: 3});
  40. edges.push({from: 2, to: 4});
  41. edges.push({from: 3, to: 5});
  42. edges.push({from: 1, to: 10});
  43. edges.push({from: 1, to: 7});
  44. edges.push({from: 2, to: 8});
  45. edges.push({from: 2, to: 9});
  46. edges.push({from: 3, to: 14});
  47. edges.push({from: 1, to: 12});
  48. edges.push({from: 0, to: 19});
  49. edges.push({from: 19, to: 2});
  50. edges.push({from: 19, to: 10});
  51. edges.push({from: 19, to: 7});
  52. edges.push({from: 19, to: 12});
  53. edges.push({from: 16, to: 15});
  54. edges.push({from: 15, to: 17});
  55. edges.push({from: 18, to: 17});
  56. // create a network
  57. var container = document.getElementById('mynetwork');
  58. var data = {
  59. nodes: nodes,
  60. edges: edges
  61. };
  62. var options = {
  63. layout: {
  64. hierarchical: {
  65. sortMethod: layoutMethod
  66. }
  67. },
  68. edges: {
  69. smooth: true,
  70. arrows: {to : true }
  71. },
  72. // physics:false
  73. };
  74. network = new vis.Network(container, data, options);
  75. }
  76. </script>
  77. <script src="../../googleAnalytics.js"></script>
  78. </head>
  79. <body onload="draw();">
  80. <h2>Hierarchical layout difference</h2>
  81. <div style="width:700px; font-size:14px; text-align: justify;">
  82. This example shows a the effect of the different hierarchical layout methods. Hubsize is based on the amount of edges connected to a node.
  83. The node with the most connections (the largest hub) is drawn at the top of the tree. The direction method is based on the direction of the edges.
  84. Try switching between the methods with the dropdown box below.
  85. </div>
  86. Layout method:
  87. <select id="layout">
  88. <option value="hubsize">hubsize</option>
  89. <option value="directed">directed</option>
  90. </select><br/>
  91. <br />
  92. <div id="mynetwork"></div>
  93. <p id="selection"></p>
  94. <script language="JavaScript">
  95. var dropdown = document.getElementById("layout");
  96. dropdown.onchange = function() {
  97. layoutMethod = dropdown.value;
  98. draw();
  99. }
  100. </script>
  101. </body>
  102. </html>