use of org.ivis.layout.LGraph in project cytoscape-impl by cytoscape.
the class SbgnPDLayout method groupZeroDegreeMembers.
/**
* This method finds all the zero degree nodes in the graph which are not
* owned by a complex node. Zero degree nodes at each level are grouped
* together and placed inside a dummy complex to reduce bounds of root
* graph.
*/
private void groupZeroDegreeMembers() {
Map<SbgnPDNode, LGraph> childComplexMap = new HashMap<SbgnPDNode, LGraph>();
for (Object graphObj : this.getGraphManager().getGraphs()) {
ArrayList<SbgnPDNode> zeroDegreeNodes = new ArrayList<SbgnPDNode>();
LGraph ownerGraph = (LGraph) graphObj;
// do not process complex nodes (their members are already owned)
if (ownerGraph.getParent().type != null && ((SbgnPDNode) ownerGraph.getParent()).isComplex())
continue;
for (Object nodeObj : ownerGraph.getNodes()) {
SbgnPDNode node = (SbgnPDNode) nodeObj;
if (calcGraphDegree(node) == 0) {
zeroDegreeNodes.add(node);
}
}
if (zeroDegreeNodes.size() > 1) {
// create a new dummy complex
SbgnPDNode complex = (SbgnPDNode) newNode(null);
complex.type = SbgnPDConstants.COMPLEX;
complex.label = "DummyComplex_" + ownerGraph.getParent().label;
ownerGraph.add(complex);
LGraph childGraph = newGraph(null);
for (SbgnPDNode zeroNode : zeroDegreeNodes) {
ownerGraph.remove(zeroNode);
childGraph.add(zeroNode);
}
dummyComplexList.add(complex);
childComplexMap.put(complex, childGraph);
}
}
for (SbgnPDNode complex : dummyComplexList) this.graphManager.add(childComplexMap.get(complex), complex);
this.getGraphManager().updateBounds();
this.graphManager.resetAllNodes();
this.graphManager.resetAllNodesToApplyGravitation();
this.graphManager.resetAllEdges();
this.calculateNodesToApplyGravitationTo();
}
use of org.ivis.layout.LGraph in project cytoscape-impl by cytoscape.
the class SbgnPDLayout method removeDummyComplexes.
/**
* Dummy complexes (placed in the "dummyComplexList") are removed from the
* graph.
*/
private void removeDummyComplexes() {
// remove dummy complexes and connect children to original parent
for (SbgnPDNode dummyComplex : dummyComplexList) {
LGraph childGraph = dummyComplex.getChild();
LGraph owner = dummyComplex.getOwner();
getGraphManager().getGraphs().remove(childGraph);
dummyComplex.setChild(null);
owner.remove(dummyComplex);
for (Object s : childGraph.getNodes()) owner.add((SbgnPDNode) s);
}
}
use of org.ivis.layout.LGraph in project cytoscape-impl by cytoscape.
the class SbgnPDLayout method removeDummyCompounds.
/**
* This method is used to remove the dummy compounds (previously created for
* each process node) from the graph.
*/
private void removeDummyCompounds() {
for (SbgnProcessNode processNode : this.processNodeList) {
SbgnPDNode dummyNode = processNode.parentCompound;
LGraph childGraph = dummyNode.getChild();
LGraph owner = dummyNode.getOwner();
// add children to original parent
for (Object s : childGraph.getNodes()) owner.add((SbgnPDNode) s);
for (Object e : childGraph.getEdges()) {
SbgnPDEdge edge = (SbgnPDEdge) e;
// childGraph.remove(edge);
owner.add(edge, edge.getSource(), edge.getTarget());
}
// add effectors / remaining edges back to the process
for (int i = 0; i < dummyNode.getEdges().size(); i++) {
SbgnPDEdge edge = (SbgnPDEdge) dummyNode.getEdges().get(i);
dummyNode.getEdges().remove(edge);
edge.setTarget(processNode);
processNode.getEdges().add(edge);
i--;
}
// remove the graph
getGraphManager().getGraphs().remove(childGraph);
dummyNode.setChild(null);
owner.remove(dummyNode);
}
getGraphManager().resetAllNodes();
getGraphManager().resetAllNodesToApplyGravitation();
getGraphManager().resetAllEdges();
this.calculateNodesToApplyGravitationTo();
}
use of org.ivis.layout.LGraph in project cytoscape-impl by cytoscape.
the class SbgnPDLayout method applyPolyomino.
/**
* This method tiles the given list of nodes by using polyomino packing
* algorithm.
*/
private void applyPolyomino(SbgnPDNode parent) {
RectangleD r;
LGraph childGr = parent.getChild();
if (childGr == null) {
System.out.println("Child graph is empty (Polyomino)");
} else {
// packing takes the input as an array. put the members in an array.
SbgnPDNode[] mpArray = new SbgnPDNode[childGr.getNodes().size()];
for (int i = 0; i < childGr.getNodes().size(); i++) {
SbgnPDNode s = (SbgnPDNode) childGr.getNodes().get(i);
mpArray[i] = s;
}
// pack rectangles
RectProc.packRectanglesMino(SbgnPDConstants.COMPLEX_MEM_HORIZONTAL_BUFFER, mpArray.length, mpArray);
// apply compaction
Compaction c = new Compaction((ArrayList<SbgnPDNode>) childGr.getNodes());
c.perform();
// get the resulting rectangle and set parent's (complex) width &
// height
r = calculateBounds(true, (ArrayList<SbgnPDNode>) childGr.getNodes());
parent.setWidth(r.getWidth());
parent.setHeight(r.getHeight());
}
}
use of org.ivis.layout.LGraph in project cytoscape-impl by cytoscape.
the class SbgnPDNode method updateBounds.
/**
* This method updates the bounds of this compound node. If the node is a
* dummy compound, do not include label and extra margins.
*/
@Override
public void updateBounds() {
assert this.getChild() != null;
if (this.getChild().getNodes().size() != 0) {
// wrap the children nodes by re-arranging the boundaries
LGraph childGraph = this.getChild();
childGraph.updateBounds(true);
this.rect.x = childGraph.getLeft();
this.rect.y = childGraph.getTop();
if (this.type != null && this.type.equals(SbgnPDConstants.DUMMY_COMPOUND)) {
this.setWidth(childGraph.getRight() - childGraph.getLeft());
this.setHeight(childGraph.getBottom() - childGraph.getTop());
} else {
this.setWidth(childGraph.getRight() - childGraph.getLeft() + 2 * LayoutConstants.COMPOUND_NODE_MARGIN);
this.setHeight(childGraph.getBottom() - childGraph.getTop() + 2 * LayoutConstants.COMPOUND_NODE_MARGIN + LayoutConstants.LABEL_HEIGHT);
}
}
}
Aggregations