Search in sources :

Example 1 with LNode

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

the class SbgnPDLayout method calculateBounds.

/**
 * This method returns the bounding rectangle of the given set of nodes with
 * or without the margins
 */
protected RectangleD calculateBounds(boolean isMarginIncluded, ArrayList<SbgnPDNode> nodes) {
    int boundLeft = Integer.MAX_VALUE;
    int boundRight = Integer.MIN_VALUE;
    int boundTop = Integer.MAX_VALUE;
    int boundBottom = Integer.MIN_VALUE;
    int nodeLeft;
    int nodeRight;
    int nodeTop;
    int nodeBottom;
    Iterator<SbgnPDNode> itr = nodes.iterator();
    while (itr.hasNext()) {
        LNode lNode = itr.next();
        nodeLeft = (int) (lNode.getLeft());
        nodeRight = (int) (lNode.getRight());
        nodeTop = (int) (lNode.getTop());
        nodeBottom = (int) (lNode.getBottom());
        if (boundLeft > nodeLeft)
            boundLeft = nodeLeft;
        if (boundRight < nodeRight)
            boundRight = nodeRight;
        if (boundTop > nodeTop)
            boundTop = nodeTop;
        if (boundBottom < nodeBottom)
            boundBottom = nodeBottom;
    }
    if (isMarginIncluded) {
        return new RectangleD(boundLeft - SbgnPDConstants.COMPLEX_MEM_MARGIN, boundTop - SbgnPDConstants.COMPLEX_MEM_MARGIN, boundRight - boundLeft + 2 * SbgnPDConstants.COMPLEX_MEM_MARGIN, boundBottom - boundTop + 2 * SbgnPDConstants.COMPLEX_MEM_MARGIN);
    } else {
        return new RectangleD(boundLeft, boundTop, boundRight - boundLeft, boundBottom - boundTop);
    }
}
Also used : RectangleD(org.ivis.util.RectangleD) LNode(org.ivis.layout.LNode)

Example 2 with LNode

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

the class GraphMLWriter method mapNodes.

/**
 * A recursive function for writing nodes of the specified LGraphManager
 * into the specified file
 *
 * @param root
 * @param level
 * @param parentStr
 */
private void mapNodes(LGraph root, short level, String parentStr) {
    String currNodeStr;
    LNode node;
    // for each node of the root graph...
    for (int i = 0; i < root.getNodes().size(); i++) {
        node = (LNode) root.getNodes().get(i);
        // check if the current root graph is the root graph of the LGraphManager
        if (level != 0)
            currNodeStr = parentStr + ":n" + i;
        else
            currNodeStr = "n" + i;
        // add new node to the node-string map
        this.map.put(node, currNodeStr);
        // then make a recursive call with current node's child graph
        if (node.getChild() != null) {
            this.mapNodes(node.getChild(), (short) (level + 1), currNodeStr);
        }
    }
}
Also used : LNode(org.ivis.layout.LNode)

Example 3 with LNode

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

the class CoSELayoutAlgorithmTask method createLEdge.

private LEdge createLEdge(final LayoutEdge layoutEdge, final CoSELayout cose, final Map<CyNode, LNode> lNodeMap, final Map<CyEdge, LEdge> lEdgeMap) {
    final LNode ln1 = lNodeMap.get(layoutEdge.getSource().getNode());
    final LNode ln2 = lNodeMap.get(layoutEdge.getTarget().getNode());
    if (ln1 != null && ln2 != null) {
        final VEdge ve = new VEdge(layoutEdge);
        final LEdge le = cose.getGraphManager().add(cose.newEdge(ve), ln1, ln2);
        lEdgeMap.put(layoutEdge.getEdge(), le);
        return le;
    }
    return null;
}
Also used : LEdge(org.ivis.layout.LEdge) LNode(org.ivis.layout.LNode)

Example 4 with LNode

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

the class GraphMLWriter method writeNodes.

/**
 * A recursive function that writes the nodes of the specified LGraphManager
 *
 * @param root
 * @param level
 * @param parentStr
 */
private void writeNodes(LGraph root, short level, String parentStr) {
    short currIndentation = (short) (this.INITIAL_INDENTATION + (level * 2));
    LNode node;
    LNode parent = root.getParent();
    int x, y;
    String currNodeStr;
    try {
        this.writeSpaces((short) (currIndentation - 2));
        if (level == 0)
            out.write("<graph id=\"\" edgedefault=\"undirected\">\n");
        else
            out.write("  <graph id=\"" + parentStr + ":\" edgedefault=\"undirected\">\n");
        for (int i = 0; i < root.getNodes().size(); i++) {
            node = (LNode) root.getNodes().get(i);
            // if it is the root graph
            if (parent == null) {
                x = (int) node.getRect().x;
                y = (int) node.getRect().y;
            } else {
                x = (int) (node.getRect().x - parent.getRect().x);
                y = (int) (node.getRect().y - parent.getRect().y);
            }
            // write the node data
            this.writeSpaces(currIndentation);
            out.write("<node id=\"");
            currNodeStr = (String) this.map.get(node);
            out.write(currNodeStr + "\">\n");
            this.writeSpaces((short) (currIndentation + 2));
            out.write("<data key=\"x\">" + x + "</data>\n");
            this.writeSpaces((short) (currIndentation + 2));
            out.write("<data key=\"y\">" + y + "</data>\n");
            this.writeSpaces((short) (currIndentation + 2));
            out.write("<data key=\"height\">" + (int) node.getRect().height + "</data>\n");
            this.writeSpaces((short) (currIndentation + 2));
            out.write("<data key=\"width\">" + (int) node.getRect().width + "</data>\n");
            this.writeToFile(NODE_DATA_1, (short) (currIndentation + 2));
            this.writeSpaces((short) (currIndentation + 2));
            out.write("<data key=\"text\">" + currNodeStr + "</data>\n");
            this.writeToFile(NODE_DATA_2, (short) (currIndentation + 2));
            // if current node is a compound, then make a recursive call
            if (node.getChild() != null) {
                this.writeNodes(node.getChild(), (short) (level + 1), currNodeStr);
            } else {
                this.writeSpaces((short) (currIndentation + 2));
                out.write("<data key=\"shape\">Rectangle</data>\n");
            }
            this.writeSpaces(currIndentation);
            out.write("</node>\n");
        }
        if (level != 0) {
            this.writeSpaces(currIndentation);
            out.write("<data key=\"margin\">10</data>\n");
            this.writeSpaces((short) (currIndentation - 2));
            out.write("</graph>\n");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : LNode(org.ivis.layout.LNode)

Example 5 with LNode

use of org.ivis.layout.LNode 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)

Aggregations

LNode (org.ivis.layout.LNode)7 CyNode (org.cytoscape.model.CyNode)2 LayoutNode (org.cytoscape.view.layout.LayoutNode)2 LEdge (org.ivis.layout.LEdge)2 LGraph (org.ivis.layout.LGraph)2 LGraphManager (org.ivis.layout.LGraphManager)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 ProgressListener (org.ivis.layout.ProgressListener)1 CoSELayout (org.ivis.layout.cose.CoSELayout)1 RectangleD (org.ivis.util.RectangleD)1