Search in sources :

Example 16 with Point

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

the class SavedHistory method getFragment.

public String getFragment() {
    final StringBuilder retval = new StringBuilder().append("(").append(m_szl).append("),").append(m_boundBox.fragment()).append(",").append(m_boundBox.getCenter());
    // Add a CRC of all of the key-value pairs in m_settings to make the fragment unique
    CRC32 settingsCrc = new CRC32();
    for (Map.Entry<String, String> entry : m_settings.entrySet()) {
        settingsCrc.update(entry.getKey().getBytes(StandardCharsets.UTF_8));
        settingsCrc.update(entry.getValue().getBytes(StandardCharsets.UTF_8));
    }
    retval.append(String.format(",(%X)", settingsCrc.getValue()));
    CRC32 locationsCrc = new CRC32();
    for (Map.Entry<VertexRef, Point> entry : m_locations.entrySet()) {
        locationsCrc.update(entry.getKey().getId().getBytes(StandardCharsets.UTF_8));
        // TODO cast to int for now
        locationsCrc.update((int) entry.getValue().getX());
        locationsCrc.update((int) entry.getValue().getY());
    }
    retval.append(String.format(",(%X)", locationsCrc.getValue()));
    CRC32 selectionsCrc = new CRC32();
    for (VertexRef entry : m_selectedVertices) {
        selectionsCrc.update(entry.getNamespace().getBytes(StandardCharsets.UTF_8));
        selectionsCrc.update(entry.getId().getBytes(StandardCharsets.UTF_8));
    }
    retval.append(String.format(",(%X)", selectionsCrc.getValue()));
    CRC32 focusCrc = new CRC32();
    for (VertexRef entry : m_focusVertices) {
        focusCrc.update(entry.getNamespace().getBytes(StandardCharsets.UTF_8));
        focusCrc.update(entry.getId().getBytes(StandardCharsets.UTF_8));
    }
    retval.append(String.format(",(%X)", focusCrc.getValue()));
    CRC32 historyCrc = new CRC32();
    for (SearchResult query : m_searchQueries) {
        historyCrc.update(query.toString().getBytes(StandardCharsets.UTF_8));
    }
    retval.append(String.format(",(%X)", historyCrc.getValue()));
    return retval.toString();
}
Also used : CRC32(java.util.zip.CRC32) SearchResult(org.opennms.features.topology.api.topo.SearchResult) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with Point

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

the class GridLayoutAlgorithm method updateLayout.

/**
 * Updates the current layout by extracting the containers graph and then perform a (x,y) transformation
 * 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(Graph graph) {
    final Layout graphLayout = graph.getLayout();
    // Sort the vertices
    final List<Vertex> sortedVertices = graph.getDisplayVertices().stream().sorted(new Comparator<Vertex>() {

        @Override
        public int compare(Vertex v1, Vertex v2) {
            return ComparisonChain.start().compare(getIndex(v1), getIndex(v2)).compare(v1.getLabel(), v2.getLabel()).compare(v1.getId(), v2.getId()).result();
        }
    }).collect(Collectors.toList());
    // Find the smallest rectangle (grid) that will fit all the vertices
    // while attempting to preserve the aspect ration of the view port
    final int numberOfVertices = sortedVertices.size();
    final BoundingBox layoutBounds = graphLayout.computeBoundingBox(new ArrayList<>(sortedVertices));
    final BoundingBox grid = calculateGrid(numberOfVertices, layoutBounds.getWidth(), layoutBounds.getHeight());
    // Layout the (sorted) vertices in the grid
    int k = 0;
    for (int y = 0; y < grid.getHeight(); y++) {
        for (int x = 0; x < grid.getWidth(); x++) {
            if (k >= numberOfVertices) {
                break;
            }
            graphLayout.setLocation(sortedVertices.get(k++), new Point(x * ELBOW_ROOM * 2, y * ELBOW_ROOM * 2));
        }
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) Layout(org.opennms.features.topology.api.Layout) BoundingBox(org.opennms.features.topology.api.BoundingBox) Point(org.opennms.features.topology.api.Point) Point(org.opennms.features.topology.api.Point) Comparator(java.util.Comparator)

Example 18 with Point

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

the class LayoutManager method isPersistedLayoutEqualToCurrentLayout.

public boolean isPersistedLayoutEqualToCurrentLayout(Graph graph) {
    LayoutEntity layoutEntity = loadLayout(graph);
    if (layoutEntity != null) {
        // If we have a layout persisted, we verify if it is equal.
        final Map<VertexRef, Point> persistedLocations = layoutEntity.getVertexPositions().stream().collect(Collectors.toMap((Function<VertexPositionEntity, VertexRef>) vertexPositionEntity -> {
            VertexRefEntity vertexRefEntity = vertexPositionEntity.getVertexRef();
            return new DefaultVertexRef(vertexRefEntity.getNamespace(), vertexRefEntity.getId());
        }, vertexPositionEntity -> {
            PointEntity position = vertexPositionEntity.getPosition();
            return new Point(position.getX(), position.getY());
        }));
        // The locations may contain elements currently not visible, we filter them
        final Map<VertexRef, Point> manualLocations = new HashMap<>();
        graph.getLayout().getLocations().forEach((key, value) -> {
            if (persistedLocations.containsKey(key)) {
                // layoutEntity stores int coordinates, but manualLocations are stored as double.
                // Convert to int to make it comparable.
                manualLocations.put(key, new Point((int) value.getX(), (int) value.getY()));
            }
        });
        final boolean layoutIsEqual = manualLocations.equals(persistedLocations);
        return layoutIsEqual;
    }
    // We don't have anything persisted, so they are not equal
    return false;
}
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) Function(java.util.function.Function) VertexRefEntity(org.opennms.netmgt.topology.persistence.api.VertexRefEntity) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) HashMap(java.util.HashMap) 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)

Example 19 with Point

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

the class FRLayoutTest method runFRLayout.

private TopoFRLayout<VertexRef, EdgeRef> runFRLayout(Graph g, Layout graphLayout, List<Vertex> vertices) {
    TopoFRLayout<VertexRef, EdgeRef> layout = new TopoFRLayout<>(createJungGraph(g));
    Dimension size = selectLayoutSize(m_graphContainer);
    // layout.setRepulsionMultiplier(3/8.0);
    // layout.setAttractionMultiplier(3/8.0);
    layout.setInitializer(initializer(graphLayout, size));
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    LOG.info("/******** FRLayout 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 FRLayout Run **********/");
    return layout;
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) 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)

Example 20 with Point

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

the class TopoFRLayoutAlgorithm 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());
    }
    TopoFRLayout<VertexRef, EdgeRef> layout = new TopoFRLayout<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) 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)

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