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