use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class D3TopoLayoutAlgorithm method updateLayout.
@Override
public void updateLayout(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());
}
D3TopoLayout<VertexRef, EdgeRef> layout = new D3TopoLayout<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), layout.getY(v) - (size.getHeight() / 2)));
}
}
use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class VEProviderGraphContainer method unselectElementsWhichAreNotVisibleAnymore.
// we have to find out if each selected vertex/edge is still displayable, if not we deselect it.
private static void unselectElementsWhichAreNotVisibleAnymore(Graph graph, SelectionManager selectionManager) {
if (selectionManager == null)
return;
List<VertexRef> selectedVertexRefs = new ArrayList<>(selectionManager.getSelectedVertexRefs());
List<VertexRef> newSelectedVertexRefs = new ArrayList<>();
for (VertexRef eachSelectedVertex : selectedVertexRefs) {
for (Vertex eachDisplayableVertex : graph.getDisplayVertices()) {
if (eachDisplayableVertex.getNamespace().equals(eachSelectedVertex.getNamespace()) && eachDisplayableVertex.getId().equals(eachSelectedVertex.getId())) {
newSelectedVertexRefs.add(eachSelectedVertex);
break;
}
}
}
List<EdgeRef> selectedEdgeRefs = new ArrayList<>(selectionManager.getSelectedEdgeRefs());
List<EdgeRef> newSelectedEdgeRefs = new ArrayList<>();
for (EdgeRef eachSelectedEdgeRef : selectedEdgeRefs) {
for (Edge eachDisplayableEdge : graph.getDisplayEdges()) {
if (eachDisplayableEdge.getNamespace().equals(eachSelectedEdgeRef.getNamespace()) && eachDisplayableEdge.getId().equals(eachSelectedEdgeRef.getId())) {
newSelectedEdgeRefs.add(eachSelectedEdgeRef);
break;
}
}
}
// if the selection changed, inform selectionManager
if (!newSelectedVertexRefs.equals(selectedVertexRefs)) {
selectionManager.setSelectedVertexRefs(newSelectedVertexRefs);
}
if (!newSelectedEdgeRefs.equals(selectedEdgeRefs)) {
selectionManager.setSelectedEdgeRefs(newSelectedEdgeRefs);
}
}
Aggregations