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.

787 lines
25 KiB

  1. var fs = require('fs');
  2. var assert = require('assert');
  3. var vis = require('../dist/vis');
  4. var Network = vis.network;
  5. var jsdom_global = require('jsdom-global');
  6. var stdout = require('test-console').stdout;
  7. var Validator = require("./../lib/shared/Validator").default;
  8. //var {printStyle} = require('./../lib/shared/Validator');
  9. // Useful during debugging:
  10. // console.log(JSON.stringify(output, null, 2));
  11. /**
  12. * Merge all options of object b into object b
  13. * @param {Object} a
  14. * @param {Object} b
  15. * @return {Object} a
  16. *
  17. * Adapted merge() in dotparser.js
  18. */
  19. function merge (a, b) {
  20. if (!a) {
  21. a = {};
  22. }
  23. if (b) {
  24. for (var name in b) {
  25. if (b.hasOwnProperty(name)) {
  26. if (typeof b[name] === 'object') {
  27. a[name] = merge(a[name], b[name]);
  28. } else {
  29. a[name] = b[name];
  30. }
  31. }
  32. }
  33. }
  34. return a;
  35. }
  36. /**
  37. * Load legacy-style (i.e. not module) javascript files into the given context.
  38. */
  39. function include(list, context) {
  40. if (!(list instanceof Array)) {
  41. list = [list];
  42. }
  43. for (var n in list) {
  44. var path = list[n];
  45. var arr = [fs.readFileSync(path) + ''];
  46. eval.apply(context, arr);
  47. }
  48. }
  49. /**
  50. * Defined network consists of two sub-networks:
  51. *
  52. * - 1-2-3-4
  53. * - 11-12-13-14
  54. *
  55. * For reference, this is the sample network of issue #1218
  56. */
  57. function createSampleNetwork(options) {
  58. var NumInitialNodes = 8;
  59. var NumInitialEdges = 6;
  60. var nodes = new vis.DataSet([
  61. {id: 1, label: '1'},
  62. {id: 2, label: '2'},
  63. {id: 3, label: '3'},
  64. {id: 4, label: '4'},
  65. {id: 11, label: '11'},
  66. {id: 12, label: '12'},
  67. {id: 13, label: '13'},
  68. {id: 14, label: '14'},
  69. ]);
  70. var edges = new vis.DataSet([
  71. {from: 1, to: 2},
  72. {from: 2, to: 3},
  73. {from: 3, to: 4},
  74. {from: 11, to: 12},
  75. {from: 12, to: 13},
  76. {from: 13, to: 14},
  77. ]);
  78. // create a network
  79. var container = document.getElementById('mynetwork');
  80. var data = {
  81. nodes: nodes,
  82. edges: edges
  83. };
  84. var defaultOptions = {
  85. layout: {
  86. randomSeed: 8
  87. },
  88. edges: {
  89. smooth: {
  90. type: 'continuous' // avoid dynamic here, it adds extra hidden nodes
  91. }
  92. }
  93. };
  94. options = merge(defaultOptions, options);
  95. var network = new vis.Network(container, data, options);
  96. assertNumNodes(network, NumInitialNodes);
  97. assertNumEdges(network, NumInitialEdges);
  98. return [network, data, NumInitialNodes, NumInitialEdges];
  99. };
  100. /**
  101. * Create a cluster for the dynamic data change cases.
  102. *
  103. * Works on the network created by createSampleNetwork().
  104. *
  105. * This is actually a pathological case; there are two separate sub-networks and
  106. * a cluster is made of two nodes, each from one of the sub-networks.
  107. */
  108. function createCluster(network) {
  109. var clusterOptionsByData = {
  110. joinCondition: function(node) {
  111. if (node.id == 1 || node.id == 11) return true;
  112. return false;
  113. },
  114. clusterNodeProperties: {id:"c1", label:'c1'}
  115. }
  116. network.cluster(clusterOptionsByData);
  117. }
  118. /**
  119. * Display node/edge state, useful during debugging
  120. */
  121. function log(network) {
  122. console.log(Object.keys(network.body.nodes));
  123. console.log(network.body.nodeIndices);
  124. console.log(Object.keys(network.body.edges));
  125. console.log(network.body.edgeIndices);
  126. };
  127. /**
  128. * Note that only the node and edges counts are asserted.
  129. * This might be done more thoroughly by explicitly checking the id's
  130. */
  131. function assertNumNodes(network, expectedPresent, expectedVisible) {
  132. if (expectedVisible === undefined) expectedVisible = expectedPresent;
  133. assert.equal(Object.keys(network.body.nodes).length, expectedPresent);
  134. assert.equal(network.body.nodeIndices.length, expectedVisible);
  135. };
  136. /**
  137. * Comment at assertNumNodes() also applies.
  138. */
  139. function assertNumEdges(network, expectedPresent, expectedVisible) {
  140. if (expectedVisible === undefined) expectedVisible = expectedPresent;
  141. assert.equal(Object.keys(network.body.edges).length, expectedPresent);
  142. assert.equal(network.body.edgeIndices.length, expectedVisible);
  143. };
  144. describe('Network', function () {
  145. before(function() {
  146. this.jsdom_global = jsdom_global(
  147. "<div id='mynetwork'></div>",
  148. { skipWindowCheck: true}
  149. );
  150. this.container = document.getElementById('mynetwork');
  151. });
  152. after(function() {
  153. this.jsdom_global();
  154. });
  155. /////////////////////////////////////////////////////
  156. // Local helper methods for Edge and Node testing
  157. /////////////////////////////////////////////////////
  158. /**
  159. * Simplify network creation for local tests
  160. */
  161. function createNetwork(options) {
  162. var [network, data, numNodes, numEdges] = createSampleNetwork(options);
  163. return network;
  164. }
  165. function firstNode(network) {
  166. for (var id in network.body.nodes) {
  167. return network.body.nodes[id];
  168. }
  169. return undefined;
  170. }
  171. function firstEdge(network) {
  172. for (var id in network.body.edges) {
  173. return network.body.edges[id];
  174. }
  175. return undefined;
  176. }
  177. function checkChooserValues(item, chooser, labelChooser) {
  178. if (chooser === 'function') {
  179. assert.equal(typeof item.chooser, 'function');
  180. } else {
  181. assert.equal(item.chooser, chooser);
  182. }
  183. if (labelChooser === 'function') {
  184. assert.equal(typeof item.labelModule.fontOptions.chooser, 'function');
  185. } else {
  186. assert.equal(item.labelModule.fontOptions.chooser, labelChooser);
  187. }
  188. }
  189. describe('Node', function () {
  190. /**
  191. * NOTE: choosify tests of Node and Edge are parallel
  192. * TODO: consolidate this is necessary
  193. */
  194. it('properly handles choosify input', function () {
  195. // check defaults
  196. var options = {};
  197. var network = createNetwork(options);
  198. checkChooserValues(firstNode(network), true, true);
  199. // There's no point in checking invalid values here; these are detected by the options parser
  200. // and subsequently handled as missing input, thus assigned defaults
  201. // check various combinations of valid input
  202. options = {nodes: {chosen: false}};
  203. network = createNetwork(options);
  204. checkChooserValues(firstNode(network), false, false);
  205. options = {nodes: {chosen: { node:true, label:false}}};
  206. network = createNetwork(options);
  207. checkChooserValues(firstNode(network), true, false);
  208. options = {nodes: {chosen: {
  209. node:true,
  210. label: function(value, id, selected, hovering) {}
  211. }}};
  212. network = createNetwork(options);
  213. checkChooserValues(firstNode(network), true, 'function');
  214. options = {nodes: {chosen: {
  215. node: function(value, id, selected, hovering) {},
  216. label:false,
  217. }}};
  218. network = createNetwork(options);
  219. checkChooserValues(firstNode(network), 'function', false);
  220. });
  221. }); // Node
  222. describe('Edge', function () {
  223. /**
  224. * NOTE: choosify tests of Node and Edge are parallel
  225. * TODO: consolidate this is necessary
  226. */
  227. it('properly handles choosify input', function () {
  228. // check defaults
  229. var options = {};
  230. var network = createNetwork(options);
  231. checkChooserValues(firstEdge(network), true, true);
  232. // There's no point in checking invalid values here; these are detected by the options parser
  233. // and subsequently handled as missing input, thus assigned defaults
  234. // check various combinations of valid input
  235. options = {edges: {chosen: false}};
  236. network = createNetwork(options);
  237. checkChooserValues(firstEdge(network), false, false);
  238. options = {edges: {chosen: { edge:true, label:false}}};
  239. network = createNetwork(options);
  240. checkChooserValues(firstEdge(network), true, false);
  241. options = {edges: {chosen: {
  242. edge:true,
  243. label: function(value, id, selected, hovering) {}
  244. }}};
  245. network = createNetwork(options);
  246. checkChooserValues(firstEdge(network), true, 'function');
  247. options = {edges: {chosen: {
  248. edge: function(value, id, selected, hovering) {},
  249. label:false,
  250. }}};
  251. network = createNetwork(options);
  252. checkChooserValues(firstEdge(network), 'function', false);
  253. });
  254. /**
  255. * Support routine for next unit test
  256. */
  257. function createDataforColorChange() {
  258. var nodes = new vis.DataSet([
  259. {id: 1, label: 'Node 1' }, // group:'Group1'},
  260. {id: 2, label: 'Node 2', group:'Group2'},
  261. {id: 3, label: 'Node 3'},
  262. ]);
  263. // create an array with edges
  264. var edges = new vis.DataSet([
  265. {id: 1, from: 1, to: 2},
  266. {id: 2, from: 1, to: 3, color: { inherit: 'to'}},
  267. {id: 3, from: 3, to: 3, color: { color: '#00FF00'}},
  268. {id: 4, from: 2, to: 3, color: { inherit: 'from'}},
  269. ]);
  270. var data = {
  271. nodes: nodes,
  272. edges: edges
  273. };
  274. return data;
  275. }
  276. /**
  277. * Unit test for fix of #3350
  278. *
  279. * The issue is that changing color options is not registered in the nodes.
  280. * We test the updates the color options in the general edges options here.
  281. */
  282. it('sets inherit color option for edges on call to Network.setOptions()', function () {
  283. var container = document.getElementById('mynetwork');
  284. var data = createDataforColorChange();
  285. var options = {
  286. "edges" : { "color" : { "inherit" : "to" } },
  287. };
  288. // Test passing options on init.
  289. var network = new vis.Network(container, data, options);
  290. var edges = network.body.edges;
  291. assert.equal(edges[1].options.color.inherit, 'to'); // new default
  292. assert.equal(edges[2].options.color.inherit, 'to'); // set in edge
  293. assert.equal(edges[3].options.color.inherit, false); // has explicit color
  294. assert.equal(edges[4].options.color.inherit, 'from'); // set in edge
  295. // Sanity check: colors should still be defaults
  296. assert.equal(edges[1].options.color.color, network.edgesHandler.options.color.color);
  297. // Override the color value - inherit returns to default
  298. network.setOptions({ edges:{color: {}}});
  299. assert.equal(edges[1].options.color.inherit, 'from'); // default
  300. assert.equal(edges[2].options.color.inherit, 'to'); // set in edge
  301. assert.equal(edges[3].options.color.inherit, false); // has explicit color
  302. assert.equal(edges[4].options.color.inherit, 'from'); // set in edge
  303. // Check no options
  304. network = new vis.Network(container, data, {});
  305. edges = network.body.edges;
  306. assert.equal(edges[1].options.color.inherit, 'from'); // default
  307. assert.equal(edges[2].options.color.inherit, 'to'); // set in edge
  308. assert.equal(edges[3].options.color.inherit, false); // has explicit color
  309. assert.equal(edges[4].options.color.inherit, 'from'); // set in edge
  310. // Set new value
  311. network.setOptions(options);
  312. assert.equal(edges[1].options.color.inherit, 'to');
  313. assert.equal(edges[2].options.color.inherit, 'to'); // set in edge
  314. assert.equal(edges[3].options.color.inherit, false); // has explicit color
  315. assert.equal(edges[4].options.color.inherit, 'from'); // set in edge
  316. /*
  317. // Useful for debugging
  318. console.log('===================================');
  319. console.log(edges[1].options.color);
  320. console.log(edges[1].options.color.__proto__);
  321. console.log(edges[1].options);
  322. console.log(edges[1].options.__proto__);
  323. console.log(edges[1].edgeOptions);
  324. */
  325. });
  326. it('sets inherit color option for specific edge', function () {
  327. var container = document.getElementById('mynetwork');
  328. var data = createDataforColorChange();
  329. // Check no options
  330. var network = new vis.Network(container, data, {});
  331. var edges = network.body.edges;
  332. assert.equal(edges[1].options.color.inherit, 'from'); // default
  333. assert.equal(edges[2].options.color.inherit, 'to'); // set in edge
  334. assert.equal(edges[3].options.color.inherit, false); // has explicit color
  335. assert.equal(edges[4].options.color.inherit, 'from'); // set in edge
  336. // Set new value
  337. data.edges.update({id: 1, color: { inherit: 'to'}});
  338. assert.equal(edges[1].options.color.inherit, 'to'); // Only this changed
  339. assert.equal(edges[2].options.color.inherit, 'to');
  340. assert.equal(edges[3].options.color.inherit, false); // has explicit color
  341. assert.equal(edges[4].options.color.inherit, 'from');
  342. });
  343. /**
  344. * Perhaps TODO: add unit test for passing string value for color option
  345. */
  346. it('sets color value for edges on call to Network.setOptions()', function () {
  347. var container = document.getElementById('mynetwork');
  348. var data = createDataforColorChange();
  349. var defaultColor = '#848484'; // From defaults
  350. var color = '#FF0000';
  351. var options = {
  352. "edges" : { "color" : { "color" : color } },
  353. };
  354. // Test passing options on init.
  355. var network = new vis.Network(container, data, options);
  356. var edges = network.body.edges;
  357. assert.equal(edges[1].options.color.color, color);
  358. assert.equal(edges[1].options.color.inherit, false); // Explicit color, so no inherit
  359. assert.equal(edges[2].options.color.color, color);
  360. assert.equal(edges[2].options.color.inherit, 'to'); // Local value overrides! (bug according to docs)
  361. assert.notEqual(edges[3].options.color.color, color); // Has own value
  362. assert.equal(edges[3].options.color.inherit, false); // Explicit color, so no inherit
  363. assert.equal(edges[4].options.color.color, color);
  364. // Override the color value - all should return to default
  365. network.setOptions({ edges:{color: {}}});
  366. assert.equal(edges[1].options.color.color, defaultColor);
  367. assert.equal(edges[1].options.color.inherit, 'from');
  368. assert.equal(edges[2].options.color.color, defaultColor);
  369. assert.notEqual(edges[3].options.color.color, color); // Has own value
  370. assert.equal(edges[4].options.color.color, defaultColor);
  371. // Check no options
  372. network = new vis.Network(container, data, {});
  373. edges = network.body.edges;
  374. // At this point, color has not changed yet
  375. assert.equal(edges[1].options.color.color, defaultColor);
  376. assert.equal(edges[1].options.color.highlight, defaultColor);
  377. assert.equal(edges[1].options.color.inherit, 'from');
  378. assert.notEqual(edges[3].options.color.color, color); // Has own value
  379. // Set new Value
  380. network.setOptions(options);
  381. assert.equal(edges[1].options.color.color, color);
  382. assert.equal(edges[1].options.color.highlight, defaultColor); // Should not be changed
  383. assert.equal(edges[1].options.color.inherit, false); // Explicit color, so no inherit
  384. assert.equal(edges[2].options.color.color, color);
  385. assert.notEqual(edges[3].options.color.color, color); // Has own value
  386. assert.equal(edges[4].options.color.color, color);
  387. });
  388. }); // Edge
  389. describe('Clustering', function () {
  390. /**
  391. * Check on fix for #1218
  392. */
  393. it('connects a new edge to a clustering node instead of the clustered node', function () {
  394. var [network, data, numNodes, numEdges] = createSampleNetwork();
  395. createCluster(network);
  396. numNodes += 1; // A clustering node is now hiding two nodes
  397. assertNumNodes(network, numNodes, numNodes - 2);
  398. numEdges += 2; // Two clustering edges now hide two edges
  399. assertNumEdges(network, numEdges, numEdges - 2);
  400. //console.log("Creating node 21")
  401. data.nodes.update([{id: 21, label: '21'}]);
  402. numNodes += 1; // New unconnected node added
  403. assertNumNodes(network, numNodes, numNodes - 2);
  404. assertNumEdges(network, numEdges, numEdges - 2); // edges unchanged
  405. //console.log("Creating edge 21 pointing to 1");
  406. // '1' is part of the cluster so should
  407. // connect to cluster instead
  408. data.edges.update([{from: 21, to: 1}]);
  409. assertNumNodes(network, numNodes, numNodes - 2); // nodes unchanged
  410. numEdges += 2; // A new clustering edge is hiding a new edge
  411. assertNumEdges(network, numEdges, numEdges - 3);
  412. });
  413. /**
  414. * Check on fix for #1315
  415. */
  416. it('can uncluster a clustered node when a node is removed that has an edge to that cluster', function () {
  417. // NOTE: this block is same as previous test
  418. var [network, data, numNodes, numEdges] = createSampleNetwork();
  419. createCluster(network);
  420. numNodes += 1; // A clustering node is now hiding two nodes
  421. assertNumNodes(network, numNodes, numNodes - 2);
  422. numEdges += 2; // Two clustering edges now hide two edges
  423. assertNumEdges(network, numEdges, numEdges - 2);
  424. // End block same as previous test
  425. //console.log("removing 12");
  426. data.nodes.remove(12);
  427. // NOTE:
  428. // At this particular point, there are still the two edges for node 12 in the edges DataSet.
  429. // If you want to do the delete correctly, these should also be deleted explictly from
  430. // the edges DataSet. In the Network instance, however, this.body.nodes and this.body.edges
  431. // should be correct, with the edges of 12 all cleared out.
  432. // 12 was connected to 11, which is clustered
  433. numNodes -= 1; // 12 removed, one less node
  434. assertNumNodes(network, numNodes, numNodes - 2);
  435. numEdges -= 3; // clustering edge c1-12 and 2 edges of 12 gone
  436. assertNumEdges(network, numEdges, numEdges - 1);
  437. //console.log("Unclustering c1");
  438. network.openCluster("c1");
  439. numNodes -= 1; // cluster node removed, one less node
  440. assertNumNodes(network, numNodes, numNodes); // all are visible again
  441. numEdges -= 1; // clustering edge gone, regular edge visible
  442. assertNumEdges(network, numEdges, numEdges); // all are visible again
  443. });
  444. /**
  445. * Check on fix for #1291
  446. */
  447. it('can remove a node inside a cluster and then open that cluster', function () {
  448. var [network, data, numNodes, numEdges] = createSampleNetwork();
  449. var clusterOptionsByData = {
  450. joinCondition: function(node) {
  451. if (node.id == 1 || node.id == 2 || node.id == 3) return true;
  452. return false;
  453. },
  454. clusterNodeProperties: {id:"c1", label:'c1'}
  455. }
  456. network.cluster(clusterOptionsByData);
  457. numNodes += 1; // new cluster node
  458. assertNumNodes(network, numNodes, numNodes - 3); // 3 clustered nodes
  459. numEdges += 1; // 1 cluster edge expected
  460. assertNumEdges(network, numEdges, numEdges - 3); // 3 edges hidden
  461. //console.log("removing node 2, which is inside the cluster");
  462. data.nodes.remove(2);
  463. numNodes -= 1; // clustered node removed
  464. assertNumNodes(network, numNodes, numNodes - 2); // view doesn't change
  465. numEdges -= 2; // edges removed hidden in cluster
  466. assertNumEdges(network, numEdges, numEdges - 1); // view doesn't change
  467. //console.log("Unclustering c1");
  468. network.openCluster("c1")
  469. numNodes -= 1; // cluster node gone
  470. assertNumNodes(network, numNodes, numNodes); // all visible
  471. numEdges -= 1; // cluster edge gone
  472. assertNumEdges(network, numEdges, numEdges); // all visible
  473. //log(network);
  474. });
  475. /**
  476. * Helper function for setting up a graph for testing clusterByEdgeCount()
  477. */
  478. function createOutlierGraph() {
  479. // create an array with nodes
  480. var nodes = new vis.DataSet([
  481. {id: 1, label: '1', group:'Group1'},
  482. {id: 2, label: '2', group:'Group2'},
  483. {id: 3, label: '3', group:'Group3'},
  484. {id: 4, label: '4', group:'Group4'},
  485. {id: 5, label: '5', group:'Group4'}
  486. ]);
  487. // create an array with edges
  488. var edges = new vis.DataSet([
  489. {from: 1, to: 3},
  490. {from: 1, to: 2},
  491. {from: 2, to: 4},
  492. {from: 2, to: 5}
  493. ]);
  494. // create a network
  495. var container = document.getElementById('mynetwork');
  496. var data = {
  497. nodes: nodes,
  498. edges: edges
  499. };
  500. var options = {
  501. "groups" : {
  502. "Group1" : { level:1 },
  503. "Group2" : { level:2 },
  504. "Group3" : { level:3 },
  505. "Group4" : { level:4 }
  506. }
  507. };
  508. var network = new vis.Network (container, data, options);
  509. return network;
  510. }
  511. /**
  512. * Check on fix for #3367
  513. */
  514. it('correctly handles edge cases of clusterByEdgeCount()', function () {
  515. /**
  516. * Collect clustered id's
  517. *
  518. * All node id's in clustering nodes are collected into an array;
  519. * The results for all clusters are returned as an array.
  520. *
  521. * Ordering of output depends on the order in which they are defined
  522. * within nodes.clustering; strictly, speaking, the array and its items
  523. * are collections, so order should not matter.
  524. */
  525. var collectClusters = function(network) {
  526. var clusters = [];
  527. for(var n in network.body.nodes) {
  528. var node = network.body.nodes[n];
  529. if (node.containedNodes === undefined) continue; // clusters only
  530. // Collect id's of nodes in the cluster
  531. var nodes = [];
  532. for(var m in node.containedNodes) {
  533. nodes.push(m);
  534. }
  535. clusters.push(nodes);
  536. }
  537. return clusters;
  538. }
  539. /**
  540. * Compare cluster data
  541. *
  542. * params are arrays of arrays of id's, e.g:
  543. *
  544. * [[1,3],[2,4]]
  545. *
  546. * Item arrays are the id's of nodes in a given cluster
  547. *
  548. * This comparison depends on the ordering; better
  549. * would be to treat the items and values as collections.
  550. */
  551. var compareClusterInfo = function(recieved, expected) {
  552. if (recieved.length !== expected.length) return false;
  553. for (var n = 0; n < recieved.length; ++n) {
  554. var itema = recieved[n];
  555. var itemb = expected[n];
  556. if (itema.length !== itemb.length) return false;
  557. for (var m = 0; m < itema.length; ++m) {
  558. if (itema[m] != itemb[m]) return false; // != because values can be string or number
  559. }
  560. }
  561. return true;
  562. }
  563. var assertJoinCondition = function(joinCondition, expected) {
  564. var network = createOutlierGraph();
  565. network.clusterOutliers({joinCondition: joinCondition});
  566. var recieved = collectClusters(network);
  567. //console.log(recieved);
  568. assert(compareClusterInfo(recieved, expected),
  569. 'recieved:' + JSON.stringify(recieved) + '; '
  570. + 'expected: ' + JSON.stringify(expected));
  571. };
  572. // Should cluster 3,4,5:
  573. var joinAll_ = function(n) { return true ; }
  574. // Should cluster none:
  575. var joinNone_ = function(n) { return false ; }
  576. // Should cluster 4 & 5:
  577. var joinLevel_ = function(n) { return n.level > 3 ; }
  578. assertJoinCondition(undefined , [[1,3],[2,4,5]]);
  579. assertJoinCondition(null , [[1,3],[2,4,5]]);
  580. assertJoinCondition(joinNone_ , []);
  581. assertJoinCondition(joinLevel_ , [[2,4,5]]);
  582. });
  583. }); // Clustering
  584. describe('on node.js', function () {
  585. it('should be running', function () {
  586. assert(this.container !== null, 'Container div not found');
  587. // The following should now just plain succeed
  588. var [network, data] = createSampleNetwork();
  589. assert.equal(Object.keys(network.body.nodes).length, 8);
  590. assert.equal(Object.keys(network.body.edges).length, 6);
  591. });
  592. describe('runs example ', function () {
  593. function loadExample(path, noPhysics) {
  594. include(path, this);
  595. var container = document.getElementById('mynetwork');
  596. // create a network
  597. var data = {
  598. nodes: new vis.DataSet(nodes),
  599. edges: new vis.DataSet(edges)
  600. };
  601. if (noPhysics) {
  602. // Avoid excessive processor time due to load.
  603. // We're just interested that the load itself is good
  604. options.physics = false;
  605. }
  606. var network = new vis.Network(container, data, options);
  607. return network;
  608. };
  609. it('basicUsage', function () {
  610. var network = loadExample('./test/network/basicUsage.js');
  611. //console.log(Object.keys(network.body.edges));
  612. // Count in following also contains the helper nodes for dynamic edges
  613. assert.equal(Object.keys(network.body.nodes).length, 10);
  614. assert.equal(Object.keys(network.body.edges).length, 5);
  615. });
  616. it('WorlCup2014', function () {
  617. // This is a huge example (which is why it's tested here!), so it takes a long time to load.
  618. this.timeout(10000);
  619. var network = loadExample('./examples/network/datasources/WorldCup2014.js', true);
  620. // Count in following also contains the helper nodes for dynamic edges
  621. assert.equal(Object.keys(network.body.nodes).length, 9964);
  622. assert.equal(Object.keys(network.body.edges).length, 9228);
  623. });
  624. // This actually failed to load, added for this reason
  625. it('disassemblerExample', function () {
  626. var network = loadExample('./examples/network/exampleApplications/disassemblerExample.js');
  627. // console.log(Object.keys(network.body.nodes));
  628. // console.log(Object.keys(network.body.edges));
  629. // Count in following also contains the helper nodes for dynamic edges
  630. assert.equal(Object.keys(network.body.nodes).length, 9);
  631. assert.equal(Object.keys(network.body.edges).length, 14 - 3); // NB 3 edges in data not displayed
  632. });
  633. }); // runs example
  634. }); // on node.js
  635. }); // Network