Skip to content

Commit

Permalink
re-adds edges if they are now connected and add does not add invalid …
Browse files Browse the repository at this point in the history
…edges (almende#3516)
  • Loading branch information
justinharrell authored and yotamberk committed Oct 3, 2017
1 parent 2860d73 commit 3581561
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions lib/network/modules/EdgesHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,23 @@ class EdgesHandler {
}

/**
* Scan for missing nodes and remove corresponding edges, if any.
*
* There is no direct relation between the nodes and the edges DataSet,
* so the right place to do call this is in the handler for event `_dataUpdated`.
*/
_updateState() {

this._addMissingEdges();

this._removeInvalidEdges();

}

/**
* Scan for missing nodes and remove corresponding edges, if any.
* @private
*/
_removeInvalidEdges() {

let edgesToDelete = [];

util.forEach(this.body.edges, (edge, id) => {
Expand All @@ -447,6 +458,27 @@ class EdgesHandler {

this.remove(edgesToDelete, false);
}

/**
* add all edges from dataset that are not in the cached state
* @private
*/
_addMissingEdges() {

let edges = this.body.edges;
let edgesData = this.body.data.edges;
let addIds = [];

edgesData.forEach((edgeData, edgeId) => {
let edge = edges[edgeId];
if(edge===undefined)
{
addIds.push(edgeId);
}
});

this.add(addIds,true);
}
}

export default EdgesHandler;

0 comments on commit 3581561

Please sign in to comment.