use of org.cytoscape.view.layout.LayoutNode in project cytoscape-impl by cytoscape.
the class DegreeSortedCircleLayoutTask method layoutPartition.
@Override
public void layoutPartition(LayoutPartition partition) {
// Create attribute
final CyTable table = network.getDefaultNodeTable();
if (table.getColumn(DEGREE_ATTR_NAME) == null)
table.createColumn(DEGREE_ATTR_NAME, Integer.class, false);
// just add the unlocked nodes
final List<LayoutNode> nodes = new ArrayList<LayoutNode>();
for (final LayoutNode ln : partition.getNodeList()) {
if (!ln.isLocked())
nodes.add(ln);
}
if (cancelled)
return;
// sort the Nodes based on the degree
Collections.sort(nodes, new Comparator<LayoutNode>() {
public int compare(LayoutNode o1, LayoutNode o2) {
final CyNode node1 = o1.getNode();
final CyNode node2 = o2.getNode();
// FIXME: should allow parametrization of edge type? (expose as
// tunable)
final int d1 = network.getAdjacentEdgeList(node1, CyEdge.Type.ANY).size();
final int d2 = network.getAdjacentEdgeList(node2, CyEdge.Type.ANY).size();
// Create Degree Attribute
o1.getRow().set(DEGREE_ATTR_NAME, d1);
o2.getRow().set(DEGREE_ATTR_NAME, d2);
return (d2 - d1);
}
public boolean equals(Object o) {
return false;
}
});
if (cancelled)
return;
// place each Node in a circle
int r = 100 * (int) Math.sqrt(nodes.size());
double phi = (2 * Math.PI) / nodes.size();
// We want to figure out our mins & maxes anew
partition.resetNodes();
for (int i = 0; i < nodes.size(); i++) {
LayoutNode node = nodes.get(i);
node.setX(r + (r * Math.sin(i * phi)));
node.setY(r + (r * Math.cos(i * phi)));
partition.moveNodeToLocation(node);
}
}
Aggregations