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
20 KiB

  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Test</title>
  5. <meta http-equiv="x-ua-compatible" content="IE=Edge" />
  6. <style type="text/css">
  7. </style>
  8. <script type="text/javascript" src="../dist/vis.js"></script>
  9. <link type="text/css" rel="stylesheet" href="../dist/vis.css">
  10. <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
  11. </head>
  12. <body>
  13. <input type="button" id="changeVis" value="ChangeVis"/>
  14. <div id="kl" style="position:absolute;height:700px; width:1200px;float:left;border: 2px solid #0094ff;overflow:auto">
  15. </div>
  16. <script>
  17. var graph = null;
  18. var chartVisual = null;
  19. window.onload = function () {
  20. chartVisual = new weve.cg.view.ChartVisual();
  21. chartVisual.LoadChart();
  22. }
  23. //
  24. // Copyright � 2011-2015 Cambridge Intelligence Limited.
  25. // All rights reserved.
  26. //
  27. // Sample Code
  28. // Click here to see the code in action: Combos 1
  29. var weve = weve || {};
  30. weve.cg = weve.cg || {};
  31. weve.cg.view = weve.cg.view || {};
  32. network = {};
  33. nodes = new vis.DataSet();
  34. edges = new vis.DataSet();
  35. // Javascript Constructor - The Main Graph object
  36. weve.cg.view.ChartVisual = function () {
  37. nodes2 = new vis.DataSet([
  38. { label: "0", id: "d0" },
  39. { label: "1", id: "d1" },
  40. { label: "2", id: "d2" },
  41. { label: "3", id: "d3" },
  42. { label: "4", id: "d4" },
  43. { label: "5", id: "d5" },
  44. { label: "6", id: "d6" },
  45. { label: "7", id: "d7" },
  46. { label: "8", id: "d8" },
  47. { label: "9", id: "d9" },
  48. { label: "10", id: "d10" },
  49. { label: "11", id: "d11" },
  50. { label: "12", id: "d12" },
  51. { label: "13", id: "d13" },
  52. { label: "14", id: "d14" },
  53. { label: "15", id: "d15" },
  54. { label: "16", id: "d16" },
  55. { label: "17", id: "d17" },
  56. { label: "18", id: "d18" },
  57. { label: "19", id: "d19" },
  58. { label: "20", id: "d20" },
  59. { label: "21", id: "d21" },
  60. { label: "22", id: "d22" },
  61. { label: "23", id: "d23" },
  62. { label: "24", id: "d24" },
  63. { label: "25", id: "d25" },
  64. { label: "26", id: "d26" },
  65. { label: "27", id: "d27" },
  66. { label: "28", id: "d28" },
  67. { label: "29", id: "d29" },
  68. { label: "30", id: "d30" },
  69. { label: "31", id: "d31" },
  70. { label: "32", id: "d32" },
  71. { label: "33", id: "d33" },
  72. { label: "34", id: "d34" },
  73. { label: "35", id: "d35" },
  74. { label: "36", id: "d36" },
  75. { label: "37", id: "d37" },
  76. { label: "38", id: "d38" },
  77. { label: "39", id: "d39" },
  78. { label: "40", id: "d40" },
  79. { label: "41", id: "d41" },
  80. { label: "42", id: "d42" },
  81. { label: "43", id: "d43" },
  82. { label: "44", id: "d44" },
  83. { label: "45", id: "d45" },
  84. { label: "46", id: "d46" },
  85. { label: "47", id: "d47" },
  86. { label: "48", id: "d48" },
  87. { label: "49", id: "d49" },
  88. { label: "50", id: "d50" },
  89. { label: "51", id: "d51" },
  90. { label: "52", id: "d52" },
  91. { label: "53", id: "d53" },
  92. { label: "54", id: "d54" },
  93. { label: "55", id: "d55" },
  94. { label: "56", id: "d56" },
  95. { label: "57", id: "d57" },
  96. { label: "58", id: "d58" },
  97. { label: "59", id: "d59" },
  98. { label: "60", id: "d60" },
  99. { label: "61", id: "d61" },
  100. { label: "62", id: "d62" },
  101. { label: "63", id: "d63" },
  102. { label: "64", id: "d64" },
  103. { label: "65", id: "d65" },
  104. { label: "66", id: "d66" },
  105. { label: "67", id: "d67" },
  106. { label: "68", id: "d68" },
  107. { label: "69", id: "d69" },
  108. { label: "70", id: "d70" },
  109. { label: "71", id: "d71" },
  110. { label: "72", id: "d72" },
  111. { label: "73", id: "d73" },
  112. { label: "74", id: "d74" },
  113. { label: "75", id: "d75" },
  114. { label: "76", id: "d76" },
  115. { label: "77", id: "d77" },
  116. { label: "78", id: "d78" },
  117. { label: "79", id: "d79" },
  118. { label: "80", id: "d80" },
  119. { label: "81", id: "d81" },
  120. { label: "82", id: "d82" },
  121. { label: "83", id: "d83" },
  122. { label: "84", id: "d84" },
  123. { label: "85", id: "d85" },
  124. { label: "86", id: "d86" },
  125. { label: "87", id: "d87" },
  126. { label: "88", id: "d88" },
  127. { label: "89", id: "d89" },
  128. { label: "90", id: "d90" },
  129. { label: "91", id: "d91" },
  130. { label: "92", id: "d92" },
  131. { label: "93", id: "d93" },
  132. { label: "94", id: "d94" },
  133. { label: "95", id: "d95" },
  134. { label: "96", id: "d96" },
  135. { label: "97", id: "d97" },
  136. { label: "98", id: "d98" },
  137. { label: "99", id: "d99" },
  138. { label: "100", id: "d100" },
  139. { label: "101", id: "d101" },
  140. { label: "102", id: "d102" },
  141. { label: "103", id: "d103" },
  142. { label: "104", id: "d104" },
  143. { label: "105", id: "d105" },
  144. { label: "106", id: "d106" },
  145. { label: "107", id: "d107" },
  146. { label: "108", id: "d108" },
  147. { label: "109", id: "d109" },
  148. { label: "110", id: "d110" },
  149. { label: "111", id: "d111" },
  150. { label: "112", id: "d112" },
  151. { label: "113", id: "d113" },
  152. { label: "114", id: "d114" },
  153. { label: "115", id: "d115" },
  154. { label: "116", id: "d116" },
  155. { label: "117", id: "d117" },
  156. { label: "118", id: "d118" },
  157. { label: "119", id: "d119" },
  158. { label: "120", id: "d120" },
  159. { label: "121", id: "d121" },
  160. { label: "122", id: "d122" },
  161. { label: "123", id: "d123" },
  162. { label: "124", id: "d124" },
  163. { label: "125", id: "d125" },
  164. { label: "126", id: "d126" },
  165. { label: "127", id: "d127" },
  166. { label: "128", id: "d128" },
  167. { label: "129", id: "d129" },
  168. { label: "130", id: "d130" },
  169. { label: "131", id: "d131" },
  170. { label: "132", id: "d132" },
  171. { label: "133", id: "d133" },
  172. { label: "134", id: "d134" },
  173. { label: "135", id: "d135" },
  174. { label: "136", id: "d136" },
  175. { label: "137", id: "d137" },
  176. { label: "138", id: "d138" },
  177. { label: "139", id: "d139" },
  178. { label: "140", id: "d140" },
  179. { label: "141", id: "d141" },
  180. { label: "142", id: "d142" },
  181. { label: "143", id: "d143" },
  182. { label: "144", id: "d144" },
  183. { label: "145", id: "d145" },
  184. { label: "146", id: "d146" },
  185. { label: "147", id: "d147" },
  186. { label: "148", id: "d148" },
  187. { label: "149", id: "d149" },
  188. { label: "150", id: "d150" },
  189. { label: "151", id: "d151" },
  190. { label: "152", id: "d152" },
  191. { label: "153", id: "d153" },
  192. { label: "154", id: "d154" },
  193. { label: "155", id: "d155" },
  194. { label: "156", id: "d156" },
  195. { label: "157", id: "d157" },
  196. { label: "158", id: "d158" },
  197. { label: "159", id: "d159" },
  198. { label: "160", id: "d160" },
  199. { label: "161", id: "d161" },
  200. { label: "162", id: "d162" },
  201. { label: "163", id: "d163" }
  202. ]);
  203. edges2 = new vis.DataSet([
  204. { from: "d0", to: "d2" },
  205. { from: "d1", to: "d0" },
  206. { from: "d2", to: "d1" },
  207. { from: "d3", to: "d2" },
  208. { from: "d4", to: "d3" },
  209. { from: "d5", to: "d4" },
  210. { from: "d6", to: "d5" },
  211. { from: "d7", to: "d6" },
  212. { from: "d8", to: "d7" },
  213. { from: "d9", to: "d8" },
  214. { from: "d10", to: "d9" },
  215. { from: "d11", to: "d10" },
  216. { from: "d12", to: "d11" },
  217. { from: "d13", to: "d12" },
  218. { from: "d14", to: "d13" },
  219. { from: "d15", to: "d14" },
  220. { from: "d16", to: "d15" },
  221. { from: "d17", to: "d16" },
  222. { from: "d18", to: "d17" },
  223. { from: "d19", to: "d18" },
  224. { from: "d20", to: "d19" },
  225. { from: "d21", to: "d20" },
  226. { from: "d22", to: "d21" },
  227. { from: "d23", to: "d22" },
  228. { from: "d24", to: "d23" },
  229. { from: "d25", to: "d24" },
  230. { from: "d26", to: "d25" },
  231. { from: "d27", to: "d26" },
  232. { from: "d28", to: "d27" },
  233. { from: "d29", to: "d28" },
  234. { from: "d30", to: "d29" },
  235. { from: "d31", to: "d30" },
  236. { from: "d32", to: "d31" },
  237. { from: "d33", to: "d32" },
  238. { from: "d34", to: "d33" },
  239. { from: "d35", to: "d34" },
  240. { from: "d36", to: "d35" },
  241. { from: "d37", to: "d36" },
  242. { from: "d38", to: "d37" },
  243. { from: "d39", to: "d38" },
  244. { from: "d40", to: "d39" },
  245. { from: "d41", to: "d40" },
  246. { from: "d42", to: "d41" },
  247. { from: "d43", to: "d42" },
  248. { from: "d44", to: "d43" },
  249. { from: "d45", to: "d44" },
  250. { from: "d46", to: "d45" },
  251. { from: "d47", to: "d46" },
  252. { from: "d48", to: "d47" },
  253. { from: "d49", to: "d48" },
  254. { from: "d50", to: "d49" },
  255. { from: "d51", to: "d50" },
  256. { from: "d52", to: "d51" },
  257. { from: "d53", to: "d52" },
  258. { from: "d54", to: "d53" },
  259. { from: "d55", to: "d54" },
  260. { from: "d56", to: "d55" },
  261. { from: "d57", to: "d56" },
  262. { from: "d58", to: "d57" },
  263. { from: "d59", to: "d58" },
  264. { from: "d60", to: "d59" },
  265. { from: "d61", to: "d60" },
  266. { from: "d62", to: "d61" },
  267. { from: "d63", to: "d62" },
  268. { from: "d64", to: "d63" },
  269. { from: "d65", to: "d64" },
  270. { from: "d66", to: "d65" },
  271. { from: "d67", to: "d66" },
  272. { from: "d68", to: "d67" },
  273. { from: "d69", to: "d68" },
  274. { from: "d70", to: "d69" },
  275. { from: "d71", to: "d70" },
  276. { from: "d72", to: "d71" },
  277. { from: "d73", to: "d72" },
  278. { from: "d74", to: "d73" },
  279. { from: "d75", to: "d74" },
  280. { from: "d76", to: "d75" },
  281. { from: "d77", to: "d76" },
  282. { from: "d78", to: "d77" },
  283. { from: "d79", to: "d78" },
  284. { from: "d80", to: "d79" },
  285. { from: "d81", to: "d80" },
  286. { from: "d82", to: "d81" },
  287. { from: "d83", to: "d82" },
  288. { from: "d84", to: "d83" },
  289. { from: "d85", to: "d84" },
  290. { from: "d86", to: "d85" },
  291. { from: "d87", to: "d86" },
  292. { from: "d88", to: "d87" },
  293. { from: "d89", to: "d88" },
  294. { from: "d90", to: "d89" },
  295. { from: "d91", to: "d90" },
  296. { from: "d92", to: "d91" },
  297. { from: "d93", to: "d92" },
  298. { from: "d94", to: "d93" },
  299. { from: "d95", to: "d94" },
  300. { from: "d96", to: "d95" },
  301. { from: "d97", to: "d96" },
  302. { from: "d98", to: "d97" },
  303. { from: "d99", to: "d98" },
  304. { from: "d100", to: "d99" },
  305. { from: "d101", to: "d100" },
  306. { from: "d102", to: "d101" },
  307. { from: "d103", to: "d102" },
  308. { from: "d104", to: "d103" },
  309. { from: "d105", to: "d104" },
  310. { from: "d106", to: "d105" },
  311. { from: "d107", to: "d106" },
  312. { from: "d108", to: "d107" },
  313. { from: "d109", to: "d108" },
  314. { from: "d110", to: "d109" },
  315. { from: "d111", to: "d110" },
  316. { from: "d112", to: "d111" },
  317. { from: "d113", to: "d112" },
  318. { from: "d114", to: "d113" },
  319. { from: "d115", to: "d114" },
  320. { from: "d116", to: "d115" },
  321. { from: "d117", to: "d116" },
  322. { from: "d118", to: "d117" },
  323. { from: "d119", to: "d118" },
  324. { from: "d120", to: "d119" },
  325. { from: "d121", to: "d120" },
  326. { from: "d122", to: "d121" },
  327. { from: "d123", to: "d122" },
  328. { from: "d124", to: "d123" },
  329. { from: "d125", to: "d124" },
  330. { from: "d126", to: "d125" },
  331. { from: "d127", to: "d126" },
  332. { from: "d128", to: "d127" },
  333. { from: "d129", to: "d128" },
  334. { from: "d130", to: "d129" },
  335. { from: "d131", to: "d130" },
  336. { from: "d132", to: "d131" },
  337. { from: "d133", to: "d132" },
  338. { from: "d134", to: "d133" },
  339. { from: "d135", to: "d134" },
  340. { from: "d136", to: "d135" },
  341. { from: "d137", to: "d136" },
  342. { from: "d138", to: "d137" },
  343. { from: "d139", to: "d138" },
  344. { from: "d140", to: "d139" },
  345. { from: "d141", to: "d140" },
  346. { from: "d142", to: "d141" },
  347. { from: "d143", to: "d142" },
  348. { from: "d144", to: "d143" },
  349. { from: "d145", to: "d144" },
  350. { from: "d146", to: "d145" },
  351. { from: "d147", to: "d146" },
  352. { from: "d148", to: "d147" },
  353. { from: "d149", to: "d148" },
  354. { from: "d150", to: "d149" },
  355. { from: "d151", to: "d150" },
  356. { from: "d152", to: "d151" },
  357. { from: "d153", to: "d152" },
  358. { from: "d154", to: "d153" },
  359. { from: "d155", to: "d154" },
  360. { from: "d156", to: "d155" },
  361. { from: "d157", to: "d156" },
  362. { from: "d158", to: "d157" }
  363. ]);
  364. nodes = nodes2;
  365. edges = edges2;
  366. this.totalEdgesAdded = 0;
  367. this.fitOnDone = false;
  368. this.fitOnDoneIterations = 0;
  369. this.options = {
  370. nodes: {
  371. shape: 'dot',
  372. scaling: {
  373. label: {
  374. min: weve.cg.view.ChartVisual.minFont_largeGroup,
  375. max: weve.cg.view.ChartVisual.maxFont_largeGroup
  376. },
  377. }
  378. },
  379. edges: {
  380. smooth: {
  381. enabled: true,
  382. type: "dynamic",
  383. // roundness: 0.5
  384. },
  385. },
  386. interaction: {
  387. multiselect: false,
  388. navigationButtons: true,
  389. selectable: true,
  390. selectConnectedEdges: true,
  391. tooltipDelay: 100,
  392. zoomView: true
  393. },
  394. physics: {
  395. stabilization: {
  396. enabled: true,
  397. iterations: 250, // maximum number of iteration to stabilize
  398. updateInterval: 5,
  399. onlyDynamicEdges: false,
  400. fit: true
  401. }
  402. }
  403. };
  404. };
  405. weve.cg.view.ChartVisual.minFont_smallGroup = 7;
  406. weve.cg.view.ChartVisual.maxFont_smallGroup = 10;
  407. weve.cg.view.ChartVisual.minFont_largeGroup = 20;
  408. weve.cg.view.ChartVisual.maxFont_largeGroup = 25;
  409. weve.cg.view.ChartVisual.prototype.LoadChart = function (viewModel, callBack) {
  410. var g = this;
  411. var container = document.getElementById('kl');
  412. var data = {
  413. nodes: nodes,
  414. edges: edges
  415. };
  416. this.viewModel = viewModel;
  417. network = new vis.Network(container, data, this.options);
  418. this.startpercentage = 60;
  419. network.on("click",this.neighbourhoodHighlight);
  420. }
  421. weve.cg.view.ChartVisual.prototype.neighbourhoodHighlight = function(params) {
  422. // if something is selected:
  423. var allNodes = nodes.get({returnType:"Object"});
  424. var allEdges = edges.get({returnType:"Object"});
  425. if (params.nodes.length > 0) {
  426. this.highlightActive = true;
  427. var i,j;
  428. var selectedNode = params.nodes[0];
  429. var degrees = 1;
  430. // mark all nodes as hard to read.
  431. for (var nodeId in allNodes) {
  432. allNodes[nodeId].originalColor = allNodes[nodeId].color;
  433. allNodes[nodeId].color = 'rgba(200,200,200,0.5)';
  434. allNodes[nodeId].hiddenLabel = allNodes[nodeId].label;
  435. allNodes[nodeId].label = undefined;
  436. //allNodes[nodeId].hidden = true;
  437. }
  438. var connectedNodes = network.getConnectedNodes(selectedNode);
  439. var allConnectedNodes = [];
  440. // all first degree nodes get their own color and their label back
  441. for (i = 0; i < connectedNodes.length; i++) {
  442. allNodes[connectedNodes[i]].color = allNodes[connectedNodes[i]].originalColor;
  443. if (allNodes[connectedNodes[i]].hiddenLabel !== undefined) {
  444. allNodes[connectedNodes[i]].label = allNodes[connectedNodes[i]].hiddenLabel;
  445. allNodes[connectedNodes[i]].hiddenLabel = undefined;
  446. //allNodes[nodeId].hidden = false;
  447. }
  448. }
  449. // the main node gets its own color and its label back.
  450. allNodes[selectedNode].color = allNodes[selectedNode].originalColor;
  451. if (allNodes[selectedNode].hiddenLabel !== undefined) {
  452. allNodes[selectedNode].label = allNodes[selectedNode].hiddenLabel;
  453. allNodes[selectedNode].hiddenLabel = undefined;
  454. //allNodes[nodeId].hidden = false;
  455. }
  456. var selectedEdges = params.edges;
  457. for (var edgeId in allEdges) {
  458. var edge = allEdges[edgeId];
  459. edge.regularWidth = edge.width; //store the original width.
  460. if (selectedEdges.indexOf(edge.id) == -1)
  461. {
  462. edge.width = 0.01;
  463. //edge.hidden = true;
  464. }
  465. }
  466. }
  467. else if (this.highlightActive === true) {
  468. // reset all nodes
  469. for (var nodeId in allNodes) {
  470. allNodes[nodeId].color = allNodes[nodeId].originalColor;
  471. if (allNodes[nodeId].hiddenLabel !== undefined) {
  472. allNodes[nodeId].label = allNodes[nodeId].hiddenLabel;
  473. allNodes[nodeId].hiddenLabel = undefined;
  474. //allNodes[nodeId].hidden = false;
  475. }
  476. }
  477. for (var edgeIds in allEdges) {
  478. var edge = allEdges[edgeIds];
  479. edge.width = edge.regularWidth; //restore the original width.
  480. //edge.hidden= false;
  481. }
  482. this.highlightActive = false
  483. }
  484. // transform the object into an array
  485. var updateArray = [];
  486. for (nodeId in allNodes) {
  487. if (allNodes.hasOwnProperty(nodeId)) {
  488. updateArray.push(allNodes[nodeId]);
  489. }
  490. }
  491. // transform the object into an array
  492. var updateEdgesArray = [];
  493. for (edgeId in allEdges) {
  494. if (allEdges.hasOwnProperty(edgeId)) {
  495. updateEdgesArray.push(allEdges[edgeId]);
  496. }
  497. }
  498. nodes.update(updateArray);
  499. edges.update(updateEdgesArray);
  500. console.log("edges", updateEdgesArray)
  501. //this.refreshUILayout(1000);
  502. }
  503. </script>
  504. </body>
  505. </html>