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.

186 lines
5.4 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Graph | Random nodes</title>
  5. <style type="text/css">
  6. body {
  7. font: 10pt sans;
  8. }
  9. #mygraph {
  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. <script type="text/javascript">
  36. var nodes = null;
  37. var edges = null;
  38. var graph = null;
  39. function draw() {
  40. nodes = [];
  41. edges = [];
  42. var connectionCount = [];
  43. // randomly create some nodes and edges
  44. var nodeCount = document.getElementById('nodeCount').value;
  45. for (var i = 0; i < nodeCount; i++) {
  46. nodes.push({
  47. id: i,
  48. label: String(i)
  49. });
  50. connectionCount[i] = 0;
  51. // create edges in a scale-free-graph way
  52. if (i == 1) {
  53. var from = i;
  54. var to = 0;
  55. edges.push({
  56. from: from,
  57. to: to
  58. });
  59. connectionCount[from]++;
  60. connectionCount[to]++;
  61. }
  62. else if (i > 1) {
  63. var conn = edges.length * 2;
  64. var rand = Math.floor(Math.random() * conn);
  65. var cum = 0;
  66. var j = 0;
  67. while (j < connectionCount.length && cum < rand) {
  68. cum += connectionCount[j];
  69. j++;
  70. }
  71. var from = i;
  72. var to = j;
  73. edges.push({
  74. from: from,
  75. to: to
  76. });
  77. connectionCount[from]++;
  78. connectionCount[to]++;
  79. }
  80. }
  81. // create a graph
  82. var container = document.getElementById('mygraph');
  83. var data = {
  84. nodes: nodes,
  85. edges: edges
  86. };
  87. /*
  88. var options = {
  89. nodes: {
  90. shape: 'circle'
  91. },
  92. edges: {
  93. length: 50
  94. },
  95. stabilize: false
  96. };
  97. */
  98. var options = {
  99. edges: {
  100. length: 50
  101. },
  102. stabilize: false,
  103. navigationUI: {
  104. enabled: true
  105. },
  106. keyboardNavigation: {
  107. enabled: true
  108. }
  109. };
  110. graph = new vis.Graph(container, data, options);
  111. // add event listeners
  112. vis.events.addListener(graph, 'select', function(params) {
  113. document.getElementById('selection').innerHTML =
  114. 'Selection: ' + graph.getSelection();
  115. });
  116. }
  117. </script>
  118. </head>
  119. <body onload="draw();">
  120. <h2>UI - User Interface and Keyboad Navigation</h2>
  121. <div style="width: 700px; font-size:14px;">
  122. This example is the same as example 2, except for the UI that has been activated. The UI icons are described below. <br /><br />
  123. <table class="legend_table">
  124. <tr>
  125. <td>Icons: </td>
  126. <td><div class="table_content"><img src="img/UI_icons/uparrow.png" /> </div></td>
  127. <td><div class="table_content"><img src="img/UI_icons/downarrow.png" /> </div></td>
  128. <td><div class="table_content"><img src="img/UI_icons/leftarrow.png" /> </div></td>
  129. <td><div class="table_content"><img src="img/UI_icons/rightarrow.png" /> </div></td>
  130. <td><div class="table_content"><img src="img/UI_icons/plus.png" /> </div></td>
  131. <td><div class="table_content"><img src="img/UI_icons/minus.png" /> </div></td>
  132. <td><div class="table_content"><img src="img/UI_icons/zoomExtends.png" /> </div></td>
  133. </tr>
  134. <tr>
  135. <td><div class="table_description">Keyboard shortcuts:</div></td>
  136. <td><div class="table_content">Up arrow</div></td>
  137. <td><div class="table_content">Down arrow</div></td>
  138. <td><div class="table_content">Left arrow</div></td>
  139. <td><div class="table_content">Right arrow</div></td>
  140. <td><div class="table_content">=<br />[<br />Page up</div></td>
  141. <td><div class="table_content">-<br />]<br />Page down</div></td>
  142. <td><div class="table_content">None</div></td>
  143. </tr>
  144. <td><div class="table_description">Description:</div></td>
  145. <td><div class="table_content">Move up</div></td>
  146. <td><div class="table_content">Move down</div></td>
  147. <td><div class="table_content">Move left</div></td>
  148. <td><div class="table_content">Move right</div></td>
  149. <td><div class="table_content">Zoom in</div></td>
  150. <td><div class="table_content">Zoom out</div></td>
  151. <td><div class="table_content">Zoom extends</div></td>
  152. </tr>
  153. </table>
  154. <br />
  155. Apart from clicking the icons, you can also navigate using the keyboard. The buttons are in table above.
  156. Zoom Extends changes the zoom and position of the camera to encompass all visible nodes. The UI buttons can be toggled on or off
  157. by pressing the U button on the keyboard.
  158. </div>
  159. <br />
  160. <form onsubmit="draw(); return false;">
  161. <label for="nodeCount">Number of nodes:</label>
  162. <input id="nodeCount" type="text" value="25" style="width: 50px;">
  163. <input type="submit" value="Go">
  164. </form>
  165. <br>
  166. <div id="mygraph"></div>
  167. <p id="selection"></p>
  168. </body>
  169. </html>