Search in sources :

Example 1 with LevelAware

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

the class HierarchyLayoutAlgorithm method convert.

private edu.uci.ics.jung.graph.DirectedGraph<VertexRef, Edge> convert(final Graph g) {
    if (!isFullyLevelAware(g)) {
        throw new IllegalStateException("The graph is not LevelAware. Cannot apply Hierarchy Layout. Aborting");
    }
    // We need to sort the elements. For this purpose we use the DirectedOrderedSparseMultigraph
    final edu.uci.ics.jung.graph.DirectedGraph<VertexRef, Edge> jungGraph = new DirectedOrderedSparseMultigraph<>();
    final Collection<Vertex> displayVertices = g.getDisplayVertices();
    // Sort by level
    final List<Vertex> sortedVertices = displayVertices.stream().filter(v -> v instanceof LevelAware).sorted(new Comparator<Vertex>() {

        @Override
        public int compare(Vertex o1, Vertex o2) {
            return Integer.compare(((LevelAware) o1).getLevel(), ((LevelAware) o2).getLevel());
        }
    }).collect(Collectors.toList());
    // Build the graph
    for (VertexRef v : sortedVertices) {
        jungGraph.addVertex(v);
    }
    // The order of edges does not matter
    for (Edge e : g.getDisplayEdges()) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    return jungGraph;
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) DirectedOrderedSparseMultigraph(edu.uci.ics.jung.graph.DirectedOrderedSparseMultigraph) DirectedOrderedSparseMultigraph(edu.uci.ics.jung.graph.DirectedOrderedSparseMultigraph) Comparator(java.util.Comparator) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge) LevelAware(org.opennms.features.topology.api.topo.LevelAware)

Example 2 with LevelAware

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

the class HierarchyLayout method buildTree.

private void buildTree() {
    // we index the levels
    graph.getVertices().forEach(v -> {
        if (v instanceof LevelAware) {
            int level = ((LevelAware) v).getLevel();
            levelMap.put(v, level);
        } else {
            levelMap.put(v, 0);
        }
    });
    // now we calculate the vertex
    this.m_currentPoint = new Point(0, 20);
    if (graph != null) {
        for (V eachRoot : getRoots()) {
            if (eachRoot != null) {
                calculateDimensionX(eachRoot);
                m_currentPoint.x += this.basePositions.get(eachRoot) / 2 + this.distX;
                buildTree(eachRoot, this.m_currentPoint.x);
            }
        }
    }
}
Also used : Point(java.awt.Point) LevelAware(org.opennms.features.topology.api.topo.LevelAware) Point(java.awt.Point)

Aggregations

LevelAware (org.opennms.features.topology.api.topo.LevelAware)2 DirectedOrderedSparseMultigraph (edu.uci.ics.jung.graph.DirectedOrderedSparseMultigraph)1 Point (java.awt.Point)1 Comparator (java.util.Comparator)1 Edge (org.opennms.features.topology.api.topo.Edge)1 Vertex (org.opennms.features.topology.api.topo.Vertex)1 VertexRef (org.opennms.features.topology.api.topo.VertexRef)1