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.

175 lines
5.7 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Navigation</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. table.legend_table {
  15. font-size: 11px;
  16. border-width:1px;
  17. border-color:#d3d3d3;
  18. border-style:solid;
  19. }
  20. table.legend_table,td {
  21. border-width:1px;
  22. border-color:#d3d3d3;
  23. border-style:solid;
  24. padding: 2px;
  25. }
  26. div.table_content {
  27. width:80px;
  28. text-align:center;
  29. }
  30. div.table_description {
  31. width:100px;
  32. }
  33. </style>
  34. <script type="text/javascript" src="../../dist/vis.js"></script>
  35. <link type="text/css" rel="stylesheet" href="../../dist/vis.css">
  36. <script type="text/javascript">
  37. var nodes = null;
  38. var edges = null;
  39. var network = null;
  40. function destroy() {
  41. if (network !== null) {
  42. network.destroy();
  43. network = null;
  44. }
  45. }
  46. function draw() {
  47. destroy();
  48. nodes = [];
  49. edges = [];
  50. var connectionCount = [];
  51. // randomly create some nodes and edges
  52. var nodeCount = document.getElementById('nodeCount').value;
  53. for (var i = 0; i < nodeCount; i++) {
  54. nodes.push({
  55. id: i,
  56. label: String(i)
  57. });
  58. connectionCount[i] = 0;
  59. // create edges in a scale-free-network way
  60. if (i == 1) {
  61. var from = i;
  62. var to = 0;
  63. edges.push({
  64. from: from,
  65. to: to
  66. });
  67. connectionCount[from]++;
  68. connectionCount[to]++;
  69. }
  70. else if (i > 1) {
  71. var conn = edges.length * 2;
  72. var rand = Math.floor(Math.random() * conn);
  73. var cum = 0;
  74. var j = 0;
  75. while (j < connectionCount.length && cum < rand) {
  76. cum += connectionCount[j];
  77. j++;
  78. }
  79. var from = i;
  80. var to = j;
  81. edges.push({
  82. from: from,
  83. to: to
  84. });
  85. connectionCount[from]++;
  86. connectionCount[to]++;
  87. }
  88. }
  89. // create a network
  90. var container = document.getElementById('mynetwork');
  91. var data = {
  92. nodes: nodes,
  93. edges: edges
  94. };
  95. var options = {
  96. interaction:{showNavigationIcons: true},
  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. <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></head>
  106. <body onload="draw();">
  107. <h2>Navigation controls and keyboad navigation</h2>
  108. <div style="width: 800px; font-size:14px; text-align: justify;">
  109. This example is the same as example 2, except for the navigation controls that have been activated. The navigation controls are described below. <br /><br />
  110. <table class="legend_table">
  111. <tr>
  112. <td>Icons: </td>
  113. <td><div class="table_content"><img src="../../dist/img/network/upArrow.png" /> </div></td>
  114. <td><div class="table_content"><img src="../../dist/img/network/downArrow.png" /> </div></td>
  115. <td><div class="table_content"><img src="../../dist/img/network/leftArrow.png" /> </div></td>
  116. <td><div class="table_content"><img src="../../dist/img/network/rightArrow.png" /> </div></td>
  117. <td><div class="table_content"><img src="../../dist/img/network/plus.png" /> </div></td>
  118. <td><div class="table_content"><img src="../../dist/img/network/minus.png" /> </div></td>
  119. <td><div class="table_content"><img src="../../dist/img/network/zoomExtends.png" /> </div></td>
  120. </tr>
  121. <tr>
  122. <td><div class="table_description">Keyboard shortcuts:</div></td>
  123. <td><div class="table_content">Up arrow</div></td>
  124. <td><div class="table_content">Down arrow</div></td>
  125. <td><div class="table_content">Left arrow</div></td>
  126. <td><div class="table_content">Right arrow</div></td>
  127. <td><div class="table_content">=<br />[<br />Page up</div></td>
  128. <td><div class="table_content">-<br />]<br />Page down</div></td>
  129. <td><div class="table_content">None</div></td>
  130. </tr>
  131. <tr>
  132. <td><div class="table_description">Description:</div></td>
  133. <td><div class="table_content">Move up</div></td>
  134. <td><div class="table_content">Move down</div></td>
  135. <td><div class="table_content">Move left</div></td>
  136. <td><div class="table_content">Move right</div></td>
  137. <td><div class="table_content">Zoom in</div></td>
  138. <td><div class="table_content">Zoom out</div></td>
  139. <td><div class="table_content">Zoom extent</div></td>
  140. </tr>
  141. </table>
  142. <br />
  143. Apart from clicking the icons, you can also navigate using the keyboard. The buttons are in table above.
  144. Zoom Extends changes the zoom and position of the camera to encompass all visible nodes. <u>To correctly display the navigation icons, the <b>vis.css</b> file must be included.</u>
  145. The user is free to alter or overload the CSS classes but without them the navigation icons are not visible.
  146. </div>
  147. <br />
  148. <form onsubmit="draw(); return false;">
  149. <label for="nodeCount">Number of nodes:</label>
  150. <input id="nodeCount" type="text" value="25" style="width: 50px;">
  151. <input type="submit" value="Go">
  152. </form>
  153. <br>
  154. <div id="mynetwork"></div>
  155. <p id="selection"></p>
  156. </body>
  157. </html>