Search in sources :

Example 11 with Point

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

the class KKLayoutAlgorithm 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 (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());
    }
    KKLayout<VertexRef, Edge> layout = new KKLayout<VertexRef, Edge>(jungGraph);
    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) KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) 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 12 with Point

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

the class VertexRefPointMapAdapter method marshal.

@Override
public VertexRefPointMapAdapter.VertexRefPointMap marshal(Map<VertexRef, Point> v) throws Exception {
    if (v == null) {
        return null;
    } else {
        VertexRefPointMap retval = new VertexRefPointMap();
        for (VertexRef key : v.keySet()) {
            VertexRefPointEntry entry = new VertexRefPointEntry();
            VertexRefKey newKey = new VertexRefKey();
            newKey.namespace = key.getNamespace();
            newKey.id = key.getId();
            newKey.label = key.getLabel();
            Point value = v.get(key);
            PointValue newValue = new PointValue();
            // TODO cast to int for now
            newValue.x = (int) value.getX();
            // TODO cast to int for now
            newValue.y = (int) value.getY();
            entry.key = newKey;
            entry.value = newValue;
            retval.entry.add(entry);
        }
        return retval;
    }
}
Also used : Point(org.opennms.features.topology.api.Point) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 13 with Point

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

the class SavedHistoryTest method verifyCRCIncludesSearchResult.

/**
 * This methods tests whether the CRC checksums for {@link SavedHistory} object with {@link SearchResult}s are generated correctly,
 * namely that they now take into account the search results
 */
@Test
public void verifyCRCIncludesSearchResult() {
    Map<String, String> settings = new HashMap<String, String>();
    settings.put("hello", "world");
    VertexRef vert1 = new DefaultVertexRef("nodes", "1");
    VertexRef vert2 = new DefaultVertexRef("nodes", "2", "HasALabel");
    Map<VertexRef, Point> locations = new HashMap<VertexRef, Point>();
    locations.put(vert1, new Point(0, 0));
    locations.put(vert2, new Point(0, 0));
    // Creating SavedHistory object with no search results
    SavedHistory history1 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, Collections.emptyList());
    List<SearchResult> searchResults = new ArrayList<>();
    searchResults.add(new SearchResult("alarm", "alarmID", "someLabel", searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED));
    // Creating SavedHistory object with a single search result with ID = "alarmID"
    SavedHistory history2 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, searchResults);
    // Assertion that the SavedHistory with no search results is different from the one with one
    Assert.assertNotEquals(history1.getFragment(), history2.getFragment());
    // Creating another SavedHistory WITH search result, identical to the 2nd one
    SavedHistory history3 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, searchResults);
    // Assertion that two SavedHistory objects with the same search results are identical
    Assert.assertEquals(history2.getFragment(), history3.getFragment());
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) HashMap(java.util.HashMap) BoundingBox(org.opennms.features.topology.api.BoundingBox) ArrayList(java.util.ArrayList) SearchResult(org.opennms.features.topology.api.topo.SearchResult) Point(org.opennms.features.topology.api.Point) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Test(org.junit.Test)

Example 14 with Point

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

the class SavedHistoryTest method testMarshall.

@Test
public void testMarshall() {
    Map<String, String> settings = new HashMap<String, String>();
    settings.put("hello", "world");
    VertexRef vert1 = new DefaultVertexRef("nodes", "1");
    VertexRef vert2 = new DefaultVertexRef("nodes", "2", "HasALabel");
    Map<VertexRef, Point> locations = new HashMap<VertexRef, Point>();
    locations.put(vert1, new Point(0, 0));
    locations.put(vert2, new Point(0, 0));
    SavedHistory savedHistory = new SavedHistory(0, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, Collections.emptyList());
    System.out.print(JaxbUtils.marshal(savedHistory));
    // Specify a focus node
    savedHistory = new SavedHistory(0, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.singleton(vert1), settings, Collections.emptyList());
    System.out.print(JaxbUtils.marshal(savedHistory));
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) HashMap(java.util.HashMap) BoundingBox(org.opennms.features.topology.api.BoundingBox) Point(org.opennms.features.topology.api.Point) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Test(org.junit.Test)

Example 15 with Point

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

the class GraphPainter method visitVertex.

@Override
public void visitVertex(Vertex vertex) throws PaintException {
    boolean selected = isSelected(m_graphContainer.getSelectionManager(), vertex);
    Point initialLocation = m_layout.getInitialLocation(vertex);
    Point location = m_layout.getLocation(vertex);
    SharedVertex v = new SharedVertex();
    v.setKey(vertex.getKey());
    // TODO cast to int for now
    v.setInitialX((int) initialLocation.getX());
    v.setInitialY((int) initialLocation.getY());
    v.setX((int) location.getX());
    v.setY((int) location.getY());
    v.setSelected(selected);
    v.setStatus(getStatus(vertex));
    v.setStatusCount(getStatusCount(vertex));
    v.setSVGIconId(getIconId(vertex));
    v.setLabel(vertex.getLabel());
    v.setTooltipText(getTooltipText(vertex));
    v.setStyleName(getVertexStyle(vertex, selected));
    v.setTargets(getTargets(vertex));
    v.setEdgePathOffset(getEdgePathOffset(vertex));
    m_vertices.add(v);
}
Also used : SharedVertex(org.opennms.features.topology.app.internal.gwt.client.SharedVertex) 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