Search in sources :

Example 6 with Point

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

the class SimpleLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(Graph graph) {
    Layout layout = graph.getLayout();
    int r = 100;
    int cx = 500;
    int cy = 500;
    int i = 0;
    for (Vertex vertex : graph.getDisplayVertices()) {
        s_log.debug("Laying out vertex id : {}", vertex);
        if (i == 0) {
            layout.setLocation(vertex, new Point(cx, cy));
        } else {
            int n = i - 1;
            double a = (2 * Math.PI) / (graph.getDisplayVertices().size() - 1);
            int x = (int) (r * Math.cos(n * a) + cx);
            int y = (int) (r * Math.sin(n * a) + cy);
            layout.setLocation(vertex, new Point(x, y));
        }
        i++;
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) Layout(org.opennms.features.topology.api.Layout) Point(org.opennms.features.topology.api.Point) Point(org.opennms.features.topology.api.Point)

Example 7 with Point

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

the class LayoutManager method persistLayout.

public void persistLayout(GraphContainer graphContainer) {
    final List<VertexRef> vertexRefs = toVertexRef(graphContainer.getGraph().getDisplayVertices());
    final String id = calculateHash(vertexRefs);
    LayoutEntity layoutEntity = layoutDao.get(id);
    if (layoutEntity == null) {
        layoutEntity = new LayoutEntity();
        layoutEntity.setId(id);
        layoutEntity.setCreated(new Date());
        layoutEntity.setCreator(graphContainer.getApplicationContext().getUsername());
    }
    layoutEntity.setUpdated(new Date());
    layoutEntity.setUpdator(graphContainer.getApplicationContext().getUsername());
    final Layout layout = graphContainer.getGraph().getLayout();
    final List<VertexPositionEntity> vertexPositionEntities = vertexRefs.stream().map(vertexRef -> {
        final Point p = layout.getLocation(vertexRef);
        PointEntity pointEntity = new PointEntity();
        pointEntity.setX((int) p.getX());
        pointEntity.setY((int) p.getY());
        final VertexPositionEntity vertexEntity = new VertexPositionEntity();
        vertexEntity.setVertexRef(toVertexRefEntity(vertexRef));
        vertexEntity.setPosition(pointEntity);
        return vertexEntity;
    }).collect(Collectors.toList());
    layoutEntity.getVertexPositions().clear();
    for (VertexPositionEntity eachVertexPosition : vertexPositionEntities) {
        layoutEntity.addVertexPosition(eachVertexPosition);
    }
    layoutDao.saveOrUpdate(layoutEntity);
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) Date(java.util.Date) Vertex(org.opennms.features.topology.api.topo.Vertex) HashMap(java.util.HashMap) Hashing(com.google.common.hash.Hashing) Function(java.util.function.Function) VertexPositionEntity(org.opennms.netmgt.topology.persistence.api.VertexPositionEntity) Point(org.opennms.features.topology.api.Point) Layout(org.opennms.features.topology.api.Layout) Map(java.util.Map) LayoutDao(org.opennms.netmgt.topology.persistence.api.LayoutDao) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) Collection(java.util.Collection) Graph(org.opennms.features.topology.api.Graph) Collectors(java.util.stream.Collectors) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) TransactionAwareBeanProxyFactory(org.opennms.netmgt.vaadin.core.TransactionAwareBeanProxyFactory) List(java.util.List) VertexRefEntity(org.opennms.netmgt.topology.persistence.api.VertexRefEntity) TransactionOperations(org.springframework.transaction.support.TransactionOperations) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) Comparator(java.util.Comparator) VertexRef(org.opennms.features.topology.api.topo.VertexRef) VertexPositionEntity(org.opennms.netmgt.topology.persistence.api.VertexPositionEntity) Layout(org.opennms.features.topology.api.Layout) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) Point(org.opennms.features.topology.api.Point) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Date(java.util.Date)

Example 8 with Point

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

the class FRLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(final 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());
    }
    FRLayout<VertexRef, EdgeRef> layout = new FRLayout<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), (int) layout.getY(v) - (size.getHeight() / 2)));
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) 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) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) 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 Point

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

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

the class RealUltimateLayoutAlgorithm method doFRLayout.

private static void doFRLayout(final Layout graphLayout, SparseGraph<VertexRef, EdgeRef> jungGraph, Dimension size, final int xOffset, final int yOffset) {
    FRLayout<VertexRef, EdgeRef> layout = new FRLayout<VertexRef, EdgeRef>(jungGraph);
    layout.setInitializer(initializer(graphLayout, xOffset, yOffset));
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    for (VertexRef v : jungGraph.getVertices()) {
        graphLayout.setLocation(v, new Point(layout.getX(v) + xOffset, layout.getY(v) + yOffset));
    }
}
Also used : FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Aggregations

Point (org.opennms.features.topology.api.Point)34 VertexRef (org.opennms.features.topology.api.topo.VertexRef)23 Vertex (org.opennms.features.topology.api.topo.Vertex)15 Layout (org.opennms.features.topology.api.Layout)13 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)9 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)9 Edge (org.opennms.features.topology.api.topo.Edge)8 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)6 BoundingBox (org.opennms.features.topology.api.BoundingBox)6 Dimension (java.awt.Dimension)5 Collection (java.util.Collection)4 Comparator (java.util.Comparator)4 Graph (org.opennms.features.topology.api.Graph)4 LayoutEntity (org.opennms.netmgt.topology.persistence.api.LayoutEntity)4 PointEntity (org.opennms.netmgt.topology.persistence.api.PointEntity)4 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3