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.

293 lines
8.6 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Graph | Navigation</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. div.graph-manipulationDiv {
  34. border-width:0px;
  35. border-bottom: 1px;
  36. border-style:solid;
  37. border-color: #d6d9d8;
  38. background: #ffffff; /* Old browsers */
  39. background: -moz-linear-gradient(top, #ffffff 0%, #f3f3f3 50%, #ededed 51%, #ffffff 100%); /* FF3.6+ */
  40. background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(50%,#f3f3f3), color-stop(51%,#ededed), color-stop(100%,#ffffff)); /* Chrome,Safari4+ */
  41. background: -webkit-linear-gradient(top, #ffffff 0%,#f3f3f3 50%,#ededed 51%,#ffffff 100%); /* Chrome10+,Safari5.1+ */
  42. background: -o-linear-gradient(top, #ffffff 0%,#f3f3f3 50%,#ededed 51%,#ffffff 100%); /* Opera 11.10+ */
  43. background: -ms-linear-gradient(top, #ffffff 0%,#f3f3f3 50%,#ededed 51%,#ffffff 100%); /* IE10+ */
  44. background: linear-gradient(to bottom, #ffffff 0%,#f3f3f3 50%,#ededed 51%,#ffffff 100%); /* W3C */
  45. filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ffffff',GradientType=0 ); /* IE6-9 */
  46. width: 600px;
  47. height:30px;
  48. z-index:10;
  49. position:absolute;
  50. }
  51. span.manipulationUI {
  52. font-family: verdana;
  53. font-size: 12px;
  54. -moz-border-radius: 15px;
  55. border-radius: 15px;
  56. display:inline-block;
  57. background-position: 0px 0px;
  58. background-repeat:no-repeat;
  59. height:24px;
  60. margin: -14px 0px 0px 10px;
  61. vertical-align:middle;
  62. cursor: pointer;
  63. padding: 0px 8px 0px 8px;
  64. -webkit-touch-callout: none;
  65. -webkit-user-select: none;
  66. -khtml-user-select: none;
  67. -moz-user-select: none;
  68. -ms-user-select: none;
  69. user-select: none;
  70. }
  71. span.manipulationUI:hover {
  72. box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.20);
  73. }
  74. span.manipulationUI:active {
  75. box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.50);
  76. }
  77. span.manipulationUI.back {
  78. background-image: url("../../dist/img/backIcon.png");
  79. }
  80. span.manipulationUI.none:hover {
  81. box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.0);
  82. cursor: default;
  83. }
  84. span.manipulationUI.none:active {
  85. box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.0);
  86. }
  87. span.manipulationUI.none {
  88. padding: 0px 0px 0px 0px;
  89. }
  90. span.manipulationUI.notification{
  91. margin: 2px;
  92. font-weight: bold;
  93. }
  94. span.manipulationUI.add {
  95. background-image: url("../../dist/img/addNodeIcon.png");
  96. }
  97. span.manipulationUI.edit {
  98. background-image: url("../../dist/img/editIcon.png");
  99. }
  100. span.manipulationUI.connect {
  101. background-image: url("../../dist/img/connectIcon.png");
  102. }
  103. span.manipulationUI.delete {
  104. background-image: url("../../dist/img/deleteIcon.png");
  105. }
  106. span.manipulationUI.acceptDelete {
  107. background-image: url("../../dist/img/acceptDeleteIcon.png");
  108. }
  109. /* top right bottom left */
  110. span.manipulationLabel {
  111. margin: 0px 0px 0px 23px;
  112. line-height: 25px;
  113. }
  114. div.seperatorLine {
  115. display:inline-block;
  116. width:1px;
  117. height:20px;
  118. background-color: #bdbdbd;
  119. margin: 5px 7px 0px 15px;
  120. }
  121. input.manipulatorInput[type="text"] {
  122. width:80px;
  123. height:15px;
  124. font-size:11px;
  125. margin: 2px 0px 0px 0px;
  126. }
  127. input.manipulatorInput[type="button"] {
  128. width:80px;
  129. height:22px;
  130. font-size:12px;
  131. margin: 2px 0px 0px 10px;
  132. }
  133. </style>
  134. <script type="text/javascript" src="../../dist/vis.js"></script>
  135. <script type="text/javascript">
  136. var nodes = null;
  137. var edges = null;
  138. var graph = null;
  139. function draw() {
  140. nodes = [];
  141. edges = [];
  142. var connectionCount = [];
  143. // randomly create some nodes and edges
  144. var nodeCount = document.getElementById('nodeCount').value;
  145. for (var i = 0; i < nodeCount; i++) {
  146. nodes.push({
  147. id: i,
  148. label: String(i)
  149. });
  150. connectionCount[i] = 0;
  151. // create edges in a scale-free-graph way
  152. if (i == 1) {
  153. var from = i;
  154. var to = 0;
  155. edges.push({
  156. from: from,
  157. to: to
  158. });
  159. connectionCount[from]++;
  160. connectionCount[to]++;
  161. }
  162. else if (i > 1) {
  163. var conn = edges.length * 2;
  164. var rand = Math.floor(Math.random() * conn);
  165. var cum = 0;
  166. var j = 0;
  167. while (j < connectionCount.length && cum < rand) {
  168. cum += connectionCount[j];
  169. j++;
  170. }
  171. var from = i;
  172. var to = j;
  173. edges.push({
  174. from: from,
  175. to: to
  176. });
  177. connectionCount[from]++;
  178. connectionCount[to]++;
  179. }
  180. }
  181. // create a graph
  182. var container = document.getElementById('mygraph');
  183. var data = {
  184. nodes: nodes,
  185. edges: edges
  186. };
  187. /*
  188. var options = {
  189. nodes: {
  190. shape: 'circle'
  191. },
  192. edges: {
  193. length: 50
  194. },
  195. stabilize: false
  196. };
  197. */
  198. var options = {
  199. edges: {
  200. length: 50
  201. },
  202. stabilize: false,
  203. clustering:true,
  204. navigation: true,
  205. keyboard: true,
  206. dataManipulationToolbar: true
  207. };
  208. graph = new vis.Graph(container, data, options);
  209. // add event listeners
  210. graph.on('select', function(params) {
  211. document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes;
  212. });
  213. }
  214. </script>
  215. </head>
  216. <body onload="draw();">
  217. <h2>Navigation controls and keyboad navigation</h2>
  218. <div style="width: 700px; font-size:14px;">
  219. This example is the same as example 2, except for the navigation controls that has been activated. The navigation controls are described below. <br /><br />
  220. <table class="legend_table">
  221. <tr>
  222. <td>Icons: </td>
  223. <td><div class="table_content"><img src="../../dist/img/uparrow.png" /> </div></td>
  224. <td><div class="table_content"><img src="../../dist/img/downarrow.png" /> </div></td>
  225. <td><div class="table_content"><img src="../../dist/img/leftarrow.png" /> </div></td>
  226. <td><div class="table_content"><img src="../../dist/img/rightarrow.png" /> </div></td>
  227. <td><div class="table_content"><img src="../../dist/img/plus.png" /> </div></td>
  228. <td><div class="table_content"><img src="../../dist/img/minus.png" /> </div></td>
  229. <td><div class="table_content"><img src="../../dist/img/zoomExtends.png" /> </div></td>
  230. </tr>
  231. <tr>
  232. <td><div class="table_description">Keyboard shortcuts:</div></td>
  233. <td><div class="table_content">Up arrow</div></td>
  234. <td><div class="table_content">Down arrow</div></td>
  235. <td><div class="table_content">Left arrow</div></td>
  236. <td><div class="table_content">Right arrow</div></td>
  237. <td><div class="table_content">=<br />[<br />Page up</div></td>
  238. <td><div class="table_content">-<br />]<br />Page down</div></td>
  239. <td><div class="table_content">None</div></td>
  240. </tr>
  241. <tr>
  242. <td><div class="table_description">Description:</div></td>
  243. <td><div class="table_content">Move up</div></td>
  244. <td><div class="table_content">Move down</div></td>
  245. <td><div class="table_content">Move left</div></td>
  246. <td><div class="table_content">Move right</div></td>
  247. <td><div class="table_content">Zoom in</div></td>
  248. <td><div class="table_content">Zoom out</div></td>
  249. <td><div class="table_content">Zoom extends</div></td>
  250. </tr>
  251. </table>
  252. <br />
  253. Apart from clicking the icons, you can also navigate using the keyboard. The buttons are in table above.
  254. Zoom Extends changes the zoom and position of the camera to encompass all visible nodes.
  255. </div>
  256. <br />
  257. <form onsubmit="draw(); return false;">
  258. <label for="nodeCount">Number of nodes:</label>
  259. <input id="nodeCount" type="text" value="25" style="width: 50px;">
  260. <input type="submit" value="Go">
  261. </form>
  262. <br>
  263. <div id="mygraph"></div>
  264. <p id="selection"></p>
  265. </body>
  266. </html>