Browse Source

Additional changes for #3500 (#3525)

* Cleaned up some whitespace and added test for issue

* Checking for proper removal, better comments and whitespace cleanup
jittering-top
justinharrell 7 years ago
committed by Yotam Berkowitz
parent
commit
aa320ae8ab
2 changed files with 37 additions and 7 deletions
  1. +2
    -7
      lib/network/modules/EdgesHandler.js
  2. +35
    -0
      test/Network.test.js

+ 2
- 7
lib/network/modules/EdgesHandler.js View File

@ -426,11 +426,8 @@ class EdgesHandler {
* so the right place to do call this is in the handler for event `_dataUpdated`. * so the right place to do call this is in the handler for event `_dataUpdated`.
*/ */
_updateState() { _updateState() {
this._addMissingEdges(); this._addMissingEdges();
this._removeInvalidEdges(); this._removeInvalidEdges();
} }
/** /**
@ -464,19 +461,17 @@ class EdgesHandler {
* @private * @private
*/ */
_addMissingEdges() { _addMissingEdges() {
let edges = this.body.edges; let edges = this.body.edges;
let edgesData = this.body.data.edges; let edgesData = this.body.data.edges;
let addIds = []; let addIds = [];
edgesData.forEach((edgeData, edgeId) => { edgesData.forEach((edgeData, edgeId) => {
let edge = edges[edgeId]; let edge = edges[edgeId];
if(edge===undefined)
{
if(edge===undefined) {
addIds.push(edgeId); addIds.push(edgeId);
} }
}); });
this.add(addIds,true); this.add(addIds,true);
} }
} }

+ 35
- 0
test/Network.test.js View File

@ -610,6 +610,41 @@ describe('Edge', function () {
assert.notEqual(edges[3].options.color.color, color); // Has own value assert.notEqual(edges[3].options.color.color, color); // Has own value
assert.equal(edges[4].options.color.color, color); 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 }); // Edge

Loading…
Cancel
Save