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.

279 lines
8.2 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: 100%;
  9. height: 500px;
  10. } </style>
  11. </head>
  12. <body>
  13. Visjs does not recognize fixing of nodes after drag & drop of a node; nodes jump back to original position.
  14. <pre></pre>
  15. <div class="graph" id="visualization1"></div>
  16. <div id="config"></div>
  17. <script type="text/javascript">
  18. var graph = {
  19. "edges": [
  20. {
  21. "id": "2ef44388-2d14-4db0-a2c7-9bd27235a17f",
  22. "from": "8044e455-d507-432e-bbc7-0d0308d29516",
  23. "to": "80f69421-1bc0-4ea2-8eed-b9df6caac6a6",
  24. "type": "tmap:unknown",
  25. "title": "Automatically assigned to an edge that does not have a type assigned",
  26. "color": "#f43bb1"
  27. },
  28. {
  29. "id": "181f6f8f-f170-4e92-8dcb-01504d864102",
  30. "from": "8044e455-d507-432e-bbc7-0d0308d29516",
  31. "to": "67942477-eb7b-43c0-a9f9-7cc0d46664ca",
  32. "type": "tmap:unknown",
  33. "title": "Automatically assigned to an edge that does not have a type assigned",
  34. "color": "#f43bb1"
  35. },
  36. {
  37. "id": "aef8b80b-d072-4c6b-bb73-c892f1cb6feb",
  38. "from": "80f69421-1bc0-4ea2-8eed-b9df6caac6a6",
  39. "to": "1b678c21-fc88-46c8-9a96-b3fbe22ecef0",
  40. "type": "tmap:unknown",
  41. "title": "Automatically assigned to an edge that does not have a type assigned",
  42. "color": "#f43bb1"
  43. },
  44. {
  45. "id": "919f7789-500b-45d7-a129-4f29141155b9",
  46. "from": "67942477-eb7b-43c0-a9f9-7cc0d46664ca",
  47. "to": "ecfbe4b8-fa35-40ec-94e6-ed859a4c8f0f",
  48. "type": "tmap:unknown",
  49. "title": "Automatically assigned to an edge that does not have a type assigned",
  50. "color": "#f43bb1"
  51. },
  52. {
  53. "id": "992cf67b-4f05-4ec7-9f90-9723f829a051",
  54. "from": "ed61cb00-8e20-4c5f-a3ee-fe7417b6b08b",
  55. "to": "eeea9c37-3335-41b6-a9e3-47b44438d0d5",
  56. "type": "tmap:unknown",
  57. "title": "Automatically assigned to an edge that does not have a type assigned",
  58. "color": "#f43bb1"
  59. },
  60. {
  61. "id": "e70fd8ed-231e-4608-869a-846c1b3264b0",
  62. "from": "eeea9c37-3335-41b6-a9e3-47b44438d0d5",
  63. "to": "8044e455-d507-432e-bbc7-0d0308d29516",
  64. "type": "tmap:unknown",
  65. "title": "Automatically assigned to an edge that does not have a type assigned",
  66. "color": "#f43bb1"
  67. }
  68. ],
  69. "nodes": [
  70. {
  71. "id": "8044e455-d507-432e-bbc7-0d0308d29516",
  72. "label": "Temple of Ihola",
  73. "x": 409,
  74. "y": 170,
  75. "fixed": {
  76. "x": true,
  77. "y": true
  78. },
  79. "color": {},
  80. "shape": "icon",
  81. "icon": {
  82. "shape": "icon",
  83. "face": "FontAwesome",
  84. "code": ""
  85. },
  86. "font": {
  87. "color": "black"
  88. }
  89. },
  90. {
  91. "id": "ecfbe4b8-fa35-40ec-94e6-ed859a4c8f0f",
  92. "label": "Temple of Sar",
  93. "x": 763,
  94. "y": 320,
  95. "fixed": {
  96. "x": true,
  97. "y": true
  98. },
  99. "color": {},
  100. "shape": "icon",
  101. "icon": {
  102. "shape": "icon",
  103. "face": "FontAwesome",
  104. "code": ""
  105. },
  106. "font": {
  107. "color": "black"
  108. }
  109. },
  110. {
  111. "id": "80f69421-1bc0-4ea2-8eed-b9df6caac6a6",
  112. "label": "Diamond mine",
  113. "x": 331,
  114. "y": 458,
  115. "fixed": {
  116. "x": true,
  117. "y": true
  118. },
  119. "color": {},
  120. "shape": "icon",
  121. "icon": {
  122. "shape": "icon",
  123. "face": "FontAwesome",
  124. "code": ""
  125. },
  126. "font": {
  127. "color": "black"
  128. }
  129. },
  130. {
  131. "id": "67942477-eb7b-43c0-a9f9-7cc0d46664ca",
  132. "label": "Castle of the Winds",
  133. "x": 664,
  134. "y": 132,
  135. "fixed": {
  136. "x": true,
  137. "y": true
  138. },
  139. "color": {},
  140. "shape": "icon",
  141. "icon": {
  142. "shape": "icon",
  143. "face": "FontAwesome",
  144. "code": ""
  145. },
  146. "font": {
  147. "color": "black"
  148. }
  149. },
  150. {
  151. "id": "ed61cb00-8e20-4c5f-a3ee-fe7417b6b08b",
  152. "label": "Start",
  153. "x": 94,
  154. "y": 314,
  155. "fixed": {
  156. "x": true,
  157. "y": true
  158. },
  159. "color": {},
  160. "font": {}
  161. },
  162. {
  163. "id": "eeea9c37-3335-41b6-a9e3-47b44438d0d5",
  164. "label": "Black forest",
  165. "x": 266,
  166. "y": 107,
  167. "fixed": {
  168. "x": true,
  169. "y": true
  170. },
  171. "color": {},
  172. "shape": "icon",
  173. "icon": {
  174. "shape": "icon",
  175. "face": "FontAwesome",
  176. "code": ""
  177. },
  178. "font": {
  179. "color": "black"
  180. }
  181. },
  182. {
  183. "id": "1b678c21-fc88-46c8-9a96-b3fbe22ecef0",
  184. "label": "Dragonland",
  185. "x": 527,
  186. "y": 444,
  187. "fixed": {
  188. "x": true,
  189. "y": true
  190. },
  191. "color": {},
  192. "shape": "icon",
  193. "icon": {
  194. "shape": "icon",
  195. "face": "FontAwesome",
  196. "code": ""
  197. },
  198. "font": {
  199. "color": "black"
  200. }
  201. }
  202. ]
  203. };
  204. var data = {
  205. nodes: new vis.DataSet(graph.nodes),
  206. edges: new vis.DataSet(graph.edges)
  207. };
  208. var options = {
  209. autoResize: true,
  210. height: '100%',
  211. width: '100%',
  212. physics: {
  213. barnesHut: {
  214. centralGravity: 0
  215. }
  216. }
  217. }
  218. ;
  219. var container = document.getElementById("visualization1");
  220. var network = new vis.Network(container, data, options);
  221. var hasNetworkStabilized = false;
  222. network.on("stabilized", function(properties) {
  223. if(!hasNetworkStabilized) {
  224. hasNetworkStabilized = true;
  225. network.fit();
  226. }
  227. });
  228. network.on("dragStart", function(properties) {
  229. if(!properties.nodes.length) return;
  230. setNodesMoveable(properties.nodes, true);
  231. });
  232. network.on("dragEnd", function(properties) {
  233. if(!properties.nodes.length) return;
  234. setNodesMoveable(properties.nodes, false);
  235. });
  236. setNodesMoveable = function(nodeIds, isMoveable) {
  237. // it only works if network.storePositions() is called before
  238. // setting moved nodes to fixed state. In visjs v4.9 this was
  239. // not required.
  240. // network.storePositions();
  241. var updates = [];
  242. var isFixed = !isMoveable;
  243. for(var i = nodeIds.length; i--;) {
  244. updates.push({
  245. id: nodeIds[i],
  246. fixed: { x: isFixed, y: isFixed }
  247. });
  248. }
  249. data.nodes.update(updates);
  250. };
  251. </script>
  252. </body>
  253. </html>