New maps in progress... (Fixed error in delete node)

This commit is contained in:
Arturo Gonzalez 2016-04-25 15:09:51 +02:00
parent e47c8641ac
commit c335394a7b
1 changed files with 22 additions and 4 deletions

View File

@ -2688,14 +2688,15 @@ MapController.prototype.deleteNode = function(self, target) {
}
var id_node = "node_" + node.graph_id;
var arrowsToDelete = self.getArrows(id_node);
var arrowsToDelete = self.get_edges_to_del(node.graph_id);
// Delete edges and nodes in "nodes" and "edges" arrays
self.deleteEdgesAndNode(arrowsToDelete, id_node);
// Delete visual edges and nodes
arrowsToDelete.forEach(function(arrow) {
d3.select("#arrow_" + arrow).remove();
d3.select("#arrow_" + arrow['graph_id']).remove();
});
d3.select(self._target + " #" + id_node).remove();
@ -2714,7 +2715,7 @@ MapController.prototype.deleteEdgesAndNode = function(arrowsToDelete, id_node) {
arrowsToDelete.forEach(function(arrow) {
temp = [];
edges.forEach(function(edge) {
if (edge["graph_id"] != arrow) {
if (edge["graph_id"] != arrow['graph_id']) {
temp.push(edge);
}
});
@ -2726,7 +2727,7 @@ MapController.prototype.deleteEdgesAndNode = function(arrowsToDelete, id_node) {
nodes.forEach(function(nodeOrEdge) {
var nodeToDel = "node_" + nodeOrEdge["graph_id"];
if ((nodeOrEdge["graph_id"] != arrow) && (nodeToDel != id_node)) {
if ((nodeOrEdge["graph_id"] != arrow['graph_id']) && (nodeToDel != id_node)) {
temp.push(nodeOrEdge);
}
});
@ -2746,6 +2747,23 @@ MapController.prototype.deleteEdgesAndNode = function(arrowsToDelete, id_node) {
}
}
/**
* Function get_edges_to_del
* Return array[edge]
* This function returns the edges of a node to delete them
*/
MapController.prototype.get_edges_to_del = function(id_graph) {
var return_edges = [];
$.each(edges, function(i, edge) {
if ((edge['to']['graph_id'] == id_graph) || (edge['from']['graph_id'] == id_graph)) {
return_edges.push(edge);
}
});
return return_edges;
}
/**
* Function getArrows
* Return array[id_arrow]