Commit 242f6640 authored by Clement Frainay's avatar Clement Frainay

Create collapse function

Univisit a node and hide its direct neighbor. Visited neighbor reaction are unvisited if they don't lie between at least two visited compounds. Can generate isolated compounds.
parent 54eeed78
......@@ -287,7 +287,7 @@ Ext.define('metExploreViz.view.panel.viz.VizController', {
hidden: false,
iconCls: "neighboursCollapse",
handler: function () {
metExploreD3.GraphNode.showNeighbours(theNode);
metExploreD3.GraphNode.hideNeighbours(theNode);
}
}, {
text: 'Remove',
......
......@@ -163,6 +163,85 @@ metExploreD3.GraphNode = {
});
metExploreD3.GraphNetwork.updateNetwork("viz", _metExploreViz.getSessionById("viz"));
},
hideNeighbours: function(node){
//get data from model
//unvisit and unfix selected node
var networkData = _metExploreViz.getSessionById("viz").getD3Data();
node.unvisit();
var allNodes = d3.select("#viz").select("#D3viz").selectAll("g.node");
allNodes.filter(function (d) {
return d.getId()===node.getId();
}).style("fill","white");
node.setLocked(false);
metExploreD3.GraphNode.unfixNode(node);
//extract links, keep thoses involving metabolite arg
networkData.getLinks().filter(function(links) {
return links.getSource() == node || links.getTarget() == node
}).forEach(function(link) {
//get all succesor reaction
if(link.getSource().getId()===node.getId() && link.getTarget().getBiologicalType()!=="pathway"){
reactionNeighbour = link.getTarget();
if(!reactionNeighbour.isVisited()){
//hide if not visited (thus only accessible from the node to collapse)
reactionNeighbour.hide();
}else{
visitedNeighbors = 0;
//count the number of visited neighbor of the reaction
networkData.getLinks().forEach(function(l){
if(l.getSource().getId()===reactionNeighbour.getId() && l.getTarget().isVisited()) {
visitedNeighbors=visitedNeighbors+1;
}
if(l.getTarget().getId()===reactionNeighbour.getId() && l.getSource().isVisited()) {
visitedNeighbors=visitedNeighbors+1;
}
});
//if the reaction only bridge one visited node to the node to collapse (only one visited neighbor), unvisit
if(visitedNeighbors<2){
allNodes.filter(function (d) {
return d.getId()===reactionNeighbour.getId();
}).style("fill","white");
reactionNeighbour.setLocked(false);
metExploreD3.GraphNode.unfixNode(reactionNeighbour);
reactionNeighbour.unvisit();
}
}
//get all predecessor reaction
} else if(link.getTarget().getId()===node.getId() && link.getSource().getBiologicalType()!=="pathway") {
reactionNeighbour = link.getSource();
if(!reactionNeighbour.isVisited()){
//hide if not visited (thus only accessible from the node to collapse)
reactionNeighbour.hide();
}else{
//count the number of visited neighbor of the reaction
visitedNeighbors = 0;
networkData.getLinks().forEach(function(l){
if(l.getSource().getId()===reactionNeighbour.getId() && l.getTarget().isVisited()) {
visitedNeighbors=visitedNeighbors+1;
}
if(l.getTarget().getId()===reactionNeighbour.getId() && l.getSource().isVisited()) {
visitedNeighbors=visitedNeighbors+1;
}
});
//if the reaction only bridge one visited node to the node to collapse (only one visited neighbor), unvisit
if(visitedNeighbors<2){
allNodes.filter(function (d) {
return d.getId()===reactionNeighbour.getId();
}).style("fill","white");
reactionNeighbour.setLocked(false);
metExploreD3.GraphNode.unfixNode(reactionNeighbour);
reactionNeighbour.unvisit();
}
}
};
});
//update display
metExploreD3.GraphNetwork.updateNetwork("viz", _metExploreViz.getSessionById("viz"));
},
// setNeighboursVisibility: function(node, visibility){
// //get data from model
// var networkData = _metExploreViz.getSessionById("viz").getD3Data();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment