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.

154 lines
3.9 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 = "direction";
  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 < 15; i++) {
  32. nodes.push({
  33. id: i,
  34. label: String(i)
  35. });
  36. }
  37. edges.push({
  38. from: 0,
  39. to: 1
  40. });
  41. edges.push({
  42. from: 0,
  43. to: 6
  44. });
  45. edges.push({
  46. from: 0,
  47. to: 13
  48. });edges.push({
  49. from: 0,
  50. to: 11
  51. });
  52. edges.push({
  53. from: 1,
  54. to: 2
  55. });
  56. edges.push({
  57. from: 2,
  58. to: 3
  59. });
  60. edges.push({
  61. from: 2,
  62. to: 4
  63. });
  64. edges.push({
  65. from: 3,
  66. to: 5
  67. });
  68. edges.push({
  69. from: 1,
  70. to: 10
  71. });
  72. edges.push({
  73. from: 1,
  74. to: 7
  75. });
  76. edges.push({
  77. from: 2,
  78. to: 8
  79. });
  80. edges.push({
  81. from: 10,
  82. to: 2
  83. });
  84. edges.push({
  85. from: 2,
  86. to: 9
  87. });
  88. edges.push({
  89. from: 3,
  90. to: 14
  91. });
  92. edges.push({
  93. from: 1,
  94. to: 12
  95. });
  96. // create a network
  97. var container = document.getElementById('mynetwork');
  98. var data = {
  99. nodes: nodes,
  100. edges: edges
  101. };
  102. var options = {
  103. hierarchicalLayout: {
  104. layout: layoutMethod
  105. },
  106. edges: {style:"arrow"},
  107. smoothCurves:false
  108. };
  109. network = new vis.Network(container, data, options);
  110. // add event listeners
  111. network.on('select', function(params) {
  112. document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes;
  113. });
  114. }
  115. </script>
  116. </head>
  117. <body onload="draw();">
  118. <h2>Hierarchical layout difference</h2>
  119. <div style="width:700px; font-size:14px; text-align: justify;">
  120. This example shows a the effect of the different hierarchical layout methods. Hubsize is based on the amount of edges connected to a node.
  121. 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.
  122. Try switching between the methods with the dropdown box below.
  123. </div>
  124. Layout method:
  125. <select id="layout">
  126. <option value="direction">direction</option>
  127. <option value="hubsize">hubsize</option>
  128. </select><br/>
  129. <br />
  130. <div id="mynetwork"></div>
  131. <p id="selection"></p>
  132. <script language="JavaScript">
  133. var dropdown = document.getElementById("layout");
  134. dropdown.onchange = function() {
  135. layoutMethod = dropdown.value;
  136. draw();
  137. }
  138. </script>
  139. </body>
  140. </html>