Search in sources :

Example 26 with Point

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

the class D3LayoutTest method runD3Layout.

private D3TopoLayout<VertexRef, EdgeRef> runD3Layout(int count, Graph g, Layout graphLayout, List<Vertex> vertices) throws IOException {
    D3TopoLayout<VertexRef, EdgeRef> layout = new D3TopoLayout<>(createJungGraph(g));
    Dimension size = selectLayoutSize(m_graphContainer);
    layout.setInitializer(initializer(graphLayout, size));
    layout.setSize(size);
    try (PrintWriter out = new PrintWriter(new FileWriter("target/data" + count + ".js"))) {
        out.println("var gCenter = { x: " + size.getWidth() / 2.0 + ", y: " + size.getHeight() / 2.0 + "};");
        out.println("var data = [");
        while (!layout.done()) {
            out.println("[");
            for (int i = 0; i < vertices.size(); i++) {
                Vertex v = vertices.get(i);
                if (i + 1 == vertices.size()) {
                    out.println("{ x:" + layout.getX(v) + ", y:" + layout.getY(v) + " }");
                } else {
                    out.println("{ x:" + layout.getX(v) + ", y:" + layout.getY(v) + " },");
                }
            }
            layout.step();
            out.println("],");
        }
        out.println("];");
        LOG.info("/******** D3Layout Run **********/");
    }
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v) - size.getWidth() / 2.0, layout.getY(v) - size.getHeight() / 2.0));
        LOG.info("layout.getX(): " + layout.getX(v) + " layout.getY(): " + layout.getY(v));
    }
    LOG.info("/******** End D3Layout Run **********/");
    return layout;
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) FileWriter(java.io.FileWriter) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Dimension(java.awt.Dimension) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Point(org.opennms.features.topology.api.Point) PrintWriter(java.io.PrintWriter)

Example 27 with Point

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

the class ManualLayoutAlgorithmTest method verifyLayoutCoordinatesHavePriority.

/*
     * If persisted layout is defined, verify that it has priority.
     */
@Test
public void verifyLayoutCoordinatesHavePriority() {
    final GraphProvider graphProvider = new SimpleGraphBuilder("dummy").vertex("vertex1").vX(1).vY(1).get();
    final ManualTest test = new ManualTest(graphProvider);
    final LayoutEntity persistedLayout = new LayoutEntity();
    int x = 5;
    int y = 5;
    for (VertexRef eachVertex : graphProvider.getVertices()) {
        VertexPositionEntity vertexPositionEntity = new VertexPositionEntity();
        vertexPositionEntity.setVertexRef(LayoutManager.toVertexRefEntity(eachVertex));
        vertexPositionEntity.setPosition(new PointEntity(x++, y++));
        persistedLayout.addVertexPosition(vertexPositionEntity);
    }
    Mockito.when(test.layoutManager.loadLayout(test.graph)).thenReturn(persistedLayout);
    new ManualLayoutAlgorithm(test.layoutManager).updateLayout(test.graph);
    Assert.assertEquals(ImmutableMap.builder().put(new DefaultVertexRef("dummy", "vertex1"), new Point(5, 5)).build(), test.layout.getLocations());
}
Also used : VertexPositionEntity(org.opennms.netmgt.topology.persistence.api.VertexPositionEntity) SimpleGraphBuilder(org.opennms.features.topology.api.support.SimpleGraphBuilder) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity) Point(org.opennms.features.topology.api.Point) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Point(org.opennms.features.topology.api.Point) Test(org.junit.Test)

Example 28 with Point

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

the class MapViewPortTest method testPanMap.

@Test
public void testPanMap() {
    DefaultMapViewManager viewManager = new DefaultMapViewManager();
    viewManager.setMapBounds(new BoundingBox(0, 0, 8000, 4000));
    viewManager.setViewPort(400, 300);
    BoundingBox box = viewManager.getCurrentBoundingBox();
    assertNotNull(box);
    assertEquals(4000, box.getCenter().getX(), m_delta);
    assertEquals(2000, box.getCenter().getY(), m_delta);
    assertEquals(8000, box.getWidth());
    assertEquals(6000, box.getHeight());
    assertEquals(0, box.getX());
    assertEquals(-1000, box.getY());
    viewManager.setCenter(new Point(3900, 1900));
    box = viewManager.getCurrentBoundingBox();
    assertNotNull(box);
    assertEquals(3900, box.getCenter().getX(), m_delta);
    assertEquals(1900, box.getCenter().getY(), m_delta);
    assertEquals(8000, box.getWidth());
    assertEquals(6000, box.getHeight());
    assertEquals(-100, box.getX());
    assertEquals(-1100, box.getY());
}
Also used : BoundingBox(org.opennms.features.topology.api.BoundingBox) Point(org.opennms.features.topology.api.Point) Test(org.junit.Test)

Example 29 with Point

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

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

the class DefaultMapViewManager method zoomToPoint.

@Override
public void zoomToPoint(double scale, Point center) {
    double oldScale = m_scale;
    m_scale = scale;
    m_scale = Math.min(1.0, m_scale);
    m_scale = Math.max(0.0, m_scale);
    m_scale = ((double) Math.round(m_scale * 10.0)) / 10.0;
    Point oldCenter = m_center;
    m_center = center;
    // TODO: Sonar is warning on the equals comparison of m_scale and oldScale
    if (m_scale != oldScale || !oldCenter.equals(m_center)) {
        fireUpdate();
    }
}
Also used : Point(org.opennms.features.topology.api.Point)

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