Skip to content

Commit

Permalink
Additional changes for almende#3500 (almende#3525)
Browse files Browse the repository at this point in the history
* Cleaned up some whitespace and added test for issue

* Checking for proper removal, better comments and whitespace cleanup
  • Loading branch information
justinharrell authored and yotamberk committed Oct 6, 2017
1 parent e4efee6 commit aa320ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/network/modules/EdgesHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,8 @@ class EdgesHandler {
* so the right place to do call this is in the handler for event `_dataUpdated`.
*/
_updateState() {

this._addMissingEdges();

this._removeInvalidEdges();

}

/**
Expand Down Expand Up @@ -464,19 +461,17 @@ class EdgesHandler {
* @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)
{
if(edge===undefined) {
addIds.push(edgeId);
}
});

this.add(addIds,true);
}
}
Expand Down
35 changes: 35 additions & 0 deletions test/Network.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,41 @@ describe('Edge', function () {
assert.notEqual(edges[3].options.color.color, color); // Has own value
assert.equal(edges[4].options.color.color, color);
});

/**
* Unit test for fix of #3500
* Checking to make sure edges that become unconnected due to node removal get reconnected
*/
it('has reconnected edges', function () {
var node1 = {id:1, label:"test1"};
var node2 = {id:2, label:"test2"};
var nodes = new vis.DataSet([node1, node2]);

var edge = {id:1, from: 1, to:2};
var edges = new vis.DataSet([edge]);

var data = {
nodes: nodes,
edges: edges
};

var container = document.getElementById('mynetwork');
var network = new vis.Network(container, data);

//remove node causing edge to become disconnected
nodes.remove(node2.id);

var foundEdge = network.body.edges[edge.id];

assert.ok(foundEdge===undefined, "edge is still in state cache");

//add node back reconnecting edge
nodes.add(node2);

foundEdge = network.body.edges[edge.id];

assert.ok(foundEdge!==undefined, "edge is missing from state cache");
});
}); // Edge


Expand Down

0 comments on commit aa320ae

Please sign in to comment.