Search in sources :

Example 76 with VertexRef

use of org.opennms.features.topology.api.topo.VertexRef 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)

Example 77 with VertexRef

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

the class AlarmHopCriteria method createVertices.

private Set<VertexRef> createVertices(List<OnmsAlarm> alarms) {
    Set<VertexRef> vertices = new TreeSet<VertexRef>(new RefComparator());
    for (OnmsAlarm alarm : alarms) {
        OnmsNode node = alarm.getNode();
        if (node == null) {
            continue;
        }
        vertices.add(new DefaultVertexRef("nodes", String.valueOf(node.getId()), node.getLabel()));
    }
    return vertices;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) TreeSet(java.util.TreeSet) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) RefComparator(org.opennms.features.topology.api.topo.RefComparator)

Example 78 with VertexRef

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

the class HierarchyLayoutAlgorithm method applyLayoutPositions.

private void applyLayoutPositions(final Collection<? extends Vertex> vertices, final HierarchyLayout<VertexRef, Edge> layout, final Layout graphLayout) {
    final List<VertexRef> displayVertices = vertices.stream().map(v -> (VertexRef) v).collect(Collectors.toList());
    layout.horizontalSqueeze(displayVertices);
    for (VertexRef v : displayVertices) {
        Point2D p = layout.transform(v);
        graphLayout.setLocation(v, new Point(p.getX(), p.getY()));
    }
}
Also used : Logger(org.slf4j.Logger) DirectedOrderedSparseMultigraph(edu.uci.ics.jung.graph.DirectedOrderedSparseMultigraph) Point2D(java.awt.geom.Point2D) Edge(org.opennms.features.topology.api.topo.Edge) Collection(java.util.Collection) Vertex(org.opennms.features.topology.api.topo.Vertex) LoggerFactory(org.slf4j.LoggerFactory) Graph(org.opennms.features.topology.api.Graph) Collectors(java.util.stream.Collectors) List(java.util.List) Point(org.opennms.features.topology.api.Point) Layout(org.opennms.features.topology.api.Layout) LevelAware(org.opennms.features.topology.api.topo.LevelAware) LayoutAlgorithm(org.opennms.features.topology.api.LayoutAlgorithm) Comparator(java.util.Comparator) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Point2D(java.awt.geom.Point2D) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 79 with VertexRef

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

the class AddFocusVerticesOperation method execute.

@Override
public void execute(List<VertexRef> targets, final OperationContext operationContext) {
    if (targets == null || targets.isEmpty()) {
        return;
    }
    final GraphContainer graphContainer = operationContext.getGraphContainer();
    for (VertexRef target : targets) {
        graphContainer.addCriteria(new DefaultVertexHopCriteria(target));
    }
    graphContainer.redoLayout();
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) DefaultVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.DefaultVertexHopCriteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 80 with VertexRef

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

the class RemoveFocusOtherVerticesOperation method execute.

@Override
public void execute(List<VertexRef> targets, final OperationContext operationContext) {
    final GraphContainer graphContainer = operationContext.getGraphContainer();
    final Set<VertexHopCriteria> criteriaForGraphContainer = Criteria.getCriteriaForGraphContainer(graphContainer, VertexHopCriteria.class);
    boolean didRemoveCriteria = false;
    for (VertexHopCriteria eachCriteria : criteriaForGraphContainer) {
        boolean shouldRemove = true;
        for (VertexRef vertex : eachCriteria.getVertices()) {
            if (targets.contains(vertex)) {
                // The criteria references at least one of our targets, so
                // we shouldn't remove it
                shouldRemove = false;
                break;
            }
        }
        if (shouldRemove) {
            graphContainer.removeCriteria(eachCriteria);
            didRemoveCriteria = true;
        }
    }
    if (didRemoveCriteria) {
        // Only update the layout if any changes were made
        graphContainer.redoLayout();
    }
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) WrappedVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.WrappedVertexHopCriteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Aggregations

VertexRef (org.opennms.features.topology.api.topo.VertexRef)105 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)33 Vertex (org.opennms.features.topology.api.topo.Vertex)31 Point (org.opennms.features.topology.api.Point)23 Criteria (org.opennms.features.topology.api.topo.Criteria)22 Edge (org.opennms.features.topology.api.topo.Edge)22 Test (org.junit.Test)21 List (java.util.List)20 ArrayList (java.util.ArrayList)19 Collectors (java.util.stream.Collectors)18 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)18 Map (java.util.Map)17 Status (org.opennms.features.topology.api.topo.Status)15 Collection (java.util.Collection)13 HashSet (java.util.HashSet)13 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)12 HashMap (java.util.HashMap)12 Layout (org.opennms.features.topology.api.Layout)12 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)12 Lists (com.google.common.collect.Lists)11