public void testHideRestore(){
CyNetwork network = Cytoscape.getCurrentNetwork();
List<CyNode> nodeList = Cytoscape.getCyNodesList();
List<CyEdge> edgeList = Cytoscape.getCyEdgesList();
//1. set all nodes and edges invisible
for (CyNode node: nodeList){
network.hideNode(node.getRootGraphIndex());
}
for (CyEdge edge: edgeList){
network.hideEdge(edge.getRootGraphIndex());
}
//2. restore all nodes and edges
for (CyNode node: nodeList){
network.restoreNode(node.getRootGraphIndex());
}
for (CyEdge edge: edgeList){
network.restoreEdge(edge.getRootGraphIndex());
}
}
I want to hide nodes and edges and be able to unhide them again.
I have an attribute defined and depending on the values of the
attribute the nodes/edges should be visible (or not).
How can I perform this task ?
Found the problem somehow:
1. Hiding hides the nodes and edges
2. Restore makes the node or edge visible, but all Layout information
is lost (position and all information of the VisualStyle). Therefore
all the nodes are located at the origin with no Layout after restore.
The single node which is visible are all nodes of the graph at the
origin.
Seems like a mayor bug, because hiding and restoration shouldn't
change the layout or position.
I need some simple methods:
CyNode node;
CyEdge edge;
// hide
node.setVisible(false);
edge.setVisible(false);
// show
node.setVisible(true);
edge.setVisible(true);
without change of the Layout. How is this possible in Cytoscape?
double xLocation = nodeView.getXPosition();
double yLocation = nodeView.getYPosition();
double width = nodeView.getWidth();
double height = nodeView.getHeight();
and then restore those values when I restore the nodes. You may also
want to try to operate on the view rather than the network:
CyNetworkView view = Cytoscape.getCurrentNetworkView();
for (CyNode node: nodeList) {
view.hideGraphObject(node);
}
for (CyNode node: nodeList) {
view.showGraphObject(node);
}
I'm not positive that the position information is saved when you hide
something in the view, but it's worth a try...
-- scooter
CyNetworkView view = Cytoscape.getCurrentNetworkView();
for (CyEdge edge: edgeList) {
view.hideGraphObject(edge);
}
for (CyNode node: nodeList) {
view.hideGraphObject(node);
}
Also tried to apply
view.updateView();
view.redrawGraph(true,false);
after hiding the nodes and edges, but are still visible. Seems like
the view.hideGraphObject() doesnt't work.
Don't know what else to do than updateView() or redrawGraph() to get
the changes to work.
Why is the hideGraphObject() not applied to the view ?
@scooter
Testing your first approach with the storage of the position and
layout information now.
Hope the storing and application of all the attributes is fast enough.
public void testHideRestore(){
CyNetwork network = Cytoscape.getCurrentNetwork();
CyNetworkView view = Cytoscape.getCurrentNetworkView();
List<CyNode> nodeList = Cytoscape.getCyNodesList();
List<CyEdge> edgeList = Cytoscape.getCyEdgesList();
//storage of the positions
Map<String, Double> xPosition = new HashMap<String, Double>();
Map<String, Double> yPosition = new HashMap<String, Double>();
//1. set all nodes and edges invisible
for (CyNode node: nodeList){
NodeView nodeView = view.getNodeView(node);
xPosition.put(node.getIdentifier(), nodeView.getXPosition());
yPosition.put(node.getIdentifier(), nodeView.getYPosition());
network.hideNode(node.getRootGraphIndex());
}
/* Not necessary, already hidden because adjacent egdes of nodes are
* hidden
for (CyEdge edge: edgeList){
network.hideEdge(edge.getRootGraphIndex());
}*/
JOptionPane.showMessageDialog(null, "Nodes hidden.");
//2.1 restore all nodes and edges (with position)
for (CyNode node: nodeList){
network.restoreNode(node.getRootGraphIndex());
NodeView nodeView = view.getNodeView(node);
nodeView.setXPosition(xPosition.get(node.getIdentifier()));
nodeView.setYPosition(yPosition.get(node.getIdentifier()));
}
for (CyEdge edge: edgeList){
network.restoreEdge(edge.getRootGraphIndex());
}
//2.2 restore the visual style
String vsName = "FluxViz";
VisualMappingManager vmm = Cytoscape.getVisualMappingManager();
CalculatorCatalog calc_cat = vmm.getCalculatorCatalog();
vi_style = calc_cat.getVisualStyle(vsName);
view.setVisualStyle(vsName);
vmm.setVisualStyle(vi_style);
vmm.applyAppearances();
JOptionPane.showMessageDialog(null, "Nodes visible.");
}
Don't like the solution. There should be a simple nodeView.hide() and
nodeView.unhide() which just make the nodes invisible. Same for the
edges.