Search in sources :

Example 1 with Container

use of org.vcell.util.graphlayout.ContainedGraph.Container in project vcell by virtualcell.

the class RandomLayouter method layout.

@Override
public void layout(ContainedGraph graph) {
    for (Node node : graph.getNodes()) {
        Container container = node.getContainer();
        node.setPos(container.getX() + random.nextDouble() * (container.getWidth() - node.getWidth()), container.getY() + random.nextDouble() * (container.getHeight() - node.getHeight()));
    }
    stretchLayouter.layout(graph);
}
Also used : Container(org.vcell.util.graphlayout.ContainedGraph.Container) Node(org.vcell.util.graphlayout.ContainedGraph.Node)

Example 2 with Container

use of org.vcell.util.graphlayout.ContainedGraph.Container in project vcell by virtualcell.

the class SimpleElipticalLayouter method layout.

// 
// 
// 
// protected static JungNode getOrAddInternalNode(ContainerContext cc, Node node) {
// JungNode glgNode = cc.getIntNodeMap().get(node);
// if(glgNode == null) {
// glgNode = new JungNode(node, false);	// internal
// cc.jungGraph.addVertex(glgNode);
// cc.intNodeMap.put(node, glgNode);
// double posX = node.getCenterX();
// double posY = node.getCenterY();
// cc.jungLayout.setLocation(glgNode, posX, posY);	// TODO: here
// }
// return glgNode;
// }
// 
// // inode - internal, already dealt with
// // enode - our external candidate
// protected static JungNode getOrAddExternalNode(ContainerContext cc, Node enode, Node inode) {
// JungNode glgNode = cc.getExtNodeMap().get(enode);
// if(glgNode == null) {
// glgNode = new JungNode(enode, true);	// external
// cc.jungGraph.addVertex(glgNode);
// cc.extNodeMap.put(enode, glgNode);
// double posX = enode.getCenterX() - inode.getCenterX();
// double posY = enode.getCenterY() - inode.getCenterY();
// cc.jungLayout.setLocation(glgNode, posX, posY);			// TODO: here
// cc.jungLayout.lock(glgNode, true);
// }
// return glgNode;
// }
// 
// protected static void getOrAddEdge(ContainerContext cc, Edge edge) {
// Node node1 = edge.getNode1();
// Node node2 = edge.getNode2();
// Container container = cc.getContainer();
// if(container.equals(node1.getContainer()) && container.equals(node2.getContainer())) {
// JungEdge jungEdge = cc.getEdgeMap().get(edge);
// if(jungEdge == null) {
// JungNode glgNode1 = getOrAddInternalNode(cc, node1);
// JungNode glgNode2 = getOrAddInternalNode(cc, node2);
// jungEdge = new JungEdge(edge);
// cc.jungGraph.addEdge(jungEdge, glgNode1, glgNode2);
// cc.edgeMap.put(edge, jungEdge);
// }
// } else if(container.equals(node1.getContainer())) {
// JungEdge jungEdge = cc.getEdgeMap().get(edge);
// if(jungEdge == null) {
// JungNode glgNode1 = getOrAddInternalNode(cc, node1);
// JungNode glgNodeExternal2 = getOrAddExternalNode(cc, node2, node1);
// jungEdge = new JungEdge(edge);
// cc.jungGraph.addEdge(jungEdge, glgNode1, glgNodeExternal2);
// cc.edgeMap.put(edge, jungEdge);
// }
// } else if(container.equals(node2.getContainer())) {
// JungEdge jungEdge = cc.getEdgeMap().get(edge);
// if(jungEdge == null) {
// JungNode glgNodeExternal1 = getOrAddExternalNode(cc, node1, node2);
// JungNode glgNode2 = getOrAddInternalNode(cc, node2);
// jungEdge = new JungEdge(edge);
// cc.jungGraph.addEdge(jungEdge, glgNode2, glgNodeExternal1);
// cc.edgeMap.put(edge, jungEdge);
// }
// }
// }
@Override
public void layout(ContainedGraph graph) {
    for (Container container : graph.getContainers()) {
        // ContainerContext containerContext = new ContainerContext(container);
        // int edgeCount = 0;
        // ContainerContext containerContext = new ContainerContext(container);
        // DirectedSparseMultigraph<String, Number> dag = new DirectedSparseMultigraph<>();
        // Collection<? extends Node> containerNodes = graph.getContainerNodes(container);
        // Map<String, Node> speciesNodesMap = new HashMap<>();
        // ReactionContainerShape rcs = (ReactionContainerShape)container.getObject();
        // Structure structure = rcs.getStructure();
        // for(Node node : containerNodes) {
        // if(node.object instanceof SpeciesContextShape) {
        // SpeciesContextShape scs = (SpeciesContextShape)node.object;
        // SpeciesContext sc = (SpeciesContext)(scs.getModelObject());
        // dag.addVertex(sc.getName());
        // speciesNodesMap.put(sc.getName(), node);
        // }
        // }
        // for(Node node : containerNodes) {
        // if(node.object instanceof ReactionStepShape) {
        // ReactionStepShape rss = (ReactionStepShape)node.object;
        // ReactionStep rs = (ReactionStep)(rss.getModelObject());
        // for(ReactionParticipant rp1 : rs.getReactionParticipants()) {
        // for(ReactionParticipant rp2 : rs.getReactionParticipants()) {
        // if(structure == rp1.getStructure() && structure == rp2.getStructure()) {
        // if(rp1 instanceof Reactant && rp2 instanceof Product) {		// edges from reactants to products
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // }
        // if(rp1 instanceof Catalyst && rp2 instanceof Reactant) {	// edges from catalysts to reactants
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // }
        // if(rp1 instanceof Reactant && rp2 instanceof Reactant && rp1 != rp2) {	// edges between reactants
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // dag.addEdge(edgeCount, rp2.getName(), rp1.getName());
        // edgeCount++;
        // }
        // if(rp1 instanceof Product && rp2 instanceof Product && rp1 != rp2) {	// edges between products
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // dag.addEdge(edgeCount, rp2.getName(), rp1.getName());
        // edgeCount++;
        // }
        // }
        // }
        // }
        // }
        // }
        // SpringLayout<String, Number> layout = new SpringLayout<String, Number>(dag);
        // layout.setSize(new Dimension((int)container.width,(int)container.height));
        // 
        // for(String v : dag.getVertices()) {
        // Node node = speciesNodesMap.get(v);
        // layout.setLocation(v, node.getCenterX(), node.getCenterY());
        // }
        // 
        // int step = 0;
        // while (!springIterate(layout) && step < 1000) {
        // step++;
        // }
        // 
        // // position the nodes on the new locations
        // for(String v : dag.getVertices()) {
        // Node node = speciesNodesMap.get(v);
        // double x = layout.getX(v);
        // double y = layout.getY(v);
        // node.setCenter(x, y);
        // }
        // 
        // // place all the reaction nodes in the center of mass of its reactants
        // for(Node node : containerNodes) {
        // if(node.object instanceof ReactionStepShape) {
        // int count = 0;
        // double x = 0;
        // double y = 0;
        // ReactionStepShape rss = (ReactionStepShape)node.object;
        // ReactionStep rs = (ReactionStep)(rss.getModelObject());
        // for(ReactionParticipant rp : rs.getReactionParticipants()) {
        // if(structure == rp.getStructure()) {
        // x += layout.getX(rp.getName());
        // y += layout.getY(rp.getName());
        // count++;
        // } else {		// reactant is in another structure
        // x += 5;		// just shift it a little
        // y += 5;
        // // TODO: make big correction as if it's far away to the left or to the right
        // // depending on the order of structures in the diagram
        // count++;
        // }
        // }
        // if(count > 0) {
        // node.setCenter(x/count, y/count);
        // }
        // }
        // }
        double centerX = container.getX() + container.getWidth() / 2;
        double centerY = container.getY() + container.getHeight() / 2;
        double quartaxisX = container.getWidth() / 3;
        double quartaxisY = container.getHeight() / 3;
        double semiaxisX = container.getWidth() / 2;
        double semiaxisY = container.getHeight() / 2;
        Collection<? extends Node> containerNodes = graph.getContainerNodes(container);
        int nNodes = containerNodes.size();
        int iNode = 0;
        for (Node node : containerNodes) {
            if (node.object instanceof SpeciesContextShape || node.object instanceof RuleParticipantSignatureDiagramShape) {
                double angle = 2 * Math.PI * (((double) iNode) / ((double) nNodes));
                node.setCenter(centerX + quartaxisX * Math.cos(angle), centerY + quartaxisY * Math.sin(angle));
            } else if (node.object instanceof ReactionStepShape || node.object instanceof ReactionRuleDiagramShape) {
                double angle = 2 * Math.PI * (((double) iNode) / ((double) nNodes));
                node.setCenter(centerX + semiaxisX * Math.cos(angle), centerY + semiaxisY * Math.sin(angle));
            }
            ++iNode;
        }
    }
    stretchLayouter.layout(graph);
}
Also used : Container(org.vcell.util.graphlayout.ContainedGraph.Container) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) Node(org.vcell.util.graphlayout.ContainedGraph.Node) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape)

Example 3 with Container

use of org.vcell.util.graphlayout.ContainedGraph.Container in project vcell by virtualcell.

the class GenericLogicGraphLayouter method layout.

@Override
public void layout(ContainedGraph graph) {
    // stop algorithm if it takes too long
    long TIMEOUT = 5000;
    long startTime = System.currentTimeMillis();
    for (int i = 0; i < 400; ++i) {
        long currentTime = System.currentTimeMillis();
        if (currentTime - startTime > TIMEOUT) {
            // exit if it takes too long
            break;
        }
        for (Container container : graph.getContainers()) {
            // size is set here
            ContainerContext containerContext = new ContainerContext(container);
            for (Node node : graph.getContainerNodes(container)) {
                getOrAddInternalNode(containerContext, node);
                for (Edge edge : graph.getNodeEdges(node)) {
                    getOrAddEdge(containerContext, edge);
                }
            }
            int count = 0;
            while (!containerContext.getGlgGraph().SpringIterate() && count < 10) {
                count++;
                ;
            }
            containerContext.getGlgGraph().Update();
            for (Node node : graph.getContainerNodes(container)) {
                Container nodeContainer = node.getContainer();
                if (nodeContainer.equals(container)) {
                    GlgGraphNode glgNode = containerContext.getIntNodeMap().get(node);
                    double x = containerContext.getGlgGraph().getLayout().getX(glgNode) + container.x;
                    double y = containerContext.getGlgGraph().getLayout().getY(glgNode) + container.y;
                    node.setCenter(x, y);
                }
            }
            stretchLayouter.layout(graph, container);
        }
    }
}
Also used : Container(org.vcell.util.graphlayout.ContainedGraph.Container) Node(org.vcell.util.graphlayout.ContainedGraph.Node) Edge(org.vcell.util.graphlayout.ContainedGraph.Edge)

Example 4 with Container

use of org.vcell.util.graphlayout.ContainedGraph.Container in project vcell by virtualcell.

the class VCellGraphToContainedGraphMapper method updateContainedGraphFromVCellGraph.

public void updateContainedGraphFromVCellGraph() {
    containedGraph.clear();
    for (Shape shape : vcellGraph.getShapes()) {
        GraphContainerLayout containerLayout = vcellGraph.getContainerLayout();
        if (containerLayout.isContainerForAutomaticLayout(shape)) {
            Rectangle boundary = containerLayout.getBoundaryForAutomaticLayout(shape);
            Container container = containedGraph.addContainer(shape, boundary.getX(), boundary.getY(), boundary.getWidth(), boundary.getHeight());
            for (Shape child : shape.getChildren()) {
                if (containerLayout.isNodeForAutomaticLayout(child)) {
                    Point absLoc = child.getSpaceManager().getAbsLoc();
                    Dimension size = child.getSpaceManager().getSize();
                    containedGraph.addNode(child, container, absLoc.getX(), absLoc.getY(), size.getWidth(), size.getHeight());
                }
            }
        }
    }
    for (Shape shape : vcellGraph.getShapes()) {
        if (shape instanceof EdgeShape) {
            EdgeShape edgeShape = (EdgeShape) shape;
            Node nodeStart = containedGraph.getNode(edgeShape.getStartShape());
            Node nodeEnd = containedGraph.getNode(edgeShape.getEndShape());
            if (nodeStart != null && nodeEnd != null) {
                containedGraph.addEdge(edgeShape, nodeStart, nodeEnd);
            }
        }
    }
}
Also used : Container(org.vcell.util.graphlayout.ContainedGraph.Container) Node(org.vcell.util.graphlayout.ContainedGraph.Node) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Dimension(java.awt.Dimension)

Example 5 with Container

use of org.vcell.util.graphlayout.ContainedGraph.Container in project vcell by virtualcell.

the class ExpandCanvasLayouter method layout.

@Override
public void layout(ContainedGraph graph) {
    for (Container container : graph.getContainers()) {
        container.setWidth(SCALE * container.getWidth());
        container.setHeight(SCALE * container.getHeight());
    }
    stretchLayouter.layout(graph);
}
Also used : Container(org.vcell.util.graphlayout.ContainedGraph.Container)

Aggregations

Container (org.vcell.util.graphlayout.ContainedGraph.Container)7 Node (org.vcell.util.graphlayout.ContainedGraph.Node)5 ReactionRuleDiagramShape (cbit.vcell.graph.ReactionRuleDiagramShape)1 ReactionStepShape (cbit.vcell.graph.ReactionStepShape)1 RuleParticipantSignatureDiagramShape (cbit.vcell.graph.RuleParticipantSignatureDiagramShape)1 SpeciesContextShape (cbit.vcell.graph.SpeciesContextShape)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 Edge (org.vcell.util.graphlayout.ContainedGraph.Edge)1