Search in sources :

Example 16 with LayoutNode

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);
    }
}
Also used : LayoutNode(org.cytoscape.view.layout.LayoutNode) CyTable(org.cytoscape.model.CyTable) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode)

Aggregations

LayoutNode (org.cytoscape.view.layout.LayoutNode)16 LayoutPoint (org.cytoscape.view.layout.LayoutPoint)5 CyNode (org.cytoscape.model.CyNode)4 LayoutEdge (org.cytoscape.view.layout.LayoutEdge)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 LGraph (org.ivis.layout.LGraph)2 LGraphManager (org.ivis.layout.LGraphManager)2 LNode (org.ivis.layout.LNode)2 Profile (csapps.layout.Profile)1 Edge (csapps.layout.algorithms.hierarchicalLayout.Edge)1 Graph (csapps.layout.algorithms.hierarchicalLayout.Graph)1 CyGroup (org.cytoscape.group.CyGroup)1 CyGroupManager (org.cytoscape.group.CyGroupManager)1 CyColumn (org.cytoscape.model.CyColumn)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyTable (org.cytoscape.model.CyTable)1