use of org.opennms.features.topology.api.topo.Edge 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.Edge in project opennms by OpenNMS.
the class DefaultGraph method updateLayout.
private void updateLayout(Collection<Vertex> displayVertices, Collection<Edge> displayEdges) {
m_displayVertices.clear();
m_displayVertices.addAll(displayVertices);
m_displayEdges.clear();
m_displayEdges.addAll(displayEdges);
for (Iterator<Edge> itr = m_displayEdges.iterator(); itr.hasNext(); ) {
Edge edge = itr.next();
if (new RefComparator().compare(edge.getSource().getVertex(), edge.getTarget().getVertex()) == 0) {
LOG.debug("Discarding edge whose source and target are the same: {}", edge);
itr.remove();
} else if (m_displayVertices.contains(edge.getSource().getVertex())) {
if (m_displayVertices.contains(edge.getTarget().getVertex())) {
// This edge is OK, it is attached to two vertices that are in the graph
} else {
LOG.debug("Discarding edge that is not attached to 2 vertices in the graph: {}", edge);
itr.remove();
}
} else {
LOG.debug("Discarding edge that is not attached to 2 vertices in the graph: {}", edge);
itr.remove();
}
}
LOG.debug("Created a graph with {} vertices and {} edges", m_displayVertices.size(), m_displayEdges.size());
}
use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class DefaultGraph method visit.
@Override
public void visit(GraphVisitor visitor) throws Exception {
visitor.visitGraph(this);
for (Vertex v : m_displayVertices) {
visitor.visitVertex(v);
}
for (Edge e : m_displayEdges) {
visitor.visitEdge(e);
}
visitor.completeGraph(this);
}
use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class SpringLayoutAlgorithm method updateLayout.
@Override
public void updateLayout(final Graph graph) {
final Layout graphLayout = graph.getLayout();
SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
Collection<? extends Vertex> vertices = graph.getDisplayVertices();
for (VertexRef v : vertices) {
jungGraph.addVertex(v);
}
Collection<? extends Edge> edges = graph.getDisplayEdges();
for (Edge e : edges) {
jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
}
SpringLayout<VertexRef, EdgeRef> layout = new SpringLayout<VertexRef, EdgeRef>(jungGraph);
layout.setForceMultiplier(SPRING_FORCE_MULTIPLIER);
layout.setRepulsionRange(SPRING_LAYOUT_REPULSION);
layout.setInitializer(initializer(graphLayout));
layout.setSize(selectLayoutSize(graph));
int count = 0;
while (!layout.done() && count < 700) {
layout.step();
count++;
}
for (VertexRef v : vertices) {
graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
}
}
use of org.opennms.features.topology.api.topo.Edge in project opennms by OpenNMS.
the class ISOMLayoutAlgorithm method updateLayout.
@Override
public void updateLayout(final 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());
}
NonStupidISOMLayout layout = new NonStupidISOMLayout(jungGraph, graphLayout);
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)));
}
}
Aggregations