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.

1477 lines
42 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. var Emitter = require('emitter-component');
  2. var Hammer = require('../module/hammer');
  3. var keycharm = require('keycharm');
  4. var util = require('../util');
  5. var hammerUtil = require('../hammerUtil');
  6. var DataSet = require('../DataSet');
  7. var DataView = require('../DataView');
  8. var dotparser = require('./dotparser');
  9. var gephiParser = require('./gephiParser');
  10. var Groups = require('./Groups');
  11. var Images = require('./Images');
  12. var Node = require('./Node');
  13. var Edge = require('./Edge');
  14. var Popup = require('./Popup');
  15. var MixinLoader = require('./mixins/MixinLoader');
  16. var Activator = require('../shared/Activator');
  17. var locales = require('./locales');
  18. // Load custom shapes into CanvasRenderingContext2D
  19. require('./shapes');
  20. import { PhysicsEngine } from './modules/PhysicsEngine'
  21. import { ClusterEngine } from './modules/Clustering'
  22. import { CanvasRenderer } from './modules/CanvasRenderer'
  23. import { Canvas } from './modules/Canvas'
  24. import { View } from './modules/View'
  25. import { InteractionHandler } from './modules/InteractionHandler'
  26. import { SelectionHandler } from "./modules/SelectionHandler"
  27. /**
  28. * @constructor Network
  29. * Create a network visualization, displaying nodes and edges.
  30. *
  31. * @param {Element} container The DOM element in which the Network will
  32. * be created. Normally a div element.
  33. * @param {Object} data An object containing parameters
  34. * {Array} nodes
  35. * {Array} edges
  36. * @param {Object} options Options
  37. */
  38. function Network (container, data, options) {
  39. if (!(this instanceof Network)) {
  40. throw new SyntaxError('Constructor must be called with the new operator');
  41. }
  42. this._initializeMixinLoaders();
  43. // render and calculation settings
  44. this.initializing = true;
  45. this.triggerFunctions = {add:null,edit:null,editEdge:null,connect:null,del:null};
  46. var customScalingFunction = function (min,max,total,value) {
  47. if (max == min) {
  48. return 0.5;
  49. }
  50. else {
  51. var scale = 1 / (max - min);
  52. return Math.max(0,(value - min)*scale);
  53. }
  54. };
  55. // set constant values
  56. this.defaultOptions = {
  57. nodes: {
  58. customScalingFunction: customScalingFunction,
  59. mass: 1,
  60. radiusMin: 10,
  61. radiusMax: 30,
  62. radius: 10,
  63. shape: 'ellipse',
  64. image: undefined,
  65. widthMin: 16, // px
  66. widthMax: 64, // px
  67. fontColor: 'black',
  68. fontSize: 14, // px
  69. fontFace: 'verdana',
  70. fontFill: undefined,
  71. fontStrokeWidth: 0, // px
  72. fontStrokeColor: '#ffffff',
  73. fontDrawThreshold: 3,
  74. scaleFontWithValue: false,
  75. fontSizeMin: 14,
  76. fontSizeMax: 30,
  77. fontSizeMaxVisible: 30,
  78. value: 1,
  79. level: -1,
  80. color: {
  81. border: '#2B7CE9',
  82. background: '#97C2FC',
  83. highlight: {
  84. border: '#2B7CE9',
  85. background: '#D2E5FF'
  86. },
  87. hover: {
  88. border: '#2B7CE9',
  89. background: '#D2E5FF'
  90. }
  91. },
  92. group: undefined,
  93. borderWidth: 1,
  94. borderWidthSelected: undefined
  95. },
  96. edges: {
  97. customScalingFunction: customScalingFunction,
  98. widthMin: 1, //
  99. widthMax: 15,//
  100. width: 1,
  101. widthSelectionMultiplier: 2,
  102. hoverWidth: 1.5,
  103. value:1,
  104. style: 'line',
  105. color: {
  106. color:'#848484',
  107. highlight:'#848484',
  108. hover: '#848484'
  109. },
  110. opacity:1.0,
  111. fontColor: '#343434',
  112. fontSize: 14, // px
  113. fontFace: 'arial',
  114. fontFill: 'white',
  115. fontStrokeWidth: 0, // px
  116. fontStrokeColor: 'white',
  117. labelAlignment:'horizontal',
  118. arrowScaleFactor: 1,
  119. dash: {
  120. length: 10,
  121. gap: 5,
  122. altLength: undefined
  123. },
  124. inheritColor: "from", // to, from, false, true (== from)
  125. useGradients: false // release in 4.0
  126. },
  127. dataManipulation: {
  128. enabled: false,
  129. initiallyVisible: false
  130. },
  131. hierarchicalLayout: {
  132. enabled:false,
  133. levelSeparation: 150,
  134. nodeSpacing: 100,
  135. direction: "UD", // UD, DU, LR, RL
  136. layout: "hubsize" // hubsize, directed
  137. },
  138. interaction: {
  139. dragNodes:true,
  140. dragView: true,
  141. zoomView: true,
  142. hoverEnabled: false,
  143. showNavigationIcons: false,
  144. tooltip: {
  145. delay: 300,
  146. fontColor: 'black',
  147. fontSize: 14, // px
  148. fontFace: 'verdana',
  149. color: {
  150. border: '#666',
  151. background: '#FFFFC6'
  152. }
  153. },
  154. keyboard: {
  155. enabled: false,
  156. speed: {x: 10, y: 10, zoom: 0.02},
  157. bindToWindow: true
  158. }
  159. },
  160. selection: {
  161. enabled: true,
  162. selectConnectedEdges: true
  163. },
  164. smoothCurves: {
  165. enabled: true,
  166. dynamic: true,
  167. type: "continuous",
  168. roundness: 0.5
  169. },
  170. locale: 'en',
  171. locales: locales,
  172. useDefaultGroups: true
  173. };
  174. this.constants = util.extend({}, this.defaultOptions);
  175. // containers for nodes and edges
  176. this.body = {
  177. nodes: {},
  178. nodeIndices: [],
  179. supportNodes: {},
  180. supportNodeIndices: [],
  181. edges: {},
  182. data: {
  183. nodes: null, // A DataSet or DataView
  184. edges: null // A DataSet or DataView
  185. },
  186. functions:{
  187. createNode: this._createNode.bind(this),
  188. createEdge: this._createEdge.bind(this)
  189. },
  190. emitter: {
  191. on: this.on.bind(this),
  192. off: this.off.bind(this),
  193. emit: this.emit.bind(this),
  194. once: this.once.bind(this)
  195. },
  196. eventListeners: {
  197. onTap: function() {},
  198. onTouch: function() {},
  199. onDoubleTap: function() {},
  200. onHold: function() {},
  201. onDragStart: function() {},
  202. onDrag: function() {},
  203. onDragEnd: function() {},
  204. onMouseWheel: function() {},
  205. onPinch: function() {},
  206. onMouseMove: function() {},
  207. onRelease: function() {}
  208. },
  209. container: container,
  210. view: {
  211. scale:1,
  212. translation:{x:0,y:0}
  213. }
  214. };
  215. // modules
  216. this.canvas = new Canvas(this.body);
  217. this.selectionHandler = new SelectionHandler(this.body, this.canvas);
  218. this.interactionHandler = new InteractionHandler(this.body, this.canvas, this.selectionHandler);
  219. this.view = new View(this.body, this.canvas);
  220. this.renderer = new CanvasRenderer(this.body, this.canvas);
  221. this.clustering = new ClusterEngine(this.body);
  222. this.physics = new PhysicsEngine(this.body);
  223. // create the DOM elements
  224. this.canvas.create();
  225. this.hoverObj = {nodes:{},edges:{}};
  226. this.controlNodesActive = false;
  227. this.navigationHammers = [];
  228. this.manipulationHammers = [];
  229. // Node variables
  230. var me = this;
  231. this.groups = new Groups(); // object with groups
  232. this.images = new Images(); // object with images
  233. this.images.setOnloadCallback(function (status) {
  234. me._requestRedraw();
  235. });
  236. // keyboard navigation variables
  237. this.xIncrement = 0;
  238. this.yIncrement = 0;
  239. this.zoomIncrement = 0;
  240. // loading all the mixins:
  241. // load the force calculation functions, grouped under the physics system.
  242. //this._loadPhysicsSystem();
  243. // create a frame and canvas
  244. // load the cluster system. (mandatory, even when not using the cluster system, there are function calls to it)
  245. // load the selection system. (mandatory, required by Network)
  246. this._loadSelectionSystem();
  247. // load the selection system. (mandatory, required by Network)
  248. //this._loadHierarchySystem();
  249. // apply options
  250. this.setOptions(options);
  251. // position and scale variables and objects
  252. this.pointerPosition = {"x": 0,"y": 0}; // coordinates of the bottom right of the canvas. they will be set during _redraw
  253. this.scale = 1; // defining the global scale variable in the constructor
  254. // create event listeners used to subscribe on the DataSets of the nodes and edges
  255. this.nodesListeners = {
  256. 'add': function (event, params) {
  257. me._addNodes(params.items);
  258. me.start();
  259. },
  260. 'update': function (event, params) {
  261. me._updateNodes(params.items, params.data);
  262. me.start();
  263. },
  264. 'remove': function (event, params) {
  265. me._removeNodes(params.items);
  266. me.start();
  267. }
  268. };
  269. this.edgesListeners = {
  270. 'add': function (event, params) {
  271. me._addEdges(params.items);
  272. me.start();
  273. },
  274. 'update': function (event, params) {
  275. me._updateEdges(params.items);
  276. me.start();
  277. },
  278. 'remove': function (event, params) {
  279. me._removeEdges(params.items);
  280. me.start();
  281. }
  282. };
  283. // properties for the animation
  284. this.moving = true;
  285. this.renderTimer = undefined; // Scheduling function. Is definded in this.start();
  286. // load data (the disable start variable will be the same as the enabled clustering)
  287. this.setData(data, this.constants.hierarchicalLayout.enabled);
  288. // hierarchical layout
  289. if (this.constants.hierarchicalLayout.enabled == true) {
  290. this._setupHierarchicalLayout();
  291. }
  292. else {
  293. // zoom so all data will fit on the screen, if clustering is enabled, we do not want start to be called here.
  294. if (this.constants.stabilize == false) {
  295. this.zoomExtent({duration:0}, true, this.constants.clustering.enabled);
  296. }
  297. }
  298. if (this.constants.stabilize == false) {
  299. this.initializing = false;
  300. }
  301. var me = this;
  302. // this event will trigger a rebuilding of the cache of colors, nodes etc.
  303. this.on("_dataChanged", function () {
  304. me._updateNodeIndexList();
  305. me.physics._updateCalculationNodes();
  306. me._markAllEdgesAsDirty();
  307. if (me.initializing !== true) {
  308. me.moving = true;
  309. me.start();
  310. }
  311. })
  312. this.on("_newEdgesCreated", this._createBezierNodes.bind(this));
  313. //this.on("stabilizationIterationsDone", function () {me.initializing = false; me.start();}.bind(this));
  314. }
  315. // Extend Network with an Emitter mixin
  316. Emitter(Network.prototype);
  317. Network.prototype._createNode = function(properties) {
  318. return new Node(properties, this.images, this.groups, this.constants)
  319. }
  320. Network.prototype._createEdge = function(properties) {
  321. return new Edge(properties, this.body, this.constants)
  322. }
  323. /**
  324. * Update the this.body.nodeIndices with the most recent node index list
  325. * @private
  326. */
  327. Network.prototype._updateNodeIndexList = function() {
  328. this.body.supportNodeIndices = Object.keys(this.body.supportNodes)
  329. this.body.nodeIndices = Object.keys(this.body.nodes);
  330. };
  331. /**
  332. * Set nodes and edges, and optionally options as well.
  333. *
  334. * @param {Object} data Object containing parameters:
  335. * {Array | DataSet | DataView} [nodes] Array with nodes
  336. * {Array | DataSet | DataView} [edges] Array with edges
  337. * {String} [dot] String containing data in DOT format
  338. * {String} [gephi] String containing data in gephi JSON format
  339. * {Options} [options] Object with options
  340. * @param {Boolean} [disableStart] | optional: disable the calling of the start function.
  341. */
  342. Network.prototype.setData = function(data, disableStart) {
  343. if (disableStart === undefined) {
  344. disableStart = false;
  345. }
  346. // unselect all to ensure no selections from old data are carried over.
  347. this.selectionHandler.unselectAll();
  348. // we set initializing to true to ensure that the hierarchical layout is not performed until both nodes and edges are added.
  349. this.initializing = true;
  350. if (data && data.dot && (data.nodes || data.edges)) {
  351. throw new SyntaxError('Data must contain either parameter "dot" or ' +
  352. ' parameter pair "nodes" and "edges", but not both.');
  353. }
  354. // clean up in case there is anyone in an active mode of the manipulation. This is the same option as bound to the escape button.
  355. if (this.constants.dataManipulation.enabled == true) {
  356. this._createManipulatorBar();
  357. }
  358. // set options
  359. this.setOptions(data && data.options);
  360. // set all data
  361. if (data && data.dot) {
  362. // parse DOT file
  363. if(data && data.dot) {
  364. var dotData = dotparser.DOTToGraph(data.dot);
  365. this.setData(dotData);
  366. return;
  367. }
  368. }
  369. else if (data && data.gephi) {
  370. // parse DOT file
  371. if(data && data.gephi) {
  372. var gephiData = gephiParser.parseGephi(data.gephi);
  373. this.setData(gephiData);
  374. return;
  375. }
  376. }
  377. else {
  378. this._setNodes(data && data.nodes);
  379. this._setEdges(data && data.edges);
  380. }
  381. if (disableStart == false) {
  382. if (this.constants.hierarchicalLayout.enabled == true) {
  383. this._resetLevels();
  384. this._setupHierarchicalLayout();
  385. }
  386. else {
  387. // find a stable position or start animating to a stable position
  388. this.body.emitter.emit("stabilize");
  389. }
  390. }
  391. else {
  392. this.initializing = false;
  393. }
  394. };
  395. /**
  396. * Set options
  397. * @param {Object} options
  398. */
  399. Network.prototype.setOptions = function (options) {
  400. if (options) {
  401. var prop;
  402. var fields = ['nodes','edges','smoothCurves','hierarchicalLayout','navigation',
  403. 'keyboard','dataManipulation','onAdd','onEdit','onEditEdge','onConnect','onDelete','clickToUse'
  404. ];
  405. // extend all but the values in fields
  406. util.selectiveNotDeepExtend(fields,this.constants, options);
  407. util.selectiveNotDeepExtend(['color'],this.constants.nodes, options.nodes);
  408. util.selectiveNotDeepExtend(['color','length'],this.constants.edges, options.edges);
  409. this.groups.useDefaultGroups = this.constants.useDefaultGroups;
  410. this.physics.setOptions(options.physics);
  411. this.canvas.setOptions(options.canvas);
  412. this.renderer.setOptions(options.rendering);
  413. this.interactionHandler.setOptions(options.interaction);
  414. this.selectionHandler.setOptions(options.selection);
  415. if (options.onAdd) {this.triggerFunctions.add = options.onAdd;}
  416. if (options.onEdit) {this.triggerFunctions.edit = options.onEdit;}
  417. if (options.onEditEdge) {this.triggerFunctions.editEdge = options.onEditEdge;}
  418. if (options.onConnect) {this.triggerFunctions.connect = options.onConnect;}
  419. if (options.onDelete) {this.triggerFunctions.del = options.onDelete;}
  420. util.mergeOptions(this.constants, options,'smoothCurves');
  421. util.mergeOptions(this.constants, options,'hierarchicalLayout');
  422. util.mergeOptions(this.constants, options,'clustering');
  423. util.mergeOptions(this.constants, options,'navigation');
  424. util.mergeOptions(this.constants, options,'keyboard');
  425. util.mergeOptions(this.constants, options,'dataManipulation');
  426. if (options.dataManipulation) {
  427. this.editMode = this.constants.dataManipulation.initiallyVisible;
  428. }
  429. // TODO: work out these options and document them
  430. if (options.edges) {
  431. if (options.edges.color !== undefined) {
  432. if (util.isString(options.edges.color)) {
  433. this.constants.edges.color = {};
  434. this.constants.edges.color.color = options.edges.color;
  435. this.constants.edges.color.highlight = options.edges.color;
  436. this.constants.edges.color.hover = options.edges.color;
  437. }
  438. else {
  439. if (options.edges.color.color !== undefined) {this.constants.edges.color.color = options.edges.color.color;}
  440. if (options.edges.color.highlight !== undefined) {this.constants.edges.color.highlight = options.edges.color.highlight;}
  441. if (options.edges.color.hover !== undefined) {this.constants.edges.color.hover = options.edges.color.hover;}
  442. }
  443. this.constants.edges.inheritColor = false;
  444. }
  445. if (!options.edges.fontColor) {
  446. if (options.edges.color !== undefined) {
  447. if (util.isString(options.edges.color)) {this.constants.edges.fontColor = options.edges.color;}
  448. else if (options.edges.color.color !== undefined) {this.constants.edges.fontColor = options.edges.color.color;}
  449. }
  450. }
  451. }
  452. if (options.nodes) {
  453. if (options.nodes.color) {
  454. var newColorObj = util.parseColor(options.nodes.color);
  455. this.constants.nodes.color.background = newColorObj.background;
  456. this.constants.nodes.color.border = newColorObj.border;
  457. this.constants.nodes.color.highlight.background = newColorObj.highlight.background;
  458. this.constants.nodes.color.highlight.border = newColorObj.highlight.border;
  459. this.constants.nodes.color.hover.background = newColorObj.hover.background;
  460. this.constants.nodes.color.hover.border = newColorObj.hover.border;
  461. }
  462. }
  463. if (options.groups) {
  464. for (var groupname in options.groups) {
  465. if (options.groups.hasOwnProperty(groupname)) {
  466. var group = options.groups[groupname];
  467. this.groups.add(groupname, group);
  468. }
  469. }
  470. }
  471. if (options.tooltip) {
  472. for (prop in options.tooltip) {
  473. if (options.tooltip.hasOwnProperty(prop)) {
  474. this.constants.tooltip[prop] = options.tooltip[prop];
  475. }
  476. }
  477. if (options.tooltip.color) {
  478. this.constants.tooltip.color = util.parseColor(options.tooltip.color);
  479. }
  480. }
  481. if ('clickToUse' in options) {
  482. if (options.clickToUse === true) {
  483. if (this.activator === undefined) {
  484. this.activator = new Activator(this.frame);
  485. this.activator.on('change', this._createKeyBinds.bind(this));
  486. }
  487. }
  488. else {
  489. if (this.activator !== undefined) {
  490. this.activator.destroy();
  491. delete this.activator;
  492. }
  493. this.body.emitter.emit("activate");
  494. }
  495. }
  496. else {
  497. this.body.emitter.emit("activate");
  498. }
  499. this._markAllEdgesAsDirty();
  500. this.canvas.setSize();
  501. if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
  502. this._resetLevels();
  503. this._setupHierarchicalLayout();
  504. }
  505. if (this.initializing !== true) {
  506. this.moving = true;
  507. this.start();
  508. }
  509. }
  510. };
  511. /**
  512. * Binding the keys for keyboard navigation. These functions are defined in the NavigationMixin
  513. * @private
  514. */
  515. Network.prototype._createKeyBinds = function() {
  516. return;
  517. //var me = this;
  518. //if (this.keycharm !== undefined) {
  519. // this.keycharm.destroy();
  520. //}
  521. //
  522. //if (this.constants.keyboard.bindToWindow == true) {
  523. // this.keycharm = keycharm({container: window, preventDefault: false});
  524. //}
  525. //else {
  526. // this.keycharm = keycharm({container: this.frame, preventDefault: false});
  527. //}
  528. //
  529. //this.keycharm.reset();
  530. //
  531. //if (this.constants.keyboard.enabled && this.isActive()) {
  532. // this.keycharm.bind("up", this._moveUp.bind(me) , "keydown");
  533. // this.keycharm.bind("up", this._yStopMoving.bind(me), "keyup");
  534. // this.keycharm.bind("down", this._moveDown.bind(me) , "keydown");
  535. // this.keycharm.bind("down", this._yStopMoving.bind(me), "keyup");
  536. // this.keycharm.bind("left", this._moveLeft.bind(me) , "keydown");
  537. // this.keycharm.bind("left", this._xStopMoving.bind(me), "keyup");
  538. // this.keycharm.bind("right",this._moveRight.bind(me), "keydown");
  539. // this.keycharm.bind("right",this._xStopMoving.bind(me), "keyup");
  540. // this.keycharm.bind("=", this._zoomIn.bind(me), "keydown");
  541. // this.keycharm.bind("=", this._stopZoom.bind(me), "keyup");
  542. // this.keycharm.bind("num+", this._zoomIn.bind(me), "keydown");
  543. // this.keycharm.bind("num+", this._stopZoom.bind(me), "keyup");
  544. // this.keycharm.bind("num-", this._zoomOut.bind(me), "keydown");
  545. // this.keycharm.bind("num-", this._stopZoom.bind(me), "keyup");
  546. // this.keycharm.bind("-", this._zoomOut.bind(me), "keydown");
  547. // this.keycharm.bind("-", this._stopZoom.bind(me), "keyup");
  548. // this.keycharm.bind("[", this._zoomIn.bind(me), "keydown");
  549. // this.keycharm.bind("[", this._stopZoom.bind(me), "keyup");
  550. // this.keycharm.bind("]", this._zoomOut.bind(me), "keydown");
  551. // this.keycharm.bind("]", this._stopZoom.bind(me), "keyup");
  552. // this.keycharm.bind("pageup",this._zoomIn.bind(me), "keydown");
  553. // this.keycharm.bind("pageup",this._stopZoom.bind(me), "keyup");
  554. // this.keycharm.bind("pagedown",this._zoomOut.bind(me),"keydown");
  555. // this.keycharm.bind("pagedown",this._stopZoom.bind(me), "keyup");
  556. //}
  557. //
  558. //if (this.constants.dataManipulation.enabled == true) {
  559. // this.keycharm.bind("esc",this._createManipulatorBar.bind(me));
  560. // this.keycharm.bind("delete",this._deleteSelected.bind(me));
  561. //}
  562. };
  563. /**
  564. * Cleans up all bindings of the network, removing it fully from the memory IF the variable is set to null after calling this function.
  565. * var network = new vis.Network(..);
  566. * network.destroy();
  567. * network = null;
  568. */
  569. Network.prototype.destroy = function() {
  570. this.start = function () {};
  571. this.redraw = function () {};
  572. this.renderTimer = false;
  573. // cleanup physicsConfiguration if it exists
  574. this._cleanupPhysicsConfiguration();
  575. // remove keybindings
  576. this.keycharm.reset();
  577. // clear hammer bindings
  578. this.hammer.destroy();
  579. // clear events
  580. this.off();
  581. this._recursiveDOMDelete(this.containerElement);
  582. };
  583. Network.prototype._recursiveDOMDelete = function(DOMobject) {
  584. while (DOMobject.hasChildNodes() == true) {
  585. this._recursiveDOMDelete(DOMobject.firstChild);
  586. DOMobject.removeChild(DOMobject.firstChild);
  587. }
  588. };
  589. /**
  590. * Check if there is an element on the given position in the network
  591. * (a node or edge). If so, and if this element has a title,
  592. * show a popup window with its title.
  593. *
  594. * @param {{x:Number, y:Number}} pointer
  595. * @private
  596. */
  597. Network.prototype._checkShowPopup = function (pointer) {
  598. var obj = {
  599. left: this._XconvertDOMtoCanvas(pointer.x),
  600. top: this._YconvertDOMtoCanvas(pointer.y),
  601. right: this._XconvertDOMtoCanvas(pointer.x),
  602. bottom: this._YconvertDOMtoCanvas(pointer.y)
  603. };
  604. var id;
  605. var previousPopupObjId = this.popupObj === undefined ? "" : this.popupObj.id;
  606. var nodeUnderCursor = false;
  607. var popupType = "node";
  608. if (this.popupObj == undefined) {
  609. // search the nodes for overlap, select the top one in case of multiple nodes
  610. var nodes = this.body.nodes;
  611. var overlappingNodes = [];
  612. for (id in nodes) {
  613. if (nodes.hasOwnProperty(id)) {
  614. var node = nodes[id];
  615. if (node.isOverlappingWith(obj)) {
  616. if (node.getTitle() !== undefined) {
  617. overlappingNodes.push(id);
  618. }
  619. }
  620. }
  621. }
  622. if (overlappingNodes.length > 0) {
  623. // if there are overlapping nodes, select the last one, this is the
  624. // one which is drawn on top of the others
  625. this.popupObj = this.body.nodes[overlappingNodes[overlappingNodes.length - 1]];
  626. // if you hover over a node, the title of the edge is not supposed to be shown.
  627. nodeUnderCursor = true;
  628. }
  629. }
  630. if (this.popupObj === undefined && nodeUnderCursor == false) {
  631. // search the edges for overlap
  632. var edges = this.body.edges;
  633. var overlappingEdges = [];
  634. for (id in edges) {
  635. if (edges.hasOwnProperty(id)) {
  636. var edge = edges[id];
  637. if (edge.connected === true && (edge.getTitle() !== undefined) &&
  638. edge.isOverlappingWith(obj)) {
  639. overlappingEdges.push(id);
  640. }
  641. }
  642. }
  643. if (overlappingEdges.length > 0) {
  644. this.popupObj = this.body.edges[overlappingEdges[overlappingEdges.length - 1]];
  645. popupType = "edge";
  646. }
  647. }
  648. if (this.popupObj) {
  649. // show popup message window
  650. if (this.popupObj.id != previousPopupObjId) {
  651. if (this.popup === undefined) {
  652. this.popup = new Popup(this.frame, this.constants.tooltip);
  653. }
  654. this.popup.popupTargetType = popupType;
  655. this.popup.popupTargetId = this.popupObj.id;
  656. // adjust a small offset such that the mouse cursor is located in the
  657. // bottom left location of the popup, and you can easily move over the
  658. // popup area
  659. this.popup.setPosition(pointer.x + 3, pointer.y - 5);
  660. this.popup.setText(this.popupObj.getTitle());
  661. this.popup.show();
  662. }
  663. }
  664. else {
  665. if (this.popup) {
  666. this.popup.hide();
  667. }
  668. }
  669. };
  670. /**
  671. * Check if the popup must be hidden, which is the case when the mouse is no
  672. * longer hovering on the object
  673. * @param {{x:Number, y:Number}} pointer
  674. * @private
  675. */
  676. Network.prototype._checkHidePopup = function (pointer) {
  677. var pointerObj = {
  678. left: this._XconvertDOMtoCanvas(pointer.x),
  679. top: this._YconvertDOMtoCanvas(pointer.y),
  680. right: this._XconvertDOMtoCanvas(pointer.x),
  681. bottom: this._YconvertDOMtoCanvas(pointer.y)
  682. };
  683. var stillOnObj = false;
  684. if (this.popup.popupTargetType == 'node') {
  685. stillOnObj = this.body.nodes[this.popup.popupTargetId].isOverlappingWith(pointerObj);
  686. if (stillOnObj === true) {
  687. var overNode = this.getNodeAt(pointer);
  688. stillOnObj = overNode.id == this.popup.popupTargetId;
  689. }
  690. }
  691. else {
  692. if (this.getNodeAt(pointer) === null) {
  693. stillOnObj = this.body.edges[this.popup.popupTargetId].isOverlappingWith(pointerObj);
  694. }
  695. }
  696. if (stillOnObj === false) {
  697. this.popupObj = undefined;
  698. this.popup.hide();
  699. }
  700. };
  701. /**
  702. * Set a data set with nodes for the network
  703. * @param {Array | DataSet | DataView} nodes The data containing the nodes.
  704. * @private
  705. */
  706. Network.prototype._setNodes = function(nodes) {
  707. var oldNodesData = this.body.data.nodes;
  708. if (nodes instanceof DataSet || nodes instanceof DataView) {
  709. this.body.data.nodes = nodes;
  710. }
  711. else if (Array.isArray(nodes)) {
  712. this.body.data.nodes = new DataSet();
  713. this.body.data.nodes.add(nodes);
  714. }
  715. else if (!nodes) {
  716. this.body.data.nodes = new DataSet();
  717. }
  718. else {
  719. throw new TypeError('Array or DataSet expected');
  720. }
  721. if (oldNodesData) {
  722. // unsubscribe from old dataset
  723. util.forEach(this.nodesListeners, function (callback, event) {
  724. oldNodesData.off(event, callback);
  725. });
  726. }
  727. // remove drawn nodes
  728. this.body.nodes = {};
  729. if (this.body.data.nodes) {
  730. // subscribe to new dataset
  731. var me = this;
  732. util.forEach(this.nodesListeners, function (callback, event) {
  733. me.body.data.nodes.on(event, callback);
  734. });
  735. // draw all new nodes
  736. var ids = this.body.data.nodes.getIds();
  737. this._addNodes(ids);
  738. }
  739. this._updateSelection();
  740. };
  741. /**
  742. * Add nodes
  743. * @param {Number[] | String[]} ids
  744. * @private
  745. */
  746. Network.prototype._addNodes = function(ids) {
  747. var id;
  748. for (var i = 0, len = ids.length; i < len; i++) {
  749. id = ids[i];
  750. var data = this.body.data.nodes.get(id);
  751. var node = new Node(data, this.images, this.groups, this.constants);
  752. this.body.nodes[id] = node; // note: this may replace an existing node
  753. if ((node.xFixed == false || node.yFixed == false) && (node.x === null || node.y === null)) {
  754. var radius = 10 * 0.1*ids.length + 10;
  755. var angle = 2 * Math.PI * Math.random();
  756. if (node.xFixed == false) {node.x = radius * Math.cos(angle);}
  757. if (node.yFixed == false) {node.y = radius * Math.sin(angle);}
  758. }
  759. this.moving = true;
  760. }
  761. this._updateNodeIndexList();
  762. if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
  763. this._resetLevels();
  764. this._setupHierarchicalLayout();
  765. }
  766. this.physics._updateCalculationNodes();
  767. this._reconnectEdges();
  768. this._updateValueRange(this.body.nodes);
  769. };
  770. /**
  771. * Update existing nodes, or create them when not yet existing
  772. * @param {Number[] | String[]} ids
  773. * @private
  774. */
  775. Network.prototype._updateNodes = function(ids,changedData) {
  776. var nodes = this.body.nodes;
  777. for (var i = 0, len = ids.length; i < len; i++) {
  778. var id = ids[i];
  779. var node = nodes[id];
  780. var data = changedData[i];
  781. if (node) {
  782. // update node
  783. node.setProperties(data, this.constants);
  784. }
  785. else {
  786. // create node
  787. node = new Node(properties, this.images, this.groups, this.constants);
  788. nodes[id] = node;
  789. }
  790. }
  791. this.moving = true;
  792. if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
  793. this._resetLevels();
  794. this._setupHierarchicalLayout();
  795. }
  796. this._updateNodeIndexList();
  797. this._updateValueRange(nodes);
  798. this._markAllEdgesAsDirty();
  799. };
  800. Network.prototype._markAllEdgesAsDirty = function() {
  801. for (var edgeId in this.body.edges) {
  802. this.body.edges[edgeId].colorDirty = true;
  803. }
  804. }
  805. /**
  806. * Remove existing nodes. If nodes do not exist, the method will just ignore it.
  807. * @param {Number[] | String[]} ids
  808. * @private
  809. */
  810. Network.prototype._removeNodes = function(ids) {
  811. var nodes = this.body.nodes;
  812. // remove from selection
  813. for (var i = 0, len = ids.length; i < len; i++) {
  814. if (this.selectionObj.nodes[ids[i]] !== undefined) {
  815. this.body.nodes[ids[i]].unselect();
  816. this._removeFromSelection(this.body.nodes[ids[i]]);
  817. }
  818. }
  819. for (var i = 0, len = ids.length; i < len; i++) {
  820. var id = ids[i];
  821. delete nodes[id];
  822. }
  823. this._updateNodeIndexList();
  824. if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
  825. this._resetLevels();
  826. this._setupHierarchicalLayout();
  827. }
  828. this.physics._updateCalculationNodes();
  829. this._reconnectEdges();
  830. this._updateSelection();
  831. this._updateValueRange(nodes);
  832. };
  833. /**
  834. * Load edges by reading the data table
  835. * @param {Array | DataSet | DataView} edges The data containing the edges.
  836. * @private
  837. * @private
  838. */
  839. Network.prototype._setEdges = function(edges) {
  840. var oldEdgesData = this.body.data.edges;
  841. if (edges instanceof DataSet || edges instanceof DataView) {
  842. this.body.data.edges = edges;
  843. }
  844. else if (Array.isArray(edges)) {
  845. this.body.data.edges = new DataSet();
  846. this.body.data.edges.add(edges);
  847. }
  848. else if (!edges) {
  849. this.body.data.edges = new DataSet();
  850. }
  851. else {
  852. throw new TypeError('Array or DataSet expected');
  853. }
  854. if (oldEdgesData) {
  855. // unsubscribe from old dataset
  856. util.forEach(this.edgesListeners, function (callback, event) {
  857. oldEdgesData.off(event, callback);
  858. });
  859. }
  860. // remove drawn edges
  861. this.body.edges = {};
  862. if (this.body.data.edges) {
  863. // subscribe to new dataset
  864. var me = this;
  865. util.forEach(this.edgesListeners, function (callback, event) {
  866. me.body.data.edges.on(event, callback);
  867. });
  868. // draw all new nodes
  869. var ids = this.body.data.edges.getIds();
  870. this._addEdges(ids);
  871. }
  872. this._reconnectEdges();
  873. };
  874. /**
  875. * Add edges
  876. * @param {Number[] | String[]} ids
  877. * @private
  878. */
  879. Network.prototype._addEdges = function (ids) {
  880. var edges = this.body.edges,
  881. edgesData = this.body.data.edges;
  882. for (var i = 0, len = ids.length; i < len; i++) {
  883. var id = ids[i];
  884. var oldEdge = edges[id];
  885. if (oldEdge) {
  886. oldEdge.disconnect();
  887. }
  888. var data = edgesData.get(id, {"showInternalIds" : true});
  889. edges[id] = new Edge(data, this.body, this.constants);
  890. }
  891. this.moving = true;
  892. this._updateValueRange(edges);
  893. this._createBezierNodes();
  894. this.physics._updateCalculationNodes();
  895. if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
  896. this._resetLevels();
  897. this._setupHierarchicalLayout();
  898. }
  899. };
  900. /**
  901. * Update existing edges, or create them when not yet existing
  902. * @param {Number[] | String[]} ids
  903. * @private
  904. */
  905. Network.prototype._updateEdges = function (ids) {
  906. var edges = this.body.edges;
  907. var edgesData = this.body.data.edges;
  908. for (var i = 0, len = ids.length; i < len; i++) {
  909. var id = ids[i];
  910. var data = edgesData.get(id);
  911. var edge = edges[id];
  912. if (edge) {
  913. // update edge
  914. edge.disconnect();
  915. edge.setProperties(data);
  916. edge.connect();
  917. }
  918. else {
  919. // create edge
  920. edge = new Edge(data, this.body, this.constants);
  921. this.body.edges[id] = edge;
  922. }
  923. }
  924. this._createBezierNodes();
  925. if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
  926. this._resetLevels();
  927. this._setupHierarchicalLayout();
  928. }
  929. this.moving = true;
  930. this._updateValueRange(edges);
  931. };
  932. /**
  933. * Remove existing edges. Non existing ids will be ignored
  934. * @param {Number[] | String[]} ids
  935. * @private
  936. */
  937. Network.prototype._removeEdges = function (ids) {
  938. var edges = this.body.edges;
  939. // remove from selection
  940. for (var i = 0, len = ids.length; i < len; i++) {
  941. if (this.selectionObj.edges[ids[i]] !== undefined) {
  942. edges[ids[i]].unselect();
  943. this._removeFromSelection(edges[ids[i]]);
  944. }
  945. }
  946. for (var i = 0, len = ids.length; i < len; i++) {
  947. var id = ids[i];
  948. var edge = edges[id];
  949. if (edge) {
  950. if (edge.via != null) {
  951. delete this.body.supportNodes[edge.via.id];
  952. }
  953. edge.disconnect();
  954. delete edges[id];
  955. }
  956. }
  957. this.moving = true;
  958. this._updateValueRange(edges);
  959. if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
  960. this._resetLevels();
  961. this._setupHierarchicalLayout();
  962. }
  963. this.physics._updateCalculationNodes();
  964. };
  965. /**
  966. * Reconnect all edges
  967. * @private
  968. */
  969. Network.prototype._reconnectEdges = function() {
  970. var id,
  971. nodes = this.body.nodes,
  972. edges = this.body.edges;
  973. for (id in nodes) {
  974. if (nodes.hasOwnProperty(id)) {
  975. nodes[id].edges = [];
  976. }
  977. }
  978. for (id in edges) {
  979. if (edges.hasOwnProperty(id)) {
  980. var edge = edges[id];
  981. edge.from = null;
  982. edge.to = null;
  983. edge.connect();
  984. }
  985. }
  986. };
  987. /**
  988. * Update the values of all object in the given array according to the current
  989. * value range of the objects in the array.
  990. * @param {Object} obj An object containing a set of Edges or Nodes
  991. * The objects must have a method getValue() and
  992. * setValueRange(min, max).
  993. * @private
  994. */
  995. Network.prototype._updateValueRange = function(obj) {
  996. var id;
  997. // determine the range of the objects
  998. var valueMin = undefined;
  999. var valueMax = undefined;
  1000. var valueTotal = 0;
  1001. for (id in obj) {
  1002. if (obj.hasOwnProperty(id)) {
  1003. var value = obj[id].getValue();
  1004. if (value !== undefined) {
  1005. valueMin = (valueMin === undefined) ? value : Math.min(value, valueMin);
  1006. valueMax = (valueMax === undefined) ? value : Math.max(value, valueMax);
  1007. valueTotal += value;
  1008. }
  1009. }
  1010. }
  1011. // adjust the range of all objects
  1012. if (valueMin !== undefined && valueMax !== undefined) {
  1013. for (id in obj) {
  1014. if (obj.hasOwnProperty(id)) {
  1015. obj[id].setValueRange(valueMin, valueMax, valueTotal);
  1016. }
  1017. }
  1018. }
  1019. };
  1020. /**
  1021. * Set the translation of the network
  1022. * @param {Number} offsetX Horizontal offset
  1023. * @param {Number} offsetY Vertical offset
  1024. * @private
  1025. */
  1026. Network.prototype._setTranslation = function(offsetX, offsetY) {
  1027. if (this.translation === undefined) {
  1028. this.translation = {
  1029. x: 0,
  1030. y: 0
  1031. };
  1032. }
  1033. if (offsetX !== undefined) {
  1034. this.translation.x = offsetX;
  1035. }
  1036. if (offsetY !== undefined) {
  1037. this.translation.y = offsetY;
  1038. }
  1039. this.emit('viewChanged');
  1040. };
  1041. /**
  1042. * Get the translation of the network
  1043. * @return {Object} translation An object with parameters x and y, both a number
  1044. * @private
  1045. */
  1046. Network.prototype._getTranslation = function() {
  1047. return {
  1048. x: this.translation.x,
  1049. y: this.translation.y
  1050. };
  1051. };
  1052. /**
  1053. * Scale the network
  1054. * @param {Number} scale Scaling factor 1.0 is unscaled
  1055. * @private
  1056. */
  1057. Network.prototype._setScale = function(scale) {
  1058. this.scale = scale;
  1059. };
  1060. /**
  1061. * Get the current scale of the network
  1062. * @return {Number} scale Scaling factor 1.0 is unscaled
  1063. * @private
  1064. */
  1065. Network.prototype._getScale = function() {
  1066. return this.scale;
  1067. };
  1068. /**
  1069. * Move the network according to the keyboard presses.
  1070. *
  1071. * @private
  1072. */
  1073. Network.prototype._handleNavigation = function() {
  1074. if (this.xIncrement != 0 || this.yIncrement != 0) {
  1075. var translation = this._getTranslation();
  1076. this._setTranslation(translation.x+this.xIncrement, translation.y+this.yIncrement);
  1077. }
  1078. if (this.zoomIncrement != 0) {
  1079. var center = {
  1080. x: this.frame.canvas.clientWidth / 2,
  1081. y: this.frame.canvas.clientHeight / 2
  1082. };
  1083. this.zoom(this.scale*(1 + this.zoomIncrement), center);
  1084. }
  1085. };
  1086. /**
  1087. * Freeze the _animationStep
  1088. */
  1089. Network.prototype.freezeSimulation = function(freeze) {
  1090. if (freeze == true) {
  1091. this.freezeSimulationEnabled = true;
  1092. this.moving = false;
  1093. }
  1094. else {
  1095. this.freezeSimulationEnabled = false;
  1096. this.moving = true;
  1097. this.start();
  1098. }
  1099. };
  1100. /**
  1101. * This function cleans the support nodes if they are not needed and adds them when they are.
  1102. *
  1103. * @param {boolean} [disableStart]
  1104. * @private
  1105. */
  1106. Network.prototype._configureSmoothCurves = function(disableStart = true) {
  1107. if (this.constants.smoothCurves.enabled == true && this.constants.smoothCurves.dynamic == true) {
  1108. this._createBezierNodes();
  1109. // cleanup unused support nodes
  1110. for (let i = 0; i < this.body.supportNodeIndices.length; i++) {
  1111. let nodeId = this.body.supportNodeIndices[i];
  1112. // delete support nodes for edges that have been deleted
  1113. if (this.body.edges[this.body.supportNodes[nodeId].parentEdgeId] === undefined) {
  1114. delete this.body.supportNodes[nodeId];
  1115. }
  1116. }
  1117. }
  1118. else {
  1119. // delete the support nodes
  1120. this.body.supportNodes = {};
  1121. for (var edgeId in this.body.edges) {
  1122. if (this.body.edges.hasOwnProperty(edgeId)) {
  1123. this.body.edges[edgeId].via = null;
  1124. }
  1125. }
  1126. }
  1127. this._updateNodeIndexList();
  1128. this.physics._updateCalculationNodes();
  1129. if (!disableStart) {
  1130. this.moving = true;
  1131. this.start();
  1132. }
  1133. };
  1134. /**
  1135. * Bezier curves require an anchor point to calculate the smooth flow. These points are nodes. These nodes are invisible but
  1136. * are used for the force calculation.
  1137. *
  1138. * @private
  1139. */
  1140. Network.prototype._createBezierNodes = function(specificEdges = this.body.edges) {
  1141. if (this.constants.smoothCurves.enabled == true && this.constants.smoothCurves.dynamic == true) {
  1142. for (var edgeId in specificEdges) {
  1143. if (specificEdges.hasOwnProperty(edgeId)) {
  1144. var edge = specificEdges[edgeId];
  1145. if (edge.via == null) {
  1146. var nodeId = "edgeId:".concat(edge.id);
  1147. var node = new Node(
  1148. {id:nodeId,
  1149. mass:1,
  1150. shape:'circle',
  1151. image:"",
  1152. internalMultiplier:1
  1153. },{},{},this.constants);
  1154. this.body.supportNodes[nodeId] = node;
  1155. edge.via = node;
  1156. edge.via.parentEdgeId = edge.id;
  1157. edge.positionBezierNode();
  1158. }
  1159. }
  1160. }
  1161. this._updateNodeIndexList();
  1162. }
  1163. };
  1164. /**
  1165. * load the functions that load the mixins into the prototype.
  1166. *
  1167. * @private
  1168. */
  1169. Network.prototype._initializeMixinLoaders = function () {
  1170. for (var mixin in MixinLoader) {
  1171. if (MixinLoader.hasOwnProperty(mixin)) {
  1172. Network.prototype[mixin] = MixinLoader[mixin];
  1173. }
  1174. }
  1175. };
  1176. /**
  1177. * Load the XY positions of the nodes into the dataset.
  1178. */
  1179. Network.prototype.storePosition = function() {
  1180. console.log("storePosition is depricated: use .storePositions() from now on.")
  1181. this.storePositions();
  1182. };
  1183. /**
  1184. * Load the XY positions of the nodes into the dataset.
  1185. */
  1186. Network.prototype.storePositions = function() {
  1187. var dataArray = [];
  1188. for (var nodeId in this.body.nodes) {
  1189. if (this.body.nodes.hasOwnProperty(nodeId)) {
  1190. var node = this.body.nodes[nodeId];
  1191. var allowedToMoveX = !this.body.nodes.xFixed;
  1192. var allowedToMoveY = !this.body.nodes.yFixed;
  1193. if (this.body.data.nodes._data[nodeId].x != Math.round(node.x) || this.body.data.nodes._data[nodeId].y != Math.round(node.y)) {
  1194. dataArray.push({id:nodeId,x:Math.round(node.x),y:Math.round(node.y),allowedToMoveX:allowedToMoveX,allowedToMoveY:allowedToMoveY});
  1195. }
  1196. }
  1197. }
  1198. this.body.data.nodes.update(dataArray);
  1199. };
  1200. /**
  1201. * Return the positions of the nodes.
  1202. */
  1203. Network.prototype.getPositions = function(ids) {
  1204. var dataArray = {};
  1205. if (ids !== undefined) {
  1206. if (Array.isArray(ids) == true) {
  1207. for (var i = 0; i < ids.length; i++) {
  1208. if (this.body.nodes[ids[i]] !== undefined) {
  1209. var node = this.body.nodes[ids[i]];
  1210. dataArray[ids[i]] = {x: Math.round(node.x), y: Math.round(node.y)};
  1211. }
  1212. }
  1213. }
  1214. else {
  1215. if (this.body.nodes[ids] !== undefined) {
  1216. var node = this.body.nodes[ids];
  1217. dataArray[ids] = {x: Math.round(node.x), y: Math.round(node.y)};
  1218. }
  1219. }
  1220. }
  1221. else {
  1222. for (var nodeId in this.body.nodes) {
  1223. if (this.body.nodes.hasOwnProperty(nodeId)) {
  1224. var node = this.body.nodes[nodeId];
  1225. dataArray[nodeId] = {x: Math.round(node.x), y: Math.round(node.y)};
  1226. }
  1227. }
  1228. }
  1229. return dataArray;
  1230. };
  1231. /**
  1232. * Returns true when the Network is active.
  1233. * @returns {boolean}
  1234. */
  1235. Network.prototype.isActive = function () {
  1236. return !this.activator || this.activator.active;
  1237. };
  1238. /**
  1239. * Sets the scale
  1240. * @returns {Number}
  1241. */
  1242. Network.prototype.setScale = function () {
  1243. return this._setScale();
  1244. };
  1245. /**
  1246. * Returns the scale
  1247. * @returns {Number}
  1248. */
  1249. Network.prototype.getScale = function () {
  1250. return this._getScale();
  1251. };
  1252. /**
  1253. * Check if a node is a cluster.
  1254. * @param nodeId
  1255. * @returns {*}
  1256. */
  1257. Network.prototype.isCluster = function(nodeId) {
  1258. if (this.body.nodes[nodeId] !== undefined) {
  1259. return this.body.nodes[nodeId].isCluster;
  1260. }
  1261. else {
  1262. console.log("Node does not exist.")
  1263. return false;
  1264. }
  1265. };
  1266. /**
  1267. * Returns the scale
  1268. * @returns {Number}
  1269. */
  1270. Network.prototype.getCenterCoordinates = function () {
  1271. return this.DOMtoCanvas({x: 0.5 * this.frame.canvas.clientWidth, y: 0.5 * this.frame.canvas.clientHeight});
  1272. };
  1273. Network.prototype.getBoundingBox = function(nodeId) {
  1274. if (this.body.nodes[nodeId] !== undefined) {
  1275. return this.body.nodes[nodeId].boundingBox;
  1276. }
  1277. }
  1278. Network.prototype.getConnectedNodes = function(nodeId) {
  1279. var nodeList = [];
  1280. if (this.body.nodes[nodeId] !== undefined) {
  1281. var node = this.body.nodes[nodeId];
  1282. var nodeObj = {nodeId : true}; // used to quickly check if node already exists
  1283. for (var i = 0; i < node.edges.length; i++) {
  1284. var edge = node.edges[i];
  1285. if (edge.toId == nodeId) {
  1286. if (nodeObj[edge.fromId] === undefined) {
  1287. nodeList.push(edge.fromId);
  1288. nodeObj[edge.fromId] = true;
  1289. }
  1290. }
  1291. else if (edge.fromId == nodeId) {
  1292. if (nodeObj[edge.toId] === undefined) {
  1293. nodeList.push(edge.toId)
  1294. nodeObj[edge.toId] = true;
  1295. }
  1296. }
  1297. }
  1298. }
  1299. return nodeList;
  1300. }
  1301. Network.prototype.getEdgesFromNode = function(nodeId) {
  1302. var edgesList = [];
  1303. if (this.body.nodes[nodeId] !== undefined) {
  1304. var node = this.body.nodes[nodeId];
  1305. for (var i = 0; i < node.edges.length; i++) {
  1306. edgesList.push(node.edges[i].id);
  1307. }
  1308. }
  1309. return edgesList;
  1310. }
  1311. Network.prototype.generateColorObject = function(color) {
  1312. return util.parseColor(color);
  1313. }
  1314. module.exports = Network;