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.

216 lines
5.3 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | DOT language playground</title>
  5. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
  6. <script src="../../../../dist/vis.js"></script>
  7. <link href="../../../../dist/vis-network.min.css" rel="stylesheet" type="text/css" />
  8. <style type="text/css">
  9. body, html {
  10. font: 10pt sans;
  11. line-height: 1.5em;;
  12. width: 100%;
  13. height: 100%;
  14. padding: 0;
  15. margin: 0;
  16. color: #4d4d4d;
  17. box-sizing: border-box;
  18. overflow: hidden;
  19. }
  20. #header {
  21. margin: 0;
  22. padding: 10px;
  23. box-sizing: border-box;
  24. }
  25. #contents {
  26. height: 100%;
  27. margin: 0;
  28. padding: 0;
  29. box-sizing: border-box;
  30. position: relative;
  31. }
  32. #left, #right {
  33. position: absolute;
  34. width: 50%;
  35. height: 100%;
  36. margin: 0;
  37. padding: 10px;
  38. box-sizing: border-box;
  39. display: inline-block;
  40. }
  41. #left {
  42. top: 0;
  43. left: 0;
  44. }
  45. #right {
  46. top: 0;
  47. right: 0;
  48. }
  49. #error {
  50. color: red;
  51. }
  52. #data {
  53. width: 100%;
  54. height: 100%;
  55. border: 1px solid #d3d3d3;
  56. box-sizing: border-box;
  57. resize: none;
  58. }
  59. #draw {
  60. padding: 5px 15px;
  61. }
  62. #mynetwork {
  63. width: 100%;
  64. height: 100%;
  65. border: 1px solid #d3d3d3;
  66. box-sizing: border-box;
  67. }
  68. a:hover {
  69. color: red;
  70. }
  71. </style>
  72. </head>
  73. <body>
  74. <div id="header">
  75. <h1>DOT language playground</h1>
  76. <p>
  77. Play around with the DOT language in the textarea below, or select one of the following examples:
  78. </p>
  79. <p style="margin-left: 30px;">
  80. <a href="#" class="example" data-url="data/simple.gv.txt">simple</a>,
  81. <a href="#" class="example" data-url="data/computer_network.gv.txt">computer network</a>,
  82. <a href="#" class="example" data-url="data/cellular_automata.gv.txt">cellular automata</a>,
  83. <a href="#" class="example" data-url="graphvizGallery/fsm.gv.txt">fsm *</a>,
  84. <a href="#" class="example" data-url="graphvizGallery/hello.gv.txt">hello *</a>,
  85. <a href="#" class="example" data-url="graphvizGallery/process.gv.txt">process *</a>,
  86. <a href="#" class="example" data-url="graphvizGallery/siblings.gv.txt">siblings *</a>,
  87. <a href="#" class="example" data-url="graphvizGallery/softmaint.gv.txt">softmaint *</a>,
  88. <a href="#" class="example" data-url="graphvizGallery/traffic_lights.gv.txt">traffic lights *</a>,
  89. <a href="#" class="example" data-url="graphvizGallery/transparency.gv.txt">transparency *</a>,
  90. <a href="#" class="example" data-url="graphvizGallery/twopi2.gv.txt">twopi2 *</a>,
  91. <a href="#" class="example" data-url="graphvizGallery/unix.gv.txt">unix *</a>,
  92. <a href="#" class="example" data-url="graphvizGallery/world.gv.txt">world *</a>
  93. </p>
  94. <p>
  95. The examples marked with a star (*) come straight from the <a href="http://www.graphviz.org/Gallery.php">GraphViz gallery</a>.
  96. </p>
  97. <div>
  98. <button id="draw" title="Draw the DOT graph (Ctrl+Enter)">Draw</button>
  99. <span id="error"></span>
  100. </div>
  101. </div>
  102. <div id="contents">
  103. <div id="left">
  104. <textarea id="data">
  105. digraph {
  106. node [shape=circle fontsize=16]
  107. edge [length=100, color=gray, fontcolor=black]
  108. A -> A[label=0.5];
  109. B -> B[label=1.2] -> C[label=0.7] -- A;
  110. B -> D;
  111. D -> {B; C}
  112. D -> E[label=0.2];
  113. F -> F;
  114. A [
  115. fontcolor=white,
  116. color=red,
  117. ]
  118. }
  119. </textarea>
  120. </div>
  121. <div id="right">
  122. <div id="mynetwork"></div>
  123. </div>
  124. </div>
  125. <script type="text/javascript">
  126. // create a network
  127. var container = document.getElementById('mynetwork');
  128. var options = {
  129. physics: {
  130. stabilization: false,
  131. barnesHut: {
  132. springLength: 200
  133. }
  134. }
  135. };
  136. var data = {};
  137. var network = new vis.Network(container, data, options);
  138. $('#draw').click(draw);
  139. $('a.example').click(function (event) {
  140. var url = $(event.target).data('url');
  141. $.get(url)
  142. .done(function(dotData) {
  143. $('#data').val(dotData);
  144. draw();
  145. })
  146. .fail(function () {
  147. $('#error').html('Error: Cannot fetch the example data because of security restrictions in JavaScript. Run the example from a server instead of as a local file to resolve this problem. Alternatively, you can copy/paste the data of DOT graphs manually in the textarea below.');
  148. resize();
  149. });
  150. });
  151. $(window).resize(resize);
  152. $(window).load(draw);
  153. $('#data').keydown(function (event) {
  154. if (event.ctrlKey && event.keyCode === 13) { // Ctrl+Enter
  155. draw();
  156. event.stopPropagation();
  157. event.preventDefault();
  158. }
  159. });
  160. function resize() {
  161. $('#contents').height($('body').height() - $('#header').height() - 30);
  162. }
  163. function draw () {
  164. try {
  165. resize();
  166. $('#error').html('');
  167. // Provide a string with data in DOT language
  168. data = vis.network.convertDot($('#data').val());
  169. network.setData(data);
  170. }
  171. catch (err) {
  172. // set the cursor at the position where the error occurred
  173. var match = /\(char (.*)\)/.exec(err);
  174. if (match) {
  175. var pos = Number(match[1]);
  176. var textarea = $('#data')[0];
  177. if(textarea.setSelectionRange) {
  178. textarea.focus();
  179. textarea.setSelectionRange(pos, pos);
  180. }
  181. }
  182. // show an error message
  183. $('#error').html(err.toString());
  184. }
  185. }
  186. </script>
  187. </body>
  188. </html>