use of org.opennms.features.topology.api.Layout 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)));
}
}
use of org.opennms.features.topology.api.Layout in project opennms by OpenNMS.
the class RealUltimateLayoutAlgorithm method updateLayout.
@Override
public void updateLayout(Graph graph) {
final Layout graphLayout = graph.getLayout();
SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
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());
}
Dimension size = selectLayoutSize(graph);
Dimension paddedSize = new Dimension((int) (size.getWidth() * .75), (int) (size.getHeight() * .75));
doISOMLayout(graphLayout, jungGraph, size);
doSpringLayout(graphLayout, jungGraph, size, SPRING_LAYOUT_REPULSION);
doFRLayout(graphLayout, jungGraph, paddedSize, (int) (size.getWidth() / 8.0), (int) (size.getHeight() / 8.0));
doSpringLayout(graphLayout, jungGraph, size, SPRING_LAYOUT_REPULSION);
}
use of org.opennms.features.topology.api.Layout 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));
}
}
}
use of org.opennms.features.topology.api.Layout 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;
}
use of org.opennms.features.topology.api.Layout 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)));
}
}
Aggregations