Search in sources :

Example 6 with SparseGraph

use of edu.uci.ics.jung.graph.SparseGraph in project opennms by OpenNMS.

the class SpringLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(final Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
    Collection<? extends Vertex> vertices = graph.getDisplayVertices();
    for (VertexRef v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<? extends Edge> edges = graph.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    SpringLayout<VertexRef, EdgeRef> layout = new SpringLayout<VertexRef, EdgeRef>(jungGraph);
    layout.setForceMultiplier(SPRING_FORCE_MULTIPLIER);
    layout.setRepulsionRange(SPRING_LAYOUT_REPULSION);
    layout.setInitializer(initializer(graphLayout));
    layout.setSize(selectLayoutSize(graph));
    int count = 0;
    while (!layout.done() && count < 700) {
        layout.step();
        count++;
    }
    for (VertexRef v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
    }
}
Also used : SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Layout(org.opennms.features.topology.api.Layout) SpringLayout(edu.uci.ics.jung.algorithms.layout.SpringLayout) SpringLayout(edu.uci.ics.jung.algorithms.layout.SpringLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge) Point(org.opennms.features.topology.api.Point)

Example 7 with SparseGraph

use of edu.uci.ics.jung.graph.SparseGraph in project opennms by OpenNMS.

the class ISOMLayoutAlgorithm method updateLayout.

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

Example 8 with SparseGraph

use of edu.uci.ics.jung.graph.SparseGraph in project opennms by OpenNMS.

the class D3LayoutTest method createJungGraph.

private SparseGraph<VertexRef, EdgeRef> createJungGraph(Graph g) {
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<>();
    Collection<Vertex> vertices = g.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<Edge> edges = g.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    return jungGraph;
}
Also used : SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Vertex(org.opennms.features.topology.api.topo.Vertex) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 9 with SparseGraph

use of edu.uci.ics.jung.graph.SparseGraph in project opennms by OpenNMS.

the class FRLayoutTest method createJungGraph.

private SparseGraph<VertexRef, EdgeRef> createJungGraph(Graph g) {
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<>();
    Collection<Vertex> vertices = g.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<Edge> edges = g.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    return jungGraph;
}
Also used : SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Vertex(org.opennms.features.topology.api.topo.Vertex) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 10 with SparseGraph

use of edu.uci.ics.jung.graph.SparseGraph in project opennms by OpenNMS.

the class D3TopoLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
    Collection<Vertex> vertices = graph.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<Edge> edges = graph.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    D3TopoLayout<VertexRef, EdgeRef> layout = new D3TopoLayout<VertexRef, EdgeRef>(jungGraph);
    // Initialize the vertex positions to the last known positions from the layout
    Dimension size = selectLayoutSize(graph);
    layout.setInitializer(initializer(graphLayout, (int) size.getWidth() / 2, (int) size.getHeight() / 2));
    // Resize the graph to accommodate the number of vertices
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    // Store the new positions in the layout
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v) - (size.getWidth() / 2), layout.getY(v) - (size.getHeight() / 2)));
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) Dimension(java.awt.Dimension) Point(org.opennms.features.topology.api.Point) SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Layout(org.opennms.features.topology.api.Layout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Aggregations

SparseGraph (edu.uci.ics.jung.graph.SparseGraph)10 Edge (org.opennms.features.topology.api.topo.Edge)10 VertexRef (org.opennms.features.topology.api.topo.VertexRef)10 Layout (org.opennms.features.topology.api.Layout)8 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)8 Vertex (org.opennms.features.topology.api.topo.Vertex)8 Point (org.opennms.features.topology.api.Point)7 Dimension (java.awt.Dimension)4 FRLayout (edu.uci.ics.jung.algorithms.layout.FRLayout)2 SpringLayout (edu.uci.ics.jung.algorithms.layout.SpringLayout)2 CircleLayout (edu.uci.ics.jung.algorithms.layout.CircleLayout)1 ISOMLayout (edu.uci.ics.jung.algorithms.layout.ISOMLayout)1 KKLayout (edu.uci.ics.jung.algorithms.layout.KKLayout)1 NonStupidISOMLayout (org.opennms.features.topology.app.internal.jung.ISOMLayoutAlgorithm.NonStupidISOMLayout)1