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.

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