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;
}
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);
}
}
}
}
Aggregations