Search in sources :

Example 11 with Layout

use of org.opennms.features.topology.api.Layout in project opennms by OpenNMS.

the class HierarchyLayoutAlgorithm method applyLayoutPositions.

private void applyLayoutPositions(final Collection<? extends Vertex> vertices, final HierarchyLayout<VertexRef, Edge> layout, final Layout graphLayout) {
    final List<VertexRef> displayVertices = vertices.stream().map(v -> (VertexRef) v).collect(Collectors.toList());
    layout.horizontalSqueeze(displayVertices);
    for (VertexRef v : displayVertices) {
        Point2D p = layout.transform(v);
        graphLayout.setLocation(v, new Point(p.getX(), p.getY()));
    }
}
Also used : Logger(org.slf4j.Logger) DirectedOrderedSparseMultigraph(edu.uci.ics.jung.graph.DirectedOrderedSparseMultigraph) Point2D(java.awt.geom.Point2D) Edge(org.opennms.features.topology.api.topo.Edge) Collection(java.util.Collection) Vertex(org.opennms.features.topology.api.topo.Vertex) LoggerFactory(org.slf4j.LoggerFactory) Graph(org.opennms.features.topology.api.Graph) Collectors(java.util.stream.Collectors) List(java.util.List) Point(org.opennms.features.topology.api.Point) Layout(org.opennms.features.topology.api.Layout) LevelAware(org.opennms.features.topology.api.topo.LevelAware) LayoutAlgorithm(org.opennms.features.topology.api.LayoutAlgorithm) Comparator(java.util.Comparator) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Point2D(java.awt.geom.Point2D) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 12 with Layout

use of org.opennms.features.topology.api.Layout 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 13 with Layout

use of org.opennms.features.topology.api.Layout 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 14 with Layout

use of org.opennms.features.topology.api.Layout 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)

Example 15 with Layout

use of org.opennms.features.topology.api.Layout in project opennms by OpenNMS.

the class HierarchyLayoutAlgorithm method updateLayout.

/**
 * Updates the current layout by extracting the containers graph and then perform a (x,y) tranformation
 * of all vertices.
 *
 * @param graph The container of the current graph. Contains all relevant information to perform the transformation
 *                       of the {@link Graph} by changing its {@link Layout}
 */
@Override
public void updateLayout(final Graph graph) {
    final Layout graphLayout = graph.getLayout();
    // fully level aware. See NMS-8703
    if (isFullyLevelAware(graph)) {
        final HierarchyLayout<VertexRef, Edge> treeLayout = createTreeLayout(graph);
        applyLayoutPositions(graph.getDisplayVertices(), treeLayout, graphLayout);
    } else {
        // SEE NMS-8703
        LOG.warn("The selected graph is not fully level aware. Cannot layout hierarchical. Falling back to D3 Layout");
        new D3TopoLayoutAlgorithm().updateLayout(graph);
    }
}
Also used : Layout(org.opennms.features.topology.api.Layout) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Aggregations

Layout (org.opennms.features.topology.api.Layout)15 Point (org.opennms.features.topology.api.Point)13 Vertex (org.opennms.features.topology.api.topo.Vertex)12 VertexRef (org.opennms.features.topology.api.topo.VertexRef)12 Edge (org.opennms.features.topology.api.topo.Edge)10 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)8 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)6 Dimension (java.awt.Dimension)4 Collection (java.util.Collection)4 Comparator (java.util.Comparator)4 Graph (org.opennms.features.topology.api.Graph)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 LayoutEntity (org.opennms.netmgt.topology.persistence.api.LayoutEntity)3 PointEntity (org.opennms.netmgt.topology.persistence.api.PointEntity)3 Hashing (com.google.common.hash.Hashing)2 FRLayout (edu.uci.ics.jung.algorithms.layout.FRLayout)2 SpringLayout (edu.uci.ics.jung.algorithms.layout.SpringLayout)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Date (java.util.Date)2