use of org.opennms.features.topology.api.Point 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.Point in project opennms by OpenNMS.
the class VertexRefPointMapAdapter method marshal.
@Override
public VertexRefPointMapAdapter.VertexRefPointMap marshal(Map<VertexRef, Point> v) throws Exception {
if (v == null) {
return null;
} else {
VertexRefPointMap retval = new VertexRefPointMap();
for (VertexRef key : v.keySet()) {
VertexRefPointEntry entry = new VertexRefPointEntry();
VertexRefKey newKey = new VertexRefKey();
newKey.namespace = key.getNamespace();
newKey.id = key.getId();
newKey.label = key.getLabel();
Point value = v.get(key);
PointValue newValue = new PointValue();
// TODO cast to int for now
newValue.x = (int) value.getX();
// TODO cast to int for now
newValue.y = (int) value.getY();
entry.key = newKey;
entry.value = newValue;
retval.entry.add(entry);
}
return retval;
}
}
use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class SavedHistoryTest method verifyCRCIncludesSearchResult.
/**
* This methods tests whether the CRC checksums for {@link SavedHistory} object with {@link SearchResult}s are generated correctly,
* namely that they now take into account the search results
*/
@Test
public void verifyCRCIncludesSearchResult() {
Map<String, String> settings = new HashMap<String, String>();
settings.put("hello", "world");
VertexRef vert1 = new DefaultVertexRef("nodes", "1");
VertexRef vert2 = new DefaultVertexRef("nodes", "2", "HasALabel");
Map<VertexRef, Point> locations = new HashMap<VertexRef, Point>();
locations.put(vert1, new Point(0, 0));
locations.put(vert2, new Point(0, 0));
// Creating SavedHistory object with no search results
SavedHistory history1 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, Collections.emptyList());
List<SearchResult> searchResults = new ArrayList<>();
searchResults.add(new SearchResult("alarm", "alarmID", "someLabel", searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED));
// Creating SavedHistory object with a single search result with ID = "alarmID"
SavedHistory history2 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, searchResults);
// Assertion that the SavedHistory with no search results is different from the one with one
Assert.assertNotEquals(history1.getFragment(), history2.getFragment());
// Creating another SavedHistory WITH search result, identical to the 2nd one
SavedHistory history3 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, searchResults);
// Assertion that two SavedHistory objects with the same search results are identical
Assert.assertEquals(history2.getFragment(), history3.getFragment());
}
use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class SavedHistoryTest method testMarshall.
@Test
public void testMarshall() {
Map<String, String> settings = new HashMap<String, String>();
settings.put("hello", "world");
VertexRef vert1 = new DefaultVertexRef("nodes", "1");
VertexRef vert2 = new DefaultVertexRef("nodes", "2", "HasALabel");
Map<VertexRef, Point> locations = new HashMap<VertexRef, Point>();
locations.put(vert1, new Point(0, 0));
locations.put(vert2, new Point(0, 0));
SavedHistory savedHistory = new SavedHistory(0, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, Collections.emptyList());
System.out.print(JaxbUtils.marshal(savedHistory));
// Specify a focus node
savedHistory = new SavedHistory(0, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.singleton(vert1), settings, Collections.emptyList());
System.out.print(JaxbUtils.marshal(savedHistory));
}
use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class GraphPainter method visitVertex.
@Override
public void visitVertex(Vertex vertex) throws PaintException {
boolean selected = isSelected(m_graphContainer.getSelectionManager(), vertex);
Point initialLocation = m_layout.getInitialLocation(vertex);
Point location = m_layout.getLocation(vertex);
SharedVertex v = new SharedVertex();
v.setKey(vertex.getKey());
// TODO cast to int for now
v.setInitialX((int) initialLocation.getX());
v.setInitialY((int) initialLocation.getY());
v.setX((int) location.getX());
v.setY((int) location.getY());
v.setSelected(selected);
v.setStatus(getStatus(vertex));
v.setStatusCount(getStatusCount(vertex));
v.setSVGIconId(getIconId(vertex));
v.setLabel(vertex.getLabel());
v.setTooltipText(getTooltipText(vertex));
v.setStyleName(getVertexStyle(vertex, selected));
v.setTargets(getTargets(vertex));
v.setEdgePathOffset(getEdgePathOffset(vertex));
m_vertices.add(v);
}
Aggregations