use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class D3LayoutTest method runD3Layout.
private D3TopoLayout<VertexRef, EdgeRef> runD3Layout(int count, Graph g, Layout graphLayout, List<Vertex> vertices) throws IOException {
D3TopoLayout<VertexRef, EdgeRef> layout = new D3TopoLayout<>(createJungGraph(g));
Dimension size = selectLayoutSize(m_graphContainer);
layout.setInitializer(initializer(graphLayout, size));
layout.setSize(size);
try (PrintWriter out = new PrintWriter(new FileWriter("target/data" + count + ".js"))) {
out.println("var gCenter = { x: " + size.getWidth() / 2.0 + ", y: " + size.getHeight() / 2.0 + "};");
out.println("var data = [");
while (!layout.done()) {
out.println("[");
for (int i = 0; i < vertices.size(); i++) {
Vertex v = vertices.get(i);
if (i + 1 == vertices.size()) {
out.println("{ x:" + layout.getX(v) + ", y:" + layout.getY(v) + " }");
} else {
out.println("{ x:" + layout.getX(v) + ", y:" + layout.getY(v) + " },");
}
}
layout.step();
out.println("],");
}
out.println("];");
LOG.info("/******** D3Layout Run **********/");
}
for (Vertex v : vertices) {
graphLayout.setLocation(v, new Point(layout.getX(v) - size.getWidth() / 2.0, layout.getY(v) - size.getHeight() / 2.0));
LOG.info("layout.getX(): " + layout.getX(v) + " layout.getY(): " + layout.getY(v));
}
LOG.info("/******** End D3Layout Run **********/");
return layout;
}
use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class ManualLayoutAlgorithmTest method verifyLayoutCoordinatesHavePriority.
/*
* If persisted layout is defined, verify that it has priority.
*/
@Test
public void verifyLayoutCoordinatesHavePriority() {
final GraphProvider graphProvider = new SimpleGraphBuilder("dummy").vertex("vertex1").vX(1).vY(1).get();
final ManualTest test = new ManualTest(graphProvider);
final LayoutEntity persistedLayout = new LayoutEntity();
int x = 5;
int y = 5;
for (VertexRef eachVertex : graphProvider.getVertices()) {
VertexPositionEntity vertexPositionEntity = new VertexPositionEntity();
vertexPositionEntity.setVertexRef(LayoutManager.toVertexRefEntity(eachVertex));
vertexPositionEntity.setPosition(new PointEntity(x++, y++));
persistedLayout.addVertexPosition(vertexPositionEntity);
}
Mockito.when(test.layoutManager.loadLayout(test.graph)).thenReturn(persistedLayout);
new ManualLayoutAlgorithm(test.layoutManager).updateLayout(test.graph);
Assert.assertEquals(ImmutableMap.builder().put(new DefaultVertexRef("dummy", "vertex1"), new Point(5, 5)).build(), test.layout.getLocations());
}
use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class MapViewPortTest method testPanMap.
@Test
public void testPanMap() {
DefaultMapViewManager viewManager = new DefaultMapViewManager();
viewManager.setMapBounds(new BoundingBox(0, 0, 8000, 4000));
viewManager.setViewPort(400, 300);
BoundingBox box = viewManager.getCurrentBoundingBox();
assertNotNull(box);
assertEquals(4000, box.getCenter().getX(), m_delta);
assertEquals(2000, box.getCenter().getY(), m_delta);
assertEquals(8000, box.getWidth());
assertEquals(6000, box.getHeight());
assertEquals(0, box.getX());
assertEquals(-1000, box.getY());
viewManager.setCenter(new Point(3900, 1900));
box = viewManager.getCurrentBoundingBox();
assertNotNull(box);
assertEquals(3900, box.getCenter().getX(), m_delta);
assertEquals(1900, box.getCenter().getY(), m_delta);
assertEquals(8000, box.getWidth());
assertEquals(6000, box.getHeight());
assertEquals(-100, box.getX());
assertEquals(-1100, box.getY());
}
use of org.opennms.features.topology.api.Point 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.Point in project opennms by OpenNMS.
the class DefaultMapViewManager method zoomToPoint.
@Override
public void zoomToPoint(double scale, Point center) {
double oldScale = m_scale;
m_scale = scale;
m_scale = Math.min(1.0, m_scale);
m_scale = Math.max(0.0, m_scale);
m_scale = ((double) Math.round(m_scale * 10.0)) / 10.0;
Point oldCenter = m_center;
m_center = center;
// TODO: Sonar is warning on the equals comparison of m_scale and oldScale
if (m_scale != oldScale || !oldCenter.equals(m_center)) {
fireUpdate();
}
}
Aggregations