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.

211 lines
4.5 KiB

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