I would like to keep my nodes under control so that each of them is linked and there are no lonely nodes.
My script adds a pair of new nodes every 30 seconds from a JSON query. If either of the new nodes is a duplicate of an existing node, the graph will only be updated with the unique node and link it to the other existing node.
While this is going on, I'm shifting off the oldest nodes to keep a maximum of 10 nodes on the graph. It is here that I seem to be running into trouble. How can I go about removing nodes and check for and remove any stragglers, nodes that are not linked to any others?
The script is based on knoren's post on adding new nodes.
this.checkLength = function () {
if (nodes.length > 10) {
var i = links.shift();
nodes.splice(findNodeIndex(i),1);
update();
}
}