use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class VertexRefPointMapAdapter method unmarshal.
@Override
public Map<VertexRef, Point> unmarshal(VertexRefPointMapAdapter.VertexRefPointMap v) throws Exception {
if (v == null) {
return null;
} else {
Map<VertexRef, Point> retval = new HashMap<VertexRef, Point>();
for (VertexRefPointEntry entry : v.entry) {
VertexRef ref = new DefaultVertexRef(entry.key.namespace, entry.key.id, entry.key.label);
Point point = new Point(entry.value.x, entry.value.y);
retval.put(ref, point);
}
return retval;
}
}
use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class SavedHistory method saveLocations.
private static Map<VertexRef, Point> saveLocations(Graph graph) {
Collection<? extends Vertex> vertices = graph.getDisplayVertices();
Map<VertexRef, Point> locations = new HashMap<>();
for (Vertex vert : vertices) {
locations.put(vert, graph.getLayout().getLocation(vert));
}
return locations;
}
use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class ManualLayoutAlgorithmTest method verifyAppliesXAndYCoordinates.
/*
* This test verifies, that the vertex coordinates of x and y are applied to the
* layout, if they exist.
*/
@Test
public void verifyAppliesXAndYCoordinates() {
final ManualTest test = new ManualTest(new SimpleGraphBuilder("dummy").vertex("1").vX(0).vY(0).vertex("2").vX(1).vY(1).get());
final LayoutAlgorithm layoutAlgorithm = new ManualLayoutAlgorithm(test.layoutManager);
layoutAlgorithm.updateLayout(test.graph);
Assert.assertEquals(ImmutableMap.builder().put(new DefaultVertexRef("dummy", "1"), new Point(0, 0)).put(new DefaultVertexRef("dummy", "2"), new Point(1, 1)).build(), test.layout.getLocations());
}
use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class ManualLayoutAlgorithmTest method verifyDefaultsToGridLayout.
/*
* If no coordinates are defined for the vertex and there are no layout coordinates yet, verify that it falls
* back to the GridLayout.
*/
@Test
public void verifyDefaultsToGridLayout() {
final ManualTest test = new ManualTest(new SimpleGraphBuilder("dummy").vertex("1").vertex("2").get());
new ManualLayoutAlgorithm(test.layoutManager).updateLayout(test.graph);
Map<VertexRef, Point> manualLocations = test.layout.getLocations();
new GridLayoutAlgorithm().updateLayout(test.graph);
Assert.assertEquals(test.layout.getLocations(), manualLocations);
}
use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class ManualLayoutAlgorithm method updateLayout.
@Override
public void updateLayout(Graph graph) {
final LayoutEntity layoutEntity = layoutManager != null ? layoutManager.loadLayout(graph) : null;
if (layoutEntity != null) {
// if we have a persisted layout, we apply it ...
final Layout layout = graph.getLayout();
final Collection<Vertex> vertices = graph.getDisplayVertices();
for (Vertex vertex : vertices) {
PointEntity pointEntity = layoutEntity.getPosition(vertex.getNamespace(), vertex.getId());
layout.setLocation(vertex, new Point(pointEntity.getX(), pointEntity.getY()));
}
} else {
// otherwise we apply the manual layout ...
final Collection<Vertex> vertices = graph.getDisplayVertices();
final Layout layout = graph.getLayout();
final long notLayedOutCount = vertices.stream().filter(v -> {
Point location = layout.getLocation(v);
return location.getX() == 0 && location.getY() == 0;
}).count();
final long noVertexLocationCount = vertices.stream().filter(v -> {
boolean hasNoX = v.getX() == null || v.getX().intValue() == 0;
boolean hasNoY = v.getY() == null || v.getY().intValue() == 0;
return hasNoX && hasNoY;
}).count();
// manually apply the Grid Layout
if (notLayedOutCount == vertices.size() && noVertexLocationCount == vertices.size()) {
new GridLayoutAlgorithm().updateLayout(graph);
} else if (noVertexLocationCount != vertices.size()) {
// If we have at least one vertex with coordinates != (0,0), we apply them to the layout
for (Vertex vertex : vertices) {
layout.setLocation(vertex, new Point(vertex.getX(), vertex.getY()));
}
} else {
// This is only done when the user explicitly saves the layout
for (Vertex vertex : vertices) {
Point p = layout.getLocation(vertex);
layout.setLocation(vertex, p);
}
}
}
}
Aggregations