Search in sources :

Example 1 with Point

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

the class VertexRefPointMapAdapter method unmarshal.

@Override
public Map<VertexRef, Point> unmarshal(VertexRefPointMapAdapter.VertexRefPointMap v) throws Exception {
    if (v == null) {
        return null;
    } else {
        Map<VertexRef, Point> retval = new HashMap<VertexRef, Point>();
        for (VertexRefPointEntry entry : v.entry) {
            VertexRef ref = new DefaultVertexRef(entry.key.namespace, entry.key.id, entry.key.label);
            Point point = new Point(entry.value.x, entry.value.y);
            retval.put(ref, point);
        }
        return retval;
    }
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) HashMap(java.util.HashMap) Point(org.opennms.features.topology.api.Point) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 2 with Point

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

the class SavedHistory method saveLocations.

private static Map<VertexRef, Point> saveLocations(Graph graph) {
    Collection<? extends Vertex> vertices = graph.getDisplayVertices();
    Map<VertexRef, Point> locations = new HashMap<>();
    for (Vertex vert : vertices) {
        locations.put(vert, graph.getLayout().getLocation(vert));
    }
    return locations;
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) HashMap(java.util.HashMap) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 3 with Point

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

the class ManualLayoutAlgorithmTest method verifyAppliesXAndYCoordinates.

/*
     * This test verifies, that the vertex coordinates of x and y are applied to the
     * layout, if they exist.
     */
@Test
public void verifyAppliesXAndYCoordinates() {
    final ManualTest test = new ManualTest(new SimpleGraphBuilder("dummy").vertex("1").vX(0).vY(0).vertex("2").vX(1).vY(1).get());
    final LayoutAlgorithm layoutAlgorithm = new ManualLayoutAlgorithm(test.layoutManager);
    layoutAlgorithm.updateLayout(test.graph);
    Assert.assertEquals(ImmutableMap.builder().put(new DefaultVertexRef("dummy", "1"), new Point(0, 0)).put(new DefaultVertexRef("dummy", "2"), new Point(1, 1)).build(), test.layout.getLocations());
}
Also used : SimpleGraphBuilder(org.opennms.features.topology.api.support.SimpleGraphBuilder) GridLayoutAlgorithm(org.opennms.features.topology.app.internal.jung.GridLayoutAlgorithm) LayoutAlgorithm(org.opennms.features.topology.api.LayoutAlgorithm) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) Point(org.opennms.features.topology.api.Point) Test(org.junit.Test)

Example 4 with Point

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

the class ManualLayoutAlgorithmTest method verifyDefaultsToGridLayout.

/*
     * If no coordinates are defined for the vertex and there are no layout coordinates yet, verify that it falls
     * back to the GridLayout.
     */
@Test
public void verifyDefaultsToGridLayout() {
    final ManualTest test = new ManualTest(new SimpleGraphBuilder("dummy").vertex("1").vertex("2").get());
    new ManualLayoutAlgorithm(test.layoutManager).updateLayout(test.graph);
    Map<VertexRef, Point> manualLocations = test.layout.getLocations();
    new GridLayoutAlgorithm().updateLayout(test.graph);
    Assert.assertEquals(test.layout.getLocations(), manualLocations);
}
Also used : SimpleGraphBuilder(org.opennms.features.topology.api.support.SimpleGraphBuilder) Point(org.opennms.features.topology.api.Point) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) GridLayoutAlgorithm(org.opennms.features.topology.app.internal.jung.GridLayoutAlgorithm) Test(org.junit.Test)

Example 5 with Point

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

the class ManualLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(Graph graph) {
    final LayoutEntity layoutEntity = layoutManager != null ? layoutManager.loadLayout(graph) : null;
    if (layoutEntity != null) {
        // if we have a persisted layout, we apply it ...
        final Layout layout = graph.getLayout();
        final Collection<Vertex> vertices = graph.getDisplayVertices();
        for (Vertex vertex : vertices) {
            PointEntity pointEntity = layoutEntity.getPosition(vertex.getNamespace(), vertex.getId());
            layout.setLocation(vertex, new Point(pointEntity.getX(), pointEntity.getY()));
        }
    } else {
        // otherwise we apply the manual layout ...
        final Collection<Vertex> vertices = graph.getDisplayVertices();
        final Layout layout = graph.getLayout();
        final long notLayedOutCount = vertices.stream().filter(v -> {
            Point location = layout.getLocation(v);
            return location.getX() == 0 && location.getY() == 0;
        }).count();
        final long noVertexLocationCount = vertices.stream().filter(v -> {
            boolean hasNoX = v.getX() == null || v.getX().intValue() == 0;
            boolean hasNoY = v.getY() == null || v.getY().intValue() == 0;
            return hasNoX && hasNoY;
        }).count();
        // manually apply the Grid Layout
        if (notLayedOutCount == vertices.size() && noVertexLocationCount == vertices.size()) {
            new GridLayoutAlgorithm().updateLayout(graph);
        } else if (noVertexLocationCount != vertices.size()) {
            // If we have at least one vertex with coordinates != (0,0), we apply them to the layout
            for (Vertex vertex : vertices) {
                layout.setLocation(vertex, new Point(vertex.getX(), vertex.getY()));
            }
        } else {
            // This is only done when the user explicitly saves the layout
            for (Vertex vertex : vertices) {
                Point p = layout.getLocation(vertex);
                layout.setLocation(vertex, p);
            }
        }
    }
}
Also used : LayoutManager(org.opennms.features.topology.app.internal.support.LayoutManager) Point(org.opennms.features.topology.api.Point) GridLayoutAlgorithm(org.opennms.features.topology.app.internal.jung.GridLayoutAlgorithm) Layout(org.opennms.features.topology.api.Layout) Collection(java.util.Collection) Vertex(org.opennms.features.topology.api.topo.Vertex) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) Graph(org.opennms.features.topology.api.Graph) LayoutAlgorithm(org.opennms.features.topology.api.LayoutAlgorithm) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity) Vertex(org.opennms.features.topology.api.topo.Vertex) Layout(org.opennms.features.topology.api.Layout) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity) Point(org.opennms.features.topology.api.Point) GridLayoutAlgorithm(org.opennms.features.topology.app.internal.jung.GridLayoutAlgorithm)

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