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.

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