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.

219 lines
4.6 KiB

10 years ago
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | DOT language playground</title>
  5. <script type="text/javascript" src="../../../../dist/vis.js"></script>
  6. <link href="../../../../dist/vis.css" rel="stylesheet" type="text/css" />
  7. <style type="text/css">
  8. body, html {
  9. font: 10pt sans;
  10. width: 100%;
  11. height: 100%;
  12. padding: 0;
  13. margin: 0;
  14. color: #4d4d4d;
  15. }
  16. #frame {
  17. width: 100%;
  18. height: 99%;
  19. }
  20. #frame td {
  21. padding: 10px;
  22. height: 100%;
  23. }
  24. #error {
  25. color: red;
  26. }
  27. #data {
  28. width: 100%;
  29. height: 100%;
  30. border: 1px solid #d3d3d3;
  31. }
  32. #mynetwork {
  33. float: left;
  34. width: 100%;
  35. height: 100%;
  36. border: 1px solid #d3d3d3;
  37. box-sizing: border-box;
  38. -moz-box-sizing: border-box;
  39. overflow: hidden;
  40. }
  41. textarea.example {
  42. display: none;
  43. }
  44. </style>
  45. <script src="../../../googleAnalytics.js"></script>
  46. </head>
  47. <body onload="drawExample('example1')">
  48. <table id="frame">
  49. <col width="50%">
  50. <col width="50%">
  51. <tr>
  52. <td colspan="2" style="height: 50px;">
  53. <h1>DOT language playground</h1>
  54. <div>
  55. <a href="javascript: drawExample('example1')">example 1</a>
  56. <a href="javascript: drawExample('example2')">example 2</a>
  57. <a href="javascript: drawExample('example3')">example 3</a>
  58. </div>
  59. <div>
  60. <br>
  61. <button id="draw">Draw</button>
  62. <span id="error"></span>
  63. </div>
  64. </td>
  65. </tr>
  66. <tr>
  67. <td>
  68. <textarea id="data"></textarea>
  69. </td>
  70. <td>
  71. <div id="mynetwork"></div>
  72. </td>
  73. </tr>
  74. </table>
  75. <script type="text/javascript">
  76. var network = null;
  77. var data = null;
  78. var btnDraw = document.getElementById('draw');
  79. var txtData = document.getElementById('data');
  80. var txtError = document.getElementById('error');
  81. btnDraw.onclick = draw;
  82. // resize the network when window resizes
  83. window.onresize = function () {
  84. network.redraw()
  85. };
  86. function destroy() {
  87. if (network !== null) {
  88. network.destroy();
  89. network = null;
  90. }
  91. }
  92. // parse and draw the data
  93. function draw () {
  94. destroy();
  95. try {
  96. txtError.innerHTML = '';
  97. // Provide a string with data in DOT language
  98. data = {
  99. dot: txtData.value
  100. };
  101. // create a network
  102. var container = document.getElementById('mynetwork');
  103. var options = {
  104. physics: {
  105. barnesHut: {
  106. springLength: 200
  107. }
  108. }
  109. };
  110. network = new vis.Network(container, data, options);
  111. }
  112. catch (err) {
  113. // set the cursor at the position where the error occurred
  114. var match = /\(char (.*)\)/.exec(err);
  115. if (match) {
  116. var pos = Number(match[1]);
  117. if(txtData.setSelectionRange) {
  118. txtData.focus();
  119. txtData.setSelectionRange(pos, pos);
  120. }
  121. }
  122. // show an error message
  123. txtError.innerHTML = err.toString();
  124. }
  125. }
  126. /**
  127. * Draw an example
  128. * @param {String} id HTML id of the textarea containing the example code
  129. */
  130. function drawExample(id) {
  131. txtData.value = document.getElementById(id).value;
  132. draw();
  133. }
  134. </script>
  135. <textarea id="example1" class="example">
  136. digraph {
  137. node [shape=circle fontSize=16]
  138. edge [length=100, color=gray, fontColor=black]
  139. A -> A[label=0.5];
  140. B -> B[label=1.2] -> C[label=0.7] -- A;
  141. B -> D;
  142. D -> {B; C}
  143. D -> E[label=0.2];
  144. F -> F;
  145. A [
  146. fontColor=white,
  147. color=red,
  148. ]
  149. }
  150. </textarea>
  151. <textarea id="example2" class="example">
  152. digraph topology
  153. {
  154. node[shape=circle fontSize=12]
  155. edge[length=170 fontSize=12]
  156. "10.0.255.1" -> "10.0.255.3"[label="1.000"];
  157. "10.0.255.1" -> "10.0.255.2"[label="1.000"];
  158. "10.0.255.1" -> "10.0.255.2"[label="1.000"];
  159. "10.0.255.1" -> "10.0.255.3"[label="1.000"];
  160. "10.0.255.2" -> "10.0.255.1"[label="1.000"];
  161. "10.0.255.2" -> "10.0.255.3"[label="1.000"];
  162. "10.0.255.3" -> "10.0.255.1"[label="1.000"];
  163. "10.0.255.3" -> "10.0.255.2"[label="1.000"];
  164. "10.0.255.3" -> "10.0.3.0/24"[label="HNA", shape=solid];
  165. "10.0.3.0/24"[shape=box];
  166. "10.0.255.2" -> "10.0.2.0/24"[label="HNA"];
  167. "10.0.2.0/24"[shape=box];
  168. "10.0.255.1" -> "10.0.1.0/24"[label="HNA"];
  169. "10.0.1.0/24"[shape=box];
  170. }
  171. </textarea>
  172. <textarea id="example3" class="example">
  173. digraph G {
  174. // note: not all attributes are recognized and supported by Network
  175. // unrecognized attributes are ignored
  176. node[width=.25,height=.375,fontsize=15]
  177. node [shape=filled fillcolor=#F1AAF0]
  178. 0-> 0 ;
  179. 1-> 1 ;
  180. 2-> 2 ;
  181. 3-> 3 ;
  182. 4-> 4 ;
  183. 5-> 5 ;
  184. 6-> 6 ;
  185. 7-> 5 ;
  186. 8-> 8 ;
  187. 9-> 9 ;
  188. 10-> 10 ;
  189. 11-> 10 ;
  190. 12-> 12 ;
  191. 13-> 5 ;
  192. 14-> 10 ;
  193. 15-> 0 ;
  194. }
  195. </textarea>
  196. </body>
  197. </html>