Search in sources :

Example 1 with LGraphManager

use of org.ivis.layout.LGraphManager in project cytoscape-impl by cytoscape.

the class CoSELayoutAlgorithmTask method layoutPartition.

@Override
public void layoutPartition(final LayoutPartition partition) {
    if (cancelled)
        return;
    final CyGroupManager groupManager = serviceRegistrar.getService(CyGroupManager.class);
    final CyNetwork network = networkView.getModel();
    // Create the CoSE model
    // (see http://www.cs.bilkent.edu.tr/~ivis/chilay/ChiLay-2.0-PG.pdf)
    cose = new CoSELayout();
    cose.addProgressListener(new ProgressListener() {

        @Override
        public void update(double value) {
            taskMonitor.setProgress(value);
        }
    });
    final LGraphManager gm = cose.getGraphManager();
    final LGraph root = gm.addRoot();
    // Index all LayoutNodes by CyNode for future reference
    final Map<CyNode, LayoutNode> layoutNodeMap = new HashMap<>();
    for (LayoutNode n : partition.getNodeList()) layoutNodeMap.put(n.getNode(), n);
    // Create all CoSE nodes
    final Map<CyNode, LNode> lNodeMap = new HashMap<>();
    for (LayoutNode n : partition.getNodeList()) {
        // If this node does not belong to a CyGroup, let's traverse its potential compound node tree.
        if (groupManager.getGroupsForNode(n.getNode(), network).isEmpty())
            traverseLNodeTree(n, root, cose, lNodeMap, layoutNodeMap, groupManager);
    }
    if (cancelled)
        return;
    // Create all CoSE edges
    final Map<CyEdge, LEdge> lEdgeMap = new HashMap<>();
    final Iterator<LayoutEdge> edgeIter = partition.edgeIterator();
    while (edgeIter.hasNext() && !cancelled) {
        final LayoutEdge e = edgeIter.next();
        createLEdge(e, cose, lNodeMap, lEdgeMap);
    }
    if (cancelled)
        return;
    // Run the layout
    try {
        cose.runLayout();
    } catch (Exception e) {
        logger.error("Error running CoSE Layout", e);
        return;
    }
    if (cancelled)
        return;
    // Move all Node Views to the new positions
    for (LayoutNode n : partition.getNodeList()) partition.moveNodeToLocation(n);
}
Also used : LayoutNode(org.cytoscape.view.layout.LayoutNode) HashMap(java.util.HashMap) LEdge(org.ivis.layout.LEdge) CyNetwork(org.cytoscape.model.CyNetwork) LGraphManager(org.ivis.layout.LGraphManager) LGraph(org.ivis.layout.LGraph) CyEdge(org.cytoscape.model.CyEdge) LayoutEdge(org.cytoscape.view.layout.LayoutEdge) ProgressListener(org.ivis.layout.ProgressListener) CyNode(org.cytoscape.model.CyNode) LNode(org.ivis.layout.LNode) CoSELayout(org.ivis.layout.cose.CoSELayout) CyGroupManager(org.cytoscape.group.CyGroupManager)

Example 2 with LGraphManager

use of org.ivis.layout.LGraphManager in project cytoscape-impl by cytoscape.

the class CoSELayoutAlgorithmTask method traverseLNodeTree.

private void traverseLNodeTree(final LayoutNode layoutNode, final LGraph graph, final CoSELayout cose, final Map<CyNode, LNode> lNodeMap, final Map<CyNode, LayoutNode> layoutNodeMap, final CyGroupManager groupManager) {
    if (lNodeMap.containsKey(layoutNode.getNode()))
        // This node has already been visited!
        return;
    final LNode ln = createLNode(layoutNode, graph, cose, lNodeMap);
    if (groupManager.isGroup(layoutNode.getNode(), networkView.getModel())) {
        final CyGroup group = groupManager.getGroup(layoutNode.getNode(), networkView.getModel());
        if (group != null) {
            final LGraphManager gm = cose.getGraphManager();
            final LGraph subGraph = gm.add(cose.newGraph("G" + group.getGroupNetwork().getSUID()), ln);
            for (CyNode childNode : group.getNodeList()) {
                final LayoutNode childLayoutNode = layoutNodeMap.get(childNode);
                if (childLayoutNode != null)
                    traverseLNodeTree(childLayoutNode, subGraph, cose, lNodeMap, layoutNodeMap, groupManager);
            }
        }
    }
}
Also used : CyGroup(org.cytoscape.group.CyGroup) LayoutNode(org.cytoscape.view.layout.LayoutNode) LGraphManager(org.ivis.layout.LGraphManager) LNode(org.ivis.layout.LNode) CyNode(org.cytoscape.model.CyNode) LGraph(org.ivis.layout.LGraph)

Aggregations

CyNode (org.cytoscape.model.CyNode)2 LayoutNode (org.cytoscape.view.layout.LayoutNode)2 LGraph (org.ivis.layout.LGraph)2 LGraphManager (org.ivis.layout.LGraphManager)2 LNode (org.ivis.layout.LNode)2 HashMap (java.util.HashMap)1 CyGroup (org.cytoscape.group.CyGroup)1 CyGroupManager (org.cytoscape.group.CyGroupManager)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNetwork (org.cytoscape.model.CyNetwork)1 LayoutEdge (org.cytoscape.view.layout.LayoutEdge)1 LEdge (org.ivis.layout.LEdge)1 ProgressListener (org.ivis.layout.ProgressListener)1 CoSELayout (org.ivis.layout.cose.CoSELayout)1