New maps in progress... (Changed jquery each to javascript native each and more fixes)

This commit is contained in:
Arturo Gonzalez 2016-03-09 13:17:27 +01:00
parent ed3b3e7094
commit 1330fd5a5f
1 changed files with 17 additions and 20 deletions

View File

@ -592,18 +592,13 @@ MapController.prototype.nodeGetDetails = function(data_id, type, id_map, data_gr
MapController.prototype.deleteNode = function(self, target) {
var id_node = d3.select(target).attr("id");
var arrowsToDelete = self.getArrows(self, id_node);
$.each(nodes, function(i, e) {
var node = "node_" + e["graph_id"];
if (node == id_node) {
nodes.splice(i, 1);
return false;
}
});
self.deleteEdges(arrowsToDelete);
// Delete edges and nodes in "nodes" and "edges" arrays
self.deleteEdgesAndNode(arrowsToDelete, id_node);
$.each(arrowsToDelete, function(i, e) {
d3.select("#arrow_" + e).remove();
// Delete visual edges and nodes
arrowsToDelete.forEach(function(arrow) {
d3.select("#arrow_" + arrow).remove();
});
d3.select(target).remove();
}
@ -613,7 +608,7 @@ MapController.prototype.deleteNode = function(self, target) {
* Return void
* This function delete the edges of a node in the edges array
*/
MapController.prototype.deleteEdges = function(arrowsToDelete) {
MapController.prototype.deleteEdgesAndNode = function(arrowsToDelete, id_node) {
var newEdges = [];
arrowsToDelete.forEach(function(arrow) {
@ -627,9 +622,10 @@ MapController.prototype.deleteEdges = function(arrowsToDelete) {
});
arrowsToDelete.forEach(function(arrow) {
nodes.forEach(function(edge) {
if (edge["graph_id"] != arrow) {
newEdges.push(edge);
nodes.forEach(function(nodeOrEdge) {
var nodeToDel = "node_" + nodeOrEdge["graph_id"];
if ((nodeOrEdge["graph_id"] != arrow) && (nodeToDel != id_node)) {
newEdges.push(nodeOrEdge);
}
});
nodes = newEdges;
@ -645,14 +641,15 @@ MapController.prototype.deleteEdges = function(arrowsToDelete) {
MapController.prototype.getArrows = function(self, id_node) {
var edgesToDel = [];
var j = 0;
$.each(edges, function(i, e) {
var nodeTo = "node_" + e["to"];
var nodeFrom = "node_" + e["from"];
if (nodeTo == id_node ||nodeFrom == id_node) {
edgesToDel[j] = e["graph_id"];
j++;
edges.forEach(function(edge, index) {
var nodeTo = "node_" + edge["to"];
var nodeFrom = "node_" + edge["from"];
if (nodeTo == id_node || nodeFrom == id_node) {
edgesToDel[index] = edge["graph_id"];
}
});
return edgesToDel;
}