Search in sources :

Example 1 with Edge

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

the class EdgeTugLayouter method layout.

@Override
public void layout(ContainedGraph graph) {
    for (Node node : graph.getNodes()) {
        node.move(random.nextInt(3) - 1, random.nextInt(3) - 1);
        Collection<? extends Edge> nodeEdges = graph.getNodeEdges(node);
        for (Edge edge : nodeEdges) {
            Node node2 = edge.getNode1().equals(node) ? edge.getNode2() : edge.getNode1();
            node.move(Math.signum(node2.getCenterX() - node.getCenterX()), Math.signum(node2.getCenterY() - node.getCenterY()));
        }
        List<Node> closestNodes = new ArrayList<Node>();
        int closestNodesCount = nodeEdges.size();
        if (closestNodesCount > 0) {
            for (Node node2 : graph.getNodes()) {
                if (closestNodes.size() < closestNodesCount) {
                    closestNodes.add(node2);
                } else if (distanceSquared(node, node2) < distanceSquared(node, closestNodes.get(closestNodesCount - 1))) {
                    closestNodes.set(closestNodesCount - 1, node2);
                }
                for (int i = closestNodes.size() - 1; i > 0; --i) {
                    if (distanceSquared(node, closestNodes.get(i)) < distanceSquared(node, closestNodes.get(i - 1))) {
                        Collections.swap(closestNodes, i, i - 1);
                    } else {
                        break;
                    }
                }
            }
            for (Node closeNode : closestNodes) {
                node.move(Math.signum(node.getCenterX() - closeNode.getCenterX()), Math.signum(node.getCenterY() - closeNode.getCenterY()));
            }
        }
    }
    stretchLayouter.layout(graph);
}
Also used : Node(org.vcell.util.graphlayout.ContainedGraph.Node) ArrayList(java.util.ArrayList) Edge(org.vcell.util.graphlayout.ContainedGraph.Edge)

Example 2 with Edge

use of org.vcell.util.graphlayout.ContainedGraph.Edge 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)

Aggregations

Edge (org.vcell.util.graphlayout.ContainedGraph.Edge)2 Node (org.vcell.util.graphlayout.ContainedGraph.Node)2 ArrayList (java.util.ArrayList)1 Container (org.vcell.util.graphlayout.ContainedGraph.Container)1