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.

770 lines
22 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  1. // Load custom shapes into CanvasRenderingContext2D
  2. require('./shapes');
  3. var Emitter = require('emitter-component');
  4. var Hammer = require('../module/hammer');
  5. var util = require('../util');
  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 Popup = require('./Popup');
  13. var Activator = require('../shared/Activator');
  14. var locales = require('./locales');
  15. import NodesHandler from './modules/NodesHandler';
  16. import EdgesHandler from './modules/EdgesHandler';
  17. import PhysicsEngine from './modules/PhysicsEngine';
  18. import ClusterEngine from './modules/Clustering';
  19. import CanvasRenderer from './modules/CanvasRenderer';
  20. import Canvas from './modules/Canvas';
  21. import View from './modules/View';
  22. import InteractionHandler from './modules/InteractionHandler';
  23. import SelectionHandler from "./modules/SelectionHandler";
  24. import LayoutEngine from "./modules/LayoutEngine";
  25. /**
  26. * @constructor Network
  27. * Create a network visualization, displaying nodes and edges.
  28. *
  29. * @param {Element} container The DOM element in which the Network will
  30. * be created. Normally a div element.
  31. * @param {Object} data An object containing parameters
  32. * {Array} nodes
  33. * {Array} edges
  34. * @param {Object} options Options
  35. */
  36. function Network (container, data, options) {
  37. if (!(this instanceof Network)) {
  38. throw new SyntaxError('Constructor must be called with the new operator');
  39. }
  40. // set constant values
  41. this.remainingOptions = {
  42. dataManipulation: {
  43. enabled: false,
  44. initiallyVisible: false
  45. },
  46. hierarchicalLayout: {
  47. enabled:false,
  48. levelSeparation: 150,
  49. nodeSpacing: 100,
  50. direction: "UD", // UD, DU, LR, RL
  51. layout: "hubsize" // hubsize, directed
  52. },
  53. locale: 'en',
  54. locales: locales,
  55. useDefaultGroups: true
  56. };
  57. // containers for nodes and edges
  58. this.body = {
  59. nodes: {},
  60. nodeIndices: [],
  61. edges: {},
  62. edgeIndices: [],
  63. data: {
  64. nodes: null, // A DataSet or DataView
  65. edges: null // A DataSet or DataView
  66. },
  67. functions:{
  68. createNode: () => {},
  69. createEdge: () => {}
  70. },
  71. emitter: {
  72. on: this.on.bind(this),
  73. off: this.off.bind(this),
  74. emit: this.emit.bind(this),
  75. once: this.once.bind(this)
  76. },
  77. eventListeners: {
  78. onTap: function() {},
  79. onTouch: function() {},
  80. onDoubleTap: function() {},
  81. onHold: function() {},
  82. onDragStart: function() {},
  83. onDrag: function() {},
  84. onDragEnd: function() {},
  85. onMouseWheel: function() {},
  86. onPinch: function() {},
  87. onMouseMove: function() {},
  88. onRelease: function() {}
  89. },
  90. container: container,
  91. view: {
  92. scale:1,
  93. translation:{x:0,y:0}
  94. }
  95. };
  96. // todo think of good comment for this set
  97. var groups = new Groups(); // object with groups
  98. var images = new Images(() => this.body.emitter.emit("_requestRedraw")); // object with images
  99. // data handling modules
  100. this.canvas = new Canvas(this.body); // DOM handler
  101. this.selectionHandler = new SelectionHandler(this.body, this.canvas); // Selection handler
  102. this.interactionHandler = new InteractionHandler(this.body, this.canvas, this.selectionHandler); // Interaction handler handles all the hammer bindings (that are bound by canvas), key
  103. this.view = new View(this.body, this.canvas); // camera handler, does animations and zooms
  104. this.renderer = new CanvasRenderer(this.body, this.canvas); // renderer, starts renderloop, has events that modules can hook into
  105. this.physics = new PhysicsEngine(this.body); // physics engine, does all the simulations
  106. this.layoutEngine = new LayoutEngine(this.body);
  107. this.clustering = new ClusterEngine(this.body); // clustering api
  108. this.nodesHandler = new NodesHandler(this.body, images, groups, this.layoutEngine); // Handle adding, deleting and updating of nodes as well as global options
  109. this.edgesHandler = new EdgesHandler(this.body, images, groups); // Handle adding, deleting and updating of edges as well as global options
  110. // this event will trigger a rebuilding of the cache everything. Used when nodes or edges have been added or removed.
  111. this.body.emitter.on("_dataChanged", (params) => {
  112. var t0 = new Date().valueOf();
  113. // update shortcut lists
  114. this._updateVisibleIndices();
  115. this.physics.updatePhysicsIndices();
  116. // update values
  117. this._updateValueRange(this.body.nodes);
  118. this._updateValueRange(this.body.edges);
  119. // update edges
  120. this._reconnectEdges();
  121. this._markAllEdgesAsDirty();
  122. // start simulation (can be called safely, even if already running)
  123. this.body.emitter.emit("startSimulation");
  124. console.log("_dataChanged took:", new Date().valueOf() - t0);
  125. })
  126. // this is called when options of EXISTING nodes or edges have changed.
  127. this.body.emitter.on("_dataUpdated", () => {
  128. var t0 = new Date().valueOf();
  129. // update values
  130. this._updateValueRange(this.body.nodes);
  131. this._updateValueRange(this.body.edges);
  132. // update edges
  133. this._reconnectEdges();
  134. this._markAllEdgesAsDirty();
  135. // start simulation (can be called safely, even if already running)
  136. this.body.emitter.emit("startSimulation");
  137. console.log("_dataUpdated took:", new Date().valueOf() - t0);
  138. });
  139. // create the DOM elements
  140. this.canvas.create();
  141. // apply options
  142. this.setOptions(options);
  143. // load data (the disable start variable will be the same as the enabled clustering)
  144. this.setData(data);
  145. }
  146. // Extend Network with an Emitter mixin
  147. Emitter(Network.prototype);
  148. /**
  149. * Update the this.body.nodeIndices with the most recent node index list
  150. * @private
  151. */
  152. Network.prototype._updateVisibleIndices = function() {
  153. let nodes = this.body.nodes;
  154. let edges = this.body.edges;
  155. this.body.nodeIndices = [];
  156. this.body.edgeIndices = [];
  157. for (let nodeId in nodes) {
  158. if (nodes.hasOwnProperty(nodeId)) {
  159. if (nodes[nodeId].options.hidden === false) {
  160. this.body.nodeIndices.push(nodeId);
  161. }
  162. }
  163. }
  164. for (let edgeId in edges) {
  165. if (edges.hasOwnProperty(edgeId)) {
  166. if (edges[edgeId].options.hidden === false) {
  167. this.body.edgeIndices.push(edgeId);
  168. }
  169. }
  170. }
  171. };
  172. /**
  173. * Set nodes and edges, and optionally options as well.
  174. *
  175. * @param {Object} data Object containing parameters:
  176. * {Array | DataSet | DataView} [nodes] Array with nodes
  177. * {Array | DataSet | DataView} [edges] Array with edges
  178. * {String} [dot] String containing data in DOT format
  179. * {String} [gephi] String containing data in gephi JSON format
  180. * {Options} [options] Object with options
  181. * @param {Boolean} [disableStart] | optional: disable the calling of the start function.
  182. */
  183. Network.prototype.setData = function(data) {
  184. // reset the physics engine.
  185. this.body.emitter.emit("resetPhysics");
  186. this.body.emitter.emit("_resetData");
  187. // unselect all to ensure no selections from old data are carried over.
  188. this.selectionHandler.unselectAll();
  189. if (data && data.dot && (data.nodes || data.edges)) {
  190. throw new SyntaxError('Data must contain either parameter "dot" or ' +
  191. ' parameter pair "nodes" and "edges", but not both.');
  192. }
  193. // set options
  194. this.setOptions(data && data.options);
  195. // set all data
  196. if (data && data.dot) {
  197. // parse DOT file
  198. if(data && data.dot) {
  199. var dotData = dotparser.DOTToGraph(data.dot);
  200. this.setData(dotData);
  201. return;
  202. }
  203. }
  204. else if (data && data.gephi) {
  205. // parse DOT file
  206. if(data && data.gephi) {
  207. var gephiData = gephiParser.parseGephi(data.gephi);
  208. this.setData(gephiData);
  209. return;
  210. }
  211. }
  212. else {
  213. this.nodesHandler.setData(data && data.nodes);
  214. this.edgesHandler.setData(data && data.edges);
  215. }
  216. // find a stable position or start animating to a stable position
  217. this.body.emitter.emit("initPhysics");
  218. };
  219. /**
  220. * Set options
  221. * @param {Object} options
  222. */
  223. Network.prototype.setOptions = function (options) {
  224. if (options) {
  225. //var fields = ['nodes','edges','smoothCurves','hierarchicalLayout','navigation',
  226. // 'keyboard','dataManipulation','onAdd','onEdit','onEditEdge','onConnect','onDelete','clickToUse'
  227. //];
  228. // extend all but the values in fields
  229. //util.selectiveNotDeepExtend(fields,this.constants, options);
  230. //util.selectiveNotDeepExtend(['color'],this.constants.nodes, options.nodes);
  231. //util.selectiveNotDeepExtend(['color','length'],this.constants.edges, options.edges);
  232. //this.groups.useDefaultGroups = this.constants.useDefaultGroups;
  233. this.nodesHandler.setOptions(options.nodes);
  234. this.edgesHandler.setOptions(options.edges);
  235. this.physics.setOptions(options.physics);
  236. this.canvas.setOptions(options.canvas);
  237. this.renderer.setOptions(options.rendering);
  238. this.view.setOptions(options.view);
  239. this.interactionHandler.setOptions(options.interaction);
  240. this.selectionHandler.setOptions(options.selection);
  241. this.layoutEngine.setOptions(options.layout);
  242. this.clustering.setOptions(options.clustering);
  243. //util.mergeOptions(this.constants, options,'smoothCurves');
  244. //util.mergeOptions(this.constants, options,'hierarchicalLayout');
  245. //util.mergeOptions(this.constants, options,'clustering');
  246. //util.mergeOptions(this.constants, options,'navigation');
  247. //util.mergeOptions(this.constants, options,'keyboard');
  248. //util.mergeOptions(this.constants, options,'dataManipulation');
  249. //if (options.dataManipulation) {
  250. // this.editMode = this.constants.dataManipulation.initiallyVisible;
  251. //}
  252. //// TODO: work out these options and document them
  253. //
  254. //
  255. //
  256. //if (options.groups) {
  257. // for (var groupname in options.groups) {
  258. // if (options.groups.hasOwnProperty(groupname)) {
  259. // var group = options.groups[groupname];
  260. // this.groups.add(groupname, group);
  261. // }
  262. // }
  263. //}
  264. //
  265. //if (options.tooltip) {
  266. // for (prop in options.tooltip) {
  267. // if (options.tooltip.hasOwnProperty(prop)) {
  268. // this.constants.tooltip[prop] = options.tooltip[prop];
  269. // }
  270. // }
  271. // if (options.tooltip.color) {
  272. // this.constants.tooltip.color = util.parseColor(options.tooltip.color);
  273. // }
  274. //}
  275. if ('clickToUse' in options) {
  276. if (options.clickToUse === true) {
  277. if (this.activator === undefined) {
  278. this.activator = new Activator(this.frame);
  279. this.activator.on('change', this._createKeyBinds.bind(this));
  280. }
  281. }
  282. else {
  283. if (this.activator !== undefined) {
  284. this.activator.destroy();
  285. delete this.activator;
  286. }
  287. this.body.emitter.emit("activate");
  288. }
  289. }
  290. else {
  291. this.body.emitter.emit("activate");
  292. }
  293. this.canvas.setSize();
  294. }
  295. };
  296. /**
  297. * Cleans up all bindings of the network, removing it fully from the memory IF the variable is set to null after calling this function.
  298. * var network = new vis.Network(..);
  299. * network.destroy();
  300. * network = null;
  301. */
  302. Network.prototype.destroy = function() {
  303. this.body.emitter.emit("destroy");
  304. // clear events
  305. this.body.emitter.off();
  306. // remove the container and everything inside it recursively
  307. this.util.recursiveDOMDelete(this.body.container);
  308. };
  309. /**
  310. * Check if there is an element on the given position in the network
  311. * (a node or edge). If so, and if this element has a title,
  312. * show a popup window with its title.
  313. *
  314. * @param {{x:Number, y:Number}} pointer
  315. * @private
  316. */
  317. Network.prototype._checkShowPopup = function (pointer) {
  318. var obj = {
  319. left: this._XconvertDOMtoCanvas(pointer.x),
  320. top: this._YconvertDOMtoCanvas(pointer.y),
  321. right: this._XconvertDOMtoCanvas(pointer.x),
  322. bottom: this._YconvertDOMtoCanvas(pointer.y)
  323. };
  324. var id;
  325. var previousPopupObjId = this.popupObj === undefined ? "" : this.popupObj.id;
  326. var nodeUnderCursor = false;
  327. var popupType = "node";
  328. if (this.popupObj == undefined) {
  329. // search the nodes for overlap, select the top one in case of multiple nodes
  330. var nodes = this.body.nodes;
  331. var overlappingNodes = [];
  332. for (id in nodes) {
  333. if (nodes.hasOwnProperty(id)) {
  334. var node = nodes[id];
  335. if (node.isOverlappingWith(obj)) {
  336. if (node.getTitle() !== undefined) {
  337. overlappingNodes.push(id);
  338. }
  339. }
  340. }
  341. }
  342. if (overlappingNodes.length > 0) {
  343. // if there are overlapping nodes, select the last one, this is the
  344. // one which is drawn on top of the others
  345. this.popupObj = this.body.nodes[overlappingNodes[overlappingNodes.length - 1]];
  346. // if you hover over a node, the title of the edge is not supposed to be shown.
  347. nodeUnderCursor = true;
  348. }
  349. }
  350. if (this.popupObj === undefined && nodeUnderCursor == false) {
  351. // search the edges for overlap
  352. var edges = this.body.edges;
  353. var overlappingEdges = [];
  354. for (id in edges) {
  355. if (edges.hasOwnProperty(id)) {
  356. var edge = edges[id];
  357. if (edge.connected === true && (edge.getTitle() !== undefined) &&
  358. edge.isOverlappingWith(obj)) {
  359. overlappingEdges.push(id);
  360. }
  361. }
  362. }
  363. if (overlappingEdges.length > 0) {
  364. this.popupObj = this.body.edges[overlappingEdges[overlappingEdges.length - 1]];
  365. popupType = "edge";
  366. }
  367. }
  368. if (this.popupObj) {
  369. // show popup message window
  370. if (this.popupObj.id != previousPopupObjId) {
  371. if (this.popup === undefined) {
  372. this.popup = new Popup(this.frame, this.constants.tooltip);
  373. }
  374. this.popup.popupTargetType = popupType;
  375. this.popup.popupTargetId = this.popupObj.id;
  376. // adjust a small offset such that the mouse cursor is located in the
  377. // bottom left location of the popup, and you can easily move over the
  378. // popup area
  379. this.popup.setPosition(pointer.x + 3, pointer.y - 5);
  380. this.popup.setText(this.popupObj.getTitle());
  381. this.popup.show();
  382. }
  383. }
  384. else {
  385. if (this.popup) {
  386. this.popup.hide();
  387. }
  388. }
  389. };
  390. /**
  391. * Check if the popup must be hidden, which is the case when the mouse is no
  392. * longer hovering on the object
  393. * @param {{x:Number, y:Number}} pointer
  394. * @private
  395. */
  396. Network.prototype._checkHidePopup = function (pointer) {
  397. var pointerObj = {
  398. left: this._XconvertDOMtoCanvas(pointer.x),
  399. top: this._YconvertDOMtoCanvas(pointer.y),
  400. right: this._XconvertDOMtoCanvas(pointer.x),
  401. bottom: this._YconvertDOMtoCanvas(pointer.y)
  402. };
  403. var stillOnObj = false;
  404. if (this.popup.popupTargetType == 'node') {
  405. stillOnObj = this.body.nodes[this.popup.popupTargetId].isOverlappingWith(pointerObj);
  406. if (stillOnObj === true) {
  407. var overNode = this.getNodeAt(pointer);
  408. stillOnObj = overNode.id == this.popup.popupTargetId;
  409. }
  410. }
  411. else {
  412. if (this.getNodeAt(pointer) === null) {
  413. stillOnObj = this.body.edges[this.popup.popupTargetId].isOverlappingWith(pointerObj);
  414. }
  415. }
  416. if (stillOnObj === false) {
  417. this.popupObj = undefined;
  418. this.popup.hide();
  419. }
  420. };
  421. Network.prototype._markAllEdgesAsDirty = function() {
  422. for (var edgeId in this.body.edges) {
  423. this.body.edges[edgeId].colorDirty = true;
  424. }
  425. }
  426. /**
  427. * Reconnect all edges
  428. * @private
  429. */
  430. Network.prototype._reconnectEdges = function() {
  431. var id,
  432. nodes = this.body.nodes,
  433. edges = this.body.edges;
  434. for (id in nodes) {
  435. if (nodes.hasOwnProperty(id)) {
  436. nodes[id].edges = [];
  437. }
  438. }
  439. for (id in edges) {
  440. if (edges.hasOwnProperty(id)) {
  441. var edge = edges[id];
  442. edge.from = null;
  443. edge.to = null;
  444. edge.connect();
  445. }
  446. }
  447. };
  448. /**
  449. * Update the values of all object in the given array according to the current
  450. * value range of the objects in the array.
  451. * @param {Object} obj An object containing a set of Edges or Nodes
  452. * The objects must have a method getValue() and
  453. * setValueRange(min, max).
  454. * @private
  455. */
  456. Network.prototype._updateValueRange = function(obj) {
  457. var id;
  458. // determine the range of the objects
  459. var valueMin = undefined;
  460. var valueMax = undefined;
  461. var valueTotal = 0;
  462. for (id in obj) {
  463. if (obj.hasOwnProperty(id)) {
  464. var value = obj[id].getValue();
  465. if (value !== undefined) {
  466. valueMin = (valueMin === undefined) ? value : Math.min(value, valueMin);
  467. valueMax = (valueMax === undefined) ? value : Math.max(value, valueMax);
  468. valueTotal += value;
  469. }
  470. }
  471. }
  472. // adjust the range of all objects
  473. if (valueMin !== undefined && valueMax !== undefined) {
  474. for (id in obj) {
  475. if (obj.hasOwnProperty(id)) {
  476. obj[id].setValueRange(valueMin, valueMax, valueTotal);
  477. }
  478. }
  479. }
  480. };
  481. /**
  482. * Set the translation of the network
  483. * @param {Number} offsetX Horizontal offset
  484. * @param {Number} offsetY Vertical offset
  485. * @private
  486. */
  487. Network.prototype._setTranslation = function(offsetX, offsetY) {
  488. if (this.translation === undefined) {
  489. this.translation = {
  490. x: 0,
  491. y: 0
  492. };
  493. }
  494. if (offsetX !== undefined) {
  495. this.translation.x = offsetX;
  496. }
  497. if (offsetY !== undefined) {
  498. this.translation.y = offsetY;
  499. }
  500. this.emit('viewChanged');
  501. };
  502. /**
  503. * Get the translation of the network
  504. * @return {Object} translation An object with parameters x and y, both a number
  505. * @private
  506. */
  507. Network.prototype._getTranslation = function() {
  508. return {
  509. x: this.translation.x,
  510. y: this.translation.y
  511. };
  512. };
  513. /**
  514. * Scale the network
  515. * @param {Number} scale Scaling factor 1.0 is unscaled
  516. * @private
  517. */
  518. Network.prototype._setScale = function(scale) {
  519. this.scale = scale;
  520. };
  521. /**
  522. * Get the current scale of the network
  523. * @return {Number} scale Scaling factor 1.0 is unscaled
  524. * @private
  525. */
  526. Network.prototype._getScale = function() {
  527. return this.scale;
  528. };
  529. /**
  530. * load the functions that load the mixins into the prototype.
  531. *
  532. * @private
  533. */
  534. Network.prototype._initializeMixinLoaders = function () {
  535. for (var mixin in MixinLoader) {
  536. if (MixinLoader.hasOwnProperty(mixin)) {
  537. Network.prototype[mixin] = MixinLoader[mixin];
  538. }
  539. }
  540. };
  541. /**
  542. * Load the XY positions of the nodes into the dataset.
  543. */
  544. Network.prototype.storePositions = function() {
  545. var dataArray = [];
  546. for (var nodeId in this.body.nodes) {
  547. if (this.body.nodes.hasOwnProperty(nodeId)) {
  548. var node = this.body.nodes[nodeId];
  549. var allowedToMoveX = !this.body.nodes.xFixed;
  550. var allowedToMoveY = !this.body.nodes.yFixed;
  551. if (this.body.data.nodes._data[nodeId].x != Math.round(node.x) || this.body.data.nodes._data[nodeId].y != Math.round(node.y)) {
  552. dataArray.push({id:nodeId,x:Math.round(node.x),y:Math.round(node.y),allowedToMoveX:allowedToMoveX,allowedToMoveY:allowedToMoveY});
  553. }
  554. }
  555. }
  556. this.body.data.nodes.update(dataArray);
  557. };
  558. /**
  559. * Return the positions of the nodes.
  560. */
  561. Network.prototype.getPositions = function(ids) {
  562. var dataArray = {};
  563. if (ids !== undefined) {
  564. if (Array.isArray(ids) == true) {
  565. for (var i = 0; i < ids.length; i++) {
  566. if (this.body.nodes[ids[i]] !== undefined) {
  567. var node = this.body.nodes[ids[i]];
  568. dataArray[ids[i]] = {x: Math.round(node.x), y: Math.round(node.y)};
  569. }
  570. }
  571. }
  572. else {
  573. if (this.body.nodes[ids] !== undefined) {
  574. var node = this.body.nodes[ids];
  575. dataArray[ids] = {x: Math.round(node.x), y: Math.round(node.y)};
  576. }
  577. }
  578. }
  579. else {
  580. for (var nodeId in this.body.nodes) {
  581. if (this.body.nodes.hasOwnProperty(nodeId)) {
  582. var node = this.body.nodes[nodeId];
  583. dataArray[nodeId] = {x: Math.round(node.x), y: Math.round(node.y)};
  584. }
  585. }
  586. }
  587. return dataArray;
  588. };
  589. /**
  590. * Returns true when the Network is active.
  591. * @returns {boolean}
  592. */
  593. Network.prototype.isActive = function () {
  594. return !this.activator || this.activator.active;
  595. };
  596. /**
  597. * Sets the scale
  598. * @returns {Number}
  599. */
  600. Network.prototype.setScale = function () {
  601. return this._setScale();
  602. };
  603. /**
  604. * Returns the scale
  605. * @returns {Number}
  606. */
  607. Network.prototype.getScale = function () {
  608. return this._getScale();
  609. };
  610. /**
  611. * Check if a node is a cluster.
  612. * @param nodeId
  613. * @returns {*}
  614. */
  615. Network.prototype.isCluster = function(nodeId) {
  616. if (this.body.nodes[nodeId] !== undefined) {
  617. return this.body.nodes[nodeId].isCluster;
  618. }
  619. else {
  620. console.log("Node does not exist.")
  621. return false;
  622. }
  623. };
  624. /**
  625. * Returns the scale
  626. * @returns {Number}
  627. */
  628. Network.prototype.getCenterCoordinates = function () {
  629. return this.DOMtoCanvas({x: 0.5 * this.frame.canvas.clientWidth, y: 0.5 * this.frame.canvas.clientHeight});
  630. };
  631. Network.prototype.getBoundingBox = function(nodeId) {
  632. if (this.body.nodes[nodeId] !== undefined) {
  633. return this.body.nodes[nodeId].boundingBox;
  634. }
  635. }
  636. Network.prototype.getConnectedNodes = function(nodeId) {
  637. var nodeList = [];
  638. if (this.body.nodes[nodeId] !== undefined) {
  639. var node = this.body.nodes[nodeId];
  640. var nodeObj = {nodeId : true}; // used to quickly check if node already exists
  641. for (var i = 0; i < node.edges.length; i++) {
  642. var edge = node.edges[i];
  643. if (edge.toId == nodeId) {
  644. if (nodeObj[edge.fromId] === undefined) {
  645. nodeList.push(edge.fromId);
  646. nodeObj[edge.fromId] = true;
  647. }
  648. }
  649. else if (edge.fromId == nodeId) {
  650. if (nodeObj[edge.toId] === undefined) {
  651. nodeList.push(edge.toId)
  652. nodeObj[edge.toId] = true;
  653. }
  654. }
  655. }
  656. }
  657. return nodeList;
  658. }
  659. Network.prototype.getEdgesFromNode = function(nodeId) {
  660. var edgesList = [];
  661. if (this.body.nodes[nodeId] !== undefined) {
  662. var node = this.body.nodes[nodeId];
  663. for (var i = 0; i < node.edges.length; i++) {
  664. edgesList.push(node.edges[i].id);
  665. }
  666. }
  667. return edgesList;
  668. }
  669. Network.prototype.generateColorObject = function(color) {
  670. return util.parseColor(color);
  671. }
  672. module.exports = Network;