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.

557 lines
17 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: 600px;
  10. } </style>
  11. </head>
  12. <body>
  13. VIEWPORT ISSUES WHEN REPLACING NODES
  14. <pre>
  15. Once the first graph is displayed
  16. 1. move the viewport (not the nodes)
  17. 2. zoom out
  18. 3. press the "fit" button (which used to be zoomExtent) - works fine!
  19. Now
  20. 1. click the "click me" button (at the very bottom below navigation buttons)
  21. 2. the datasets will be cleared and a second graph will be displayed
  22. 3. Maybe wait a few seconds before the stabilization event is fired and the graph is fit again (actually this step is not necessary)
  23. 4. press the "click me button again to switch to the first graph
  24. 5. try to fit the graph by pressing the "fit" button (which used to be zoomExtent)
  25. 6. Neither does it correctly centerize nor is it zoomed (streched) correctly!
  26. </pre>
  27. <div class="graph" id="visualization1"></div>
  28. <button onclick="javascript:action()">Click me</button>
  29. <script type="text/javascript">
  30. // @Alex @Jos THIS IS ONLY DATA - SCCCCCCCCCCCRRROOLLLLLLLLLLLL DOWN
  31. var graph1 = {
  32. "nodes": [
  33. {
  34. "color": "#c79df1",
  35. "label": "Compose ballad",
  36. "title": "Compose ballad",
  37. "font": {
  38. "color": "#000000"
  39. },
  40. "group": "matches",
  41. "id": "7BEF6C80-B285-48B3-9736-F0845E612A4F",
  42. "x": -346,
  43. "y": 26,
  44. "fixed": {
  45. "x": true,
  46. "y": true
  47. }
  48. },
  49. {
  50. "color": "#e2e3ab",
  51. "label": "Get the Ring",
  52. "title": "Get the Ring",
  53. "font": {
  54. "color": "#000000"
  55. },
  56. "group": "matches",
  57. "id": "E255F767-A447-46D7-865C-494C782FC034",
  58. "x": -120,
  59. "y": -31,
  60. "fixed": {
  61. "x": true,
  62. "y": true
  63. }
  64. },
  65. {
  66. "color": "#7fedb3",
  67. "label": "Go to Mordor",
  68. "title": "Go to Mordor",
  69. "font": {
  70. "color": "#000000"
  71. },
  72. "group": "matches",
  73. "id": "7E692850-2846-41ED-8E7D-F58E7F39680D",
  74. "x": -776,
  75. "y": -32,
  76. "fixed": {
  77. "x": true,
  78. "y": true
  79. }
  80. },
  81. {
  82. "color": "#dd9c9c",
  83. "label": "Kill the Dragon",
  84. "title": "Kill the Dragon",
  85. "font": {
  86. "color": "#000000"
  87. },
  88. "group": "matches",
  89. "id": "51CB2809-A6E9-46A7-AFEA-42DEF2228C59",
  90. "x": -559,
  91. "y": 102,
  92. "fixed": {
  93. "x": true,
  94. "y": true
  95. }
  96. },
  97. {
  98. "color": "#a6b8e3",
  99. "label": "Make the beds",
  100. "title": "Make the beds",
  101. "font": {
  102. "color": "#000000"
  103. },
  104. "group": "matches",
  105. "id": "F37FE14F-DBCB-40A5-8055-F4020FFB37BB",
  106. "x": -130,
  107. "y": 156,
  108. "fixed": {
  109. "x": true,
  110. "y": true
  111. }
  112. }
  113. ],
  114. "edges": [
  115. {
  116. "id": "6A5795CA-2B17-4133-AB83-E63563935A7B",
  117. "from": "7BEF6C80-B285-48B3-9736-F0845E612A4F",
  118. "to": "E255F767-A447-46D7-865C-494C782FC034",
  119. "type": "maybe also",
  120. "label": "maybe also",
  121. "color": "red",
  122. "style": "dash-line"
  123. },
  124. {
  125. "id": "91DD50F4-BA3A-43CD-A27C-5FE3C8C676A3",
  126. "from": "7BEF6C80-B285-48B3-9736-F0845E612A4F",
  127. "to": "F37FE14F-DBCB-40A5-8055-F4020FFB37BB",
  128. "type": "then",
  129. "label": "then",
  130. "color": "slateGray",
  131. "labelAlignment": "line-above"
  132. },
  133. {
  134. "id": "3128CD68-781A-4942-A2EB-FB6AFF0BBEC1",
  135. "from": "7E692850-2846-41ED-8E7D-F58E7F39680D",
  136. "to": "51CB2809-A6E9-46A7-AFEA-42DEF2228C59",
  137. "type": "then",
  138. "label": "then",
  139. "color": "slateGray",
  140. "labelAlignment": "line-above"
  141. },
  142. {
  143. "id": "3C620D0A-3A27-41EF-AE3B-A66F5833F63F",
  144. "from": "51CB2809-A6E9-46A7-AFEA-42DEF2228C59",
  145. "to": "7BEF6C80-B285-48B3-9736-F0845E612A4F",
  146. "type": "then",
  147. "label": "then",
  148. "color": "slateGray",
  149. "labelAlignment": "line-above"
  150. }
  151. ]
  152. };
  153. graph2 = {
  154. "nodes": [
  155. {
  156. "color": "#97C2FC",
  157. "label": "Adam",
  158. "title": "Adam",
  159. "group": "matches",
  160. "id": "35b99ac8-aa07-4834-b508-6e9435f573cb",
  161. "x": -100,
  162. "y": -380,
  163. "fixed": {
  164. "x": true,
  165. "y": true
  166. }
  167. },
  168. {
  169. "color": "#97C2FC",
  170. "label": "Betsy",
  171. "title": "Betsy",
  172. "group": "matches",
  173. "id": "38d37e10-3c8b-487c-9757-1061d2bbbd07",
  174. "x": -100,
  175. "y": -540,
  176. "fixed": {
  177. "x": true,
  178. "y": true
  179. }
  180. },
  181. {
  182. "color": "#97C2FC",
  183. "label": "Carol",
  184. "title": "Carol",
  185. "group": "matches",
  186. "id": "4762501a-6bcb-4d35-acfd-f2e9d6310389",
  187. "x": -230,
  188. "y": -380,
  189. "fixed": {
  190. "x": true,
  191. "y": true
  192. }
  193. },
  194. {
  195. "color": "#97C2FC",
  196. "label": "Catherine",
  197. "title": "Catherine",
  198. "group": "matches",
  199. "id": "7e17b617-b7a4-4f70-937b-f45ec8dc0a9d",
  200. "x": -520,
  201. "y": -210,
  202. "fixed": {
  203. "x": true,
  204. "y": true
  205. }
  206. },
  207. {
  208. "color": "#97C2FC",
  209. "label": "Craig",
  210. "title": "Craig",
  211. "group": "matches",
  212. "id": "e017a09b-4526-4b4d-b097-f70e56f20ab4",
  213. "x": 130,
  214. "y": -380,
  215. "fixed": {
  216. "x": true,
  217. "y": true
  218. }
  219. },
  220. {
  221. "color": "#97C2FC",
  222. "label": "George",
  223. "title": "George",
  224. "group": "matches",
  225. "id": "8ec7f3ee-35f9-4c56-a57b-12d91c0c372e",
  226. "x": -360,
  227. "y": -540,
  228. "fixed": {
  229. "x": true,
  230. "y": true
  231. }
  232. },
  233. {
  234. "color": "#97C2FC",
  235. "label": "Jessica",
  236. "title": "Jessica",
  237. "group": "matches",
  238. "id": "8d2a0469-bb6a-4e40-ab1f-3d5edc620415",
  239. "x": 20,
  240. "y": -380,
  241. "fixed": {
  242. "x": true,
  243. "y": true
  244. }
  245. },
  246. {
  247. "color": "#97C2FC",
  248. "label": "John",
  249. "title": "John",
  250. "group": "matches",
  251. "id": "afd75e95-e45a-4dea-848a-e16ca735bc57",
  252. "x": -490,
  253. "y": -540,
  254. "fixed": {
  255. "x": true,
  256. "y": true
  257. }
  258. },
  259. {
  260. "color": "#97C2FC",
  261. "label": "Mary",
  262. "title": "Mary",
  263. "group": "matches",
  264. "id": "9c050064-d805-48b3-80a6-181d3599daff",
  265. "x": -280,
  266. "y": -210,
  267. "fixed": {
  268. "x": true,
  269. "y": true
  270. }
  271. },
  272. {
  273. "color": "#97C2FC",
  274. "label": "Michael",
  275. "title": "Michael",
  276. "group": "matches",
  277. "id": "f24ab062-62a1-4555-a57f-dfcd597c3515",
  278. "x": -30,
  279. "y": -210,
  280. "fixed": {
  281. "x": true,
  282. "y": true
  283. }
  284. },
  285. {
  286. "color": "#97C2FC",
  287. "label": "Michelle",
  288. "title": "Michelle",
  289. "group": "matches",
  290. "id": "59d10b18-1c9e-4dcb-ba4f-988ebd7a3efb",
  291. "x": -610,
  292. "y": -380,
  293. "fixed": {
  294. "x": true,
  295. "y": true
  296. }
  297. },
  298. {
  299. "color": "#97C2FC",
  300. "label": "Robert",
  301. "title": "Robert",
  302. "group": "matches",
  303. "id": "b11149a2-9050-4632-b095-d9d233319b91",
  304. "x": -360,
  305. "y": -380,
  306. "fixed": {
  307. "x": true,
  308. "y": true
  309. }
  310. },
  311. {
  312. "color": "#97C2FC",
  313. "label": "Sharon",
  314. "title": "Sharon",
  315. "group": "matches",
  316. "id": "a1485262-99fe-4b1e-a246-cc70fbb1859a",
  317. "x": -490,
  318. "y": -380,
  319. "fixed": {
  320. "x": true,
  321. "y": true
  322. }
  323. }
  324. ],
  325. "edges": [
  326. {
  327. "id": "62b28c2f-c6dc-4b6b-b108-722eb47d5972",
  328. "from": "35b99ac8-aa07-4834-b508-6e9435f573cb",
  329. "to": "f24ab062-62a1-4555-a57f-dfcd597c3515",
  330. "type": "family:father of",
  331. "label": "father of",
  332. "color": "#bc960d",
  333. "labelAlignment": "line-above"
  334. },
  335. {
  336. "id": "4ae8de41-ef1a-400a-b51b-05662ce24597",
  337. "from": "38d37e10-3c8b-487c-9757-1061d2bbbd07",
  338. "to": "e017a09b-4526-4b4d-b097-f70e56f20ab4",
  339. "type": "family:mother of",
  340. "label": "mother of",
  341. "color": "#eec75b",
  342. "labelAlignment": "line-above"
  343. },
  344. {
  345. "id": "70f6e36a-ce9a-47b4-97e1-14b2df17d204",
  346. "from": "38d37e10-3c8b-487c-9757-1061d2bbbd07",
  347. "to": "8d2a0469-bb6a-4e40-ab1f-3d5edc620415",
  348. "type": "family:mother of",
  349. "label": "mother of",
  350. "color": "#eec75b",
  351. "labelAlignment": "line-above"
  352. },
  353. {
  354. "id": "c32a86ce-ab9a-49b6-a202-e93a37265fda",
  355. "from": "38d37e10-3c8b-487c-9757-1061d2bbbd07",
  356. "to": "b11149a2-9050-4632-b095-d9d233319b91",
  357. "type": "family:mother of",
  358. "label": "mother of",
  359. "color": "#eec75b",
  360. "labelAlignment": "line-above"
  361. },
  362. {
  363. "id": "bbce9cc0-0353-45cd-bfa6-a13834ff7218",
  364. "from": "4762501a-6bcb-4d35-acfd-f2e9d6310389",
  365. "to": "f24ab062-62a1-4555-a57f-dfcd597c3515",
  366. "type": "family:mother of",
  367. "label": "mother of",
  368. "color": "#eec75b",
  369. "labelAlignment": "line-above"
  370. },
  371. {
  372. "id": "deb7eb05-f667-496b-aeda-205c37b2484b",
  373. "from": "8ec7f3ee-35f9-4c56-a57b-12d91c0c372e",
  374. "to": "afd75e95-e45a-4dea-848a-e16ca735bc57",
  375. "type": "family:brother of",
  376. "label": "brother of",
  377. "color": "green",
  378. "labelAlignment": "line-above"
  379. },
  380. {
  381. "id": "3c8c7947-6c82-4f98-978a-26bbb372bfbb",
  382. "from": "afd75e95-e45a-4dea-848a-e16ca735bc57",
  383. "to": "a1485262-99fe-4b1e-a246-cc70fbb1859a",
  384. "type": "family:father of",
  385. "label": "father of",
  386. "color": "#bc960d",
  387. "labelAlignment": "line-above"
  388. },
  389. {
  390. "id": "cd4e71e7-9735-4a42-8632-e88cc01ab64f",
  391. "from": "f24ab062-62a1-4555-a57f-dfcd597c3515",
  392. "to": "9c050064-d805-48b3-80a6-181d3599daff",
  393. "type": "family:brother of",
  394. "label": "brother of",
  395. "color": "green",
  396. "labelAlignment": "line-above"
  397. },
  398. {
  399. "id": "b4499f60-04f9-4306-9c57-3d73b72f37c0",
  400. "from": "59d10b18-1c9e-4dcb-ba4f-988ebd7a3efb",
  401. "to": "7e17b617-b7a4-4f70-937b-f45ec8dc0a9d",
  402. "type": "family:mother of",
  403. "label": "mother of",
  404. "color": "#eec75b",
  405. "labelAlignment": "line-above"
  406. },
  407. {
  408. "id": "16562853-b597-44f6-9c55-2ce8a1fe4f83",
  409. "from": "b11149a2-9050-4632-b095-d9d233319b91",
  410. "to": "7e17b617-b7a4-4f70-937b-f45ec8dc0a9d",
  411. "type": "family:father of",
  412. "label": "father of",
  413. "color": "#bc960d",
  414. "labelAlignment": "line-above"
  415. },
  416. {
  417. "id": "599dd644-e61f-401e-8b17-dfdd340c125e",
  418. "from": "b11149a2-9050-4632-b095-d9d233319b91",
  419. "to": "9c050064-d805-48b3-80a6-181d3599daff",
  420. "type": "family:father of",
  421. "label": "father of",
  422. "color": "#bc960d",
  423. "labelAlignment": "line-above"
  424. },
  425. {
  426. "id": "961f7f2b-5abe-4036-a155-aa9b30ae1260",
  427. "from": "b11149a2-9050-4632-b095-d9d233319b91",
  428. "to": "a1485262-99fe-4b1e-a246-cc70fbb1859a",
  429. "type": "family:married to",
  430. "label": "married to",
  431. "color": "#17bba3",
  432. "labelAlignment": "line-above"
  433. }
  434. ]
  435. };
  436. // OK, OK ENOUGH SCROLLING
  437. // HERE IS THE ACTUAL CODE
  438. var isGraph1Active = true;
  439. var action = function() {
  440. // switch graphs
  441. var graph = isGraph1Active ? graph2 : graph1;
  442. isGraph1Active = !isGraph1Active;
  443. updateGraph(graph.nodes, graph.edges, options);
  444. }
  445. var data = {
  446. nodes: new vis.DataSet(),
  447. edges: new vis.DataSet()
  448. };
  449. var options = {
  450. "autoResize": true,
  451. "height": "100%",
  452. "width": "100%",
  453. "interaction": {
  454. "dragNodes":true,
  455. "dragView": true,
  456. "hideEdgesOnDrag": false,
  457. "hideNodesOnDrag": false,
  458. "hover": false,
  459. "navigationButtons": true,
  460. "selectable": true,
  461. "selectConnectedEdges": true,
  462. "tooltipDelay": 300,
  463. "zoomView": true
  464. },
  465. "nodes": {
  466. "shape": "box",
  467. "color": {
  468. "border" : "#2B7CE9",
  469. "background" : "#97C2FC",
  470. "highlight": {
  471. "border": "#2B7CE9",
  472. "background": "#D2E5FF"
  473. },
  474. "hover": {
  475. "border": "white",
  476. "background": "white"
  477. }
  478. }
  479. },
  480. "physics": {
  481. "barnesHut": {
  482. "centralGravity": 0,
  483. "springLength": 240
  484. }
  485. },
  486. };
  487. var container = document.getElementById("visualization1");
  488. var network = new vis.Network(container, data, options);
  489. var hasNetworkStabilized = false;
  490. var updateGraph = function(nodes, edges, options) {
  491. // clear before redrawing a completely different graph
  492. data.nodes.clear();
  493. data.edges.clear();
  494. // update options for new graph
  495. this.network.setOptions(options);
  496. // allow stabilization again
  497. hasNetworkStabilized = false;
  498. // update data
  499. data.nodes.update(nodes);
  500. data.edges.update(edges);
  501. network.fit()
  502. }
  503. // RUNTIME
  504. updateGraph(graph1.nodes, graph1.edges, options);
  505. </script>
  506. </body>
  507. </html>