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.

269 lines
7.6 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <script src="../dist/vis.js"></script>
  5. <link href="../dist/vis.css" rel="stylesheet" type="text/css" />
  6. <style type="text/css">
  7. .graph {
  8. width: 600px;
  9. height: 500px;
  10. } </style>
  11. </head>
  12. <body>
  13. STATIC GRAPH EXAMPLE
  14. <pre>
  15. Issue 1:
  16. 1) Bring your cursor over a node, e.g. "Kill the Dragon" without clicking!
  17. 2) Now try to drag it straight downwards (fast and straight!). It seems that nodes only(!) move when they are at one point also moved on the x axis, otherwise when trying to move them up or down initially they keep standing still. I tested this in chrome and ff on linux. If you cannot reproduce it on the first drag, please go to another node and try dragging it straight downwards (or alternatively upwards)
  18. Issue 2:
  19. After dragging a node far to the outside, move the canvas (viewport). The node you just moved will start swirling around again even though it is "fixed".
  20. Issue 3:
  21. 1) Please go to a node in the jsbin (the actual code).
  22. 2) Remove x and y specification from one of the json node objects (JSON). But leave (!) the "fixed" property.
  23. 3) Reload the bin and you'll get a "too much recursion" error (console).
  24. </pre>
  25. <div class="graph" id="visualization1"></div>
  26. <button onclick="javascript:action()">Click me</button>
  27. <script type="text/javascript">
  28. var action = function() {
  29. var container = document.getElementById("visualization");
  30. container.parentNode.removeChild(container);
  31. }
  32. var nodes = new vis.DataSet([
  33. {
  34. "color": {
  35. "background": "#c79df1"
  36. },
  37. "label": "Compose ballad",
  38. "group": "matches",
  39. "id": "7BEF6C80-B285-48B3-9736-F0845E612A4F",
  40. "x": -100,
  41. "y": 0,
  42. },
  43. {
  44. "color": {
  45. "background": "#e2e3ab"
  46. },
  47. "label": "Get the Ring",
  48. "group": "matches",
  49. "id": "E255F767-A447-46D7-865C-494C782FC034",
  50. "x": -317,
  51. "y": 8,
  52. },
  53. {
  54. "color": {
  55. "background": "#7fedb3"
  56. },
  57. "label": "Go to Mordor",
  58. "group": "matches",
  59. "id": "7E692850-2846-41ED-8E7D-F58E7F39680D",
  60. "x": -190,
  61. "y": -101,
  62. },
  63. {
  64. "color": {
  65. "background": "#dd9c9c"
  66. },
  67. "label": "Kill the Dragon",
  68. "group": "matches",
  69. "id": "51CB2809-A6E9-46A7-AFEA-42DEF2228C59",
  70. "x": 316,
  71. "y": -233,
  72. },
  73. {
  74. "color": {
  75. "background": "#a6b8e3"
  76. },
  77. "label": "Make the beds",
  78. "fontColor": "#000000",
  79. "group": "matches",
  80. "id": "2",
  81. "x": 214,
  82. "y": 160,
  83. }
  84. ]);
  85. var edges = new vis.DataSet([
  86. {
  87. "id": "6A5795CA-2B17-4133-AB83-E63563935A7B",
  88. "from": "7BEF6C80-B285-48B3-9736-F0845E612A4F",
  89. "to": "E255F767-A447-46D7-865C-494C782FC034",
  90. "type": "maybe also",
  91. "label": "maybe also",
  92. "color": "red",
  93. "style": "dash-line"
  94. },
  95. {
  96. "id": "91DD50F4-BA3A-43CD-A27C-5FE3C8C676A3",
  97. "from": "7BEF6C80-B285-48B3-9736-F0845E612A4F",
  98. "to": "2",
  99. "type": "then",
  100. "label": "then",
  101. "color": "slateGray",
  102. "labelAlignment": "line-above"
  103. },
  104. {
  105. "id": "3128CD68-781A-4942-A2EB-FB6AFF0BBEC1",
  106. "from": "7E692850-2846-41ED-8E7D-F58E7F39680D",
  107. "to": "51CB2809-A6E9-46A7-AFEA-42DEF2228C59",
  108. "type": "then",
  109. "label": "then",
  110. "color": "slateGray",
  111. "labelAlignment": "line-above"
  112. },
  113. {
  114. "id": "3C620D0A-3A27-41EF-AE3B-A66F5833F63F",
  115. "from": "51CB2809-A6E9-46A7-AFEA-42DEF2228C59",
  116. "to": "7BEF6C80-B285-48B3-9736-F0845E612A4F",
  117. "type": "then",
  118. "label": "then",
  119. "color": "slateGray",
  120. "labelAlignment": "line-above"
  121. }
  122. ]);
  123. var data = {
  124. nodes: nodes,
  125. edges: edges
  126. };
  127. var options = {
  128. "autoResize": true,
  129. "height": "100%",
  130. "width": "100%",
  131. "interaction": {
  132. "dragNodes":true,
  133. "dragView": true,
  134. "hideEdgesOnDrag": false,
  135. "hideNodesOnDrag": false,
  136. "hover": false,
  137. "navigationButtons": true,
  138. "selectable": true,
  139. "selectConnectedEdges": true,
  140. "tooltipDelay": 300,
  141. "zoomView": true,
  142. "keyboard": {
  143. "enabled": false,
  144. "speed": {
  145. "x": 10,
  146. "y": 10,
  147. "zoom": 0.02
  148. },
  149. "bindToWindow": true
  150. }
  151. },
  152. "nodes": {
  153. "shape": "box",
  154. "color": {
  155. "border" : "#2B7CE9",
  156. "background" : "#97C2FC",
  157. "highlight": {
  158. "border": "#2B7CE9",
  159. "background": "#D2E5FF"
  160. },
  161. "hover": {
  162. "border": "white",
  163. "background": "white"
  164. }
  165. }
  166. },
  167. "physics": {
  168. "barnesHut": {
  169. "centralGravity": 0,
  170. "springLength": 240
  171. }
  172. },
  173. "groups": {
  174. "neighbours": {
  175. "color": "#E6E6E6"
  176. },
  177. "matches": {
  178. "color": "#97C2FC"
  179. }
  180. },
  181. "locale": "en_EN"
  182. }
  183. ;
  184. var container = document.getElementById("visualization1");
  185. var network = new vis.Network(container, data, options);
  186. var hasNetworkStabilized = false;
  187. network.on("stabilized", function(properties) {
  188. if(!hasNetworkStabilized) {
  189. hasNetworkStabilized = true;
  190. network.storePositions();
  191. setNodesMoveable(data.nodes.get(), false);
  192. network.fit();
  193. }
  194. });
  195. // network.on("dragStart", function(properties) {
  196. // console.log("here",properties)
  197. // if(properties.nodes.length) {
  198. // var node = data.nodes.get(properties.nodes[0]);
  199. // setNodesMoveable([ node ], true);
  200. // }
  201. // });
  202. //
  203. // network.on("dragEnd", function(properties) {
  204. // console.log('end',properties)
  205. // if(properties.nodes.length) {
  206. // var node = data.nodes.get(properties.nodes[0]);
  207. // setNodesMoveable([ node ], false);
  208. // }
  209. // });
  210. setNodesMoveable = function(nodes, isMoveable) {
  211. // first store positions
  212. // network.storePositions();
  213. var updates = [];
  214. var keys = Object.keys(nodes);
  215. for(var i = 0; i < keys.length; i++) {
  216. var id = nodes[keys[i]].id;
  217. var update = {
  218. id: id,
  219. physics:false
  220. };
  221. updates.push(update);
  222. }
  223. data.nodes.update(updates);
  224. console.log(updates);
  225. };
  226. </script>
  227. </body>
  228. </html>