Search in sources :

Example 1 with CircleLayout

use of edu.uci.ics.jung.algorithms.layout.CircleLayout in project opennms by OpenNMS.

the class CircleLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(final Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, Edge> jungGraph = new SparseGraph<VertexRef, Edge>();
    Collection<? extends Vertex> vertices = graph.getDisplayVertices();
    for (VertexRef v : vertices) {
        jungGraph.addVertex(v);
    }
    for (Edge e : graph.getDisplayEdges()) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    CircleLayout<VertexRef, Edge> layout = new CircleLayout<VertexRef, Edge>(jungGraph);
    layout.setInitializer(initializer(graphLayout));
    layout.setSize(selectLayoutSize(graph));
    for (VertexRef v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
    }
}
Also used : SparseGraph(edu.uci.ics.jung.graph.SparseGraph) CircleLayout(edu.uci.ics.jung.algorithms.layout.CircleLayout) CircleLayout(edu.uci.ics.jung.algorithms.layout.CircleLayout) Layout(org.opennms.features.topology.api.Layout) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 2 with CircleLayout

use of edu.uci.ics.jung.algorithms.layout.CircleLayout in project titan.EclipsePlug-ins by eclipse.

the class ClusterTransformer method groupCluster.

/**
 * Calculate positions for one cluster
 *
 * @param vertices
 *            : the set of vertices inside the cluster
 */
protected void groupCluster(final Set<NodeDescriptor> vertices) {
    if (vertices.size() < mainLayout.getGraph().getVertexCount()) {
        final Point2D center = mainLayout.apply(vertices.iterator().next());
        final DirectedSparseGraph<NodeDescriptor, EdgeDescriptor> subGraph = new DirectedSparseGraph<NodeDescriptor, EdgeDescriptor>();
        for (final NodeDescriptor v : vertices) {
            subGraph.addVertex(v);
        }
        final Layout<NodeDescriptor, EdgeDescriptor> subLayout = new CircleLayout<NodeDescriptor, EdgeDescriptor>(subGraph);
        subLayout.setInitializer(mainLayout);
        // TODO Could we calculate the needed space for one cluster?
        final Dimension canvasSize = new Dimension(100, 100);
        subLayout.setSize(canvasSize);
        mainLayout.put(subLayout, center);
    }
}
Also used : CircleLayout(edu.uci.ics.jung.algorithms.layout.CircleLayout) Point2D(java.awt.geom.Point2D) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) Dimension(java.awt.Dimension) EdgeDescriptor(org.eclipse.titanium.graph.components.EdgeDescriptor) DirectedSparseGraph(edu.uci.ics.jung.graph.DirectedSparseGraph)

Aggregations

CircleLayout (edu.uci.ics.jung.algorithms.layout.CircleLayout)2 DirectedSparseGraph (edu.uci.ics.jung.graph.DirectedSparseGraph)1 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)1 Dimension (java.awt.Dimension)1 Point2D (java.awt.geom.Point2D)1 EdgeDescriptor (org.eclipse.titanium.graph.components.EdgeDescriptor)1 NodeDescriptor (org.eclipse.titanium.graph.components.NodeDescriptor)1 Layout (org.opennms.features.topology.api.Layout)1 Point (org.opennms.features.topology.api.Point)1 Edge (org.opennms.features.topology.api.topo.Edge)1 VertexRef (org.opennms.features.topology.api.topo.VertexRef)1