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.

136 lines
3.9 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. border-collapse: collapse;
  16. }
  17. table.legend_table td,
  18. table.legend_table th {
  19. border: 1px solid #d3d3d3;
  20. padding: 10px;
  21. }
  22. table.legend_table td {
  23. text-align: center;
  24. width:110px;
  25. }
  26. </style>
  27. <script type="text/javascript" src="../../exampleUtil.js"></script>
  28. <script type="text/javascript" src="../../../../dist/vis.js"></script>
  29. <link href="../../../../dist/vis.css" rel="stylesheet" type="text/css" />
  30. <script type="text/javascript">
  31. var nodes = null;
  32. var edges = null;
  33. var network = null;
  34. function destroy() {
  35. if (network !== null) {
  36. network.destroy();
  37. network = null;
  38. }
  39. }
  40. function draw() {
  41. destroy();
  42. // create an array with nodes
  43. var nodes = [
  44. {id: 1, label: 'Node 1'},
  45. {id: 2, label: 'Node 2'},
  46. {id: 3, label: 'Node 3'},
  47. {id: 4, label: 'Node 4'},
  48. {id: 5, label: 'Node 5'}
  49. ];
  50. // create an array with edges
  51. var edges = new vis.DataSet([
  52. {from: 1, to: 1},
  53. {from: 1, to: 3},
  54. {from: 1, to: 2},
  55. {from: 2, to: 4},
  56. {from: 2, to: 5}
  57. ]);
  58. // create a network
  59. var container = document.getElementById('mynetwork');
  60. var data = {
  61. nodes: nodes,
  62. edges: edges
  63. };
  64. var options = {
  65. interaction: {
  66. navigationButtons: true,
  67. keyboard: true
  68. }
  69. };
  70. network = new vis.Network(container, data, options);
  71. // add event listeners
  72. network.on('select', function(params) {
  73. document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes;
  74. });
  75. }
  76. </script>
  77. <script src="../../../googleAnalytics.js"></script>
  78. </head>
  79. <body onload="draw();">
  80. <h2>Navigation controls and keyboad navigation</h2>
  81. <div style="width: 800px; font-size:14px; text-align: justify;">
  82. 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 />
  83. <table class="legend_table">
  84. <tr>
  85. <th>Icons: </th>
  86. <td><img src="../../../../dist/img/network/upArrow.png" /> </td>
  87. <td><img src="../../../../dist/img/network/downArrow.png" /> </td>
  88. <td><img src="../../../../dist/img/network/leftArrow.png" /> </td>
  89. <td><img src="../../../../dist/img/network/rightArrow.png" /> </td>
  90. <td><img src="../../../../dist/img/network/plus.png" /> </td>
  91. <td><img src="../../../../dist/img/network/minus.png" /> </td>
  92. <td><img src="../../../../dist/img/network/zoomExtends.png" /> </td>
  93. </tr>
  94. <tr>
  95. <th>Keyboard shortcuts:</th>
  96. <td><div>Up arrow</div></td>
  97. <td><div>Down arrow</div></td>
  98. <td><div>Left arrow</div></td>
  99. <td><div>Right arrow</div></td>
  100. <td><div>=<br />[<br />Page up</div></td>
  101. <td><div>-<br />]<br />Page down</div></td>
  102. <td><div>None</div></td>
  103. </tr>
  104. <tr>
  105. <th>Description:</th>
  106. <td>Move up</td>
  107. <td>Move down</td>
  108. <td>Move left</td>
  109. <td>Move right</td>
  110. <td>Zoom in</td>
  111. <td>Zoom out</td>
  112. <td>Zoom extent</td>
  113. </tr>
  114. </table>
  115. <br />
  116. Apart from clicking the icons, you can also navigate using the keyboard. The buttons are in table above.
  117. 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>
  118. The user is free to alter or overload the CSS classes but without them the navigation icons are not visible.
  119. </div>
  120. <div id="mynetwork"></div>
  121. <p id="selection"></p>
  122. </body>
  123. </html>