use of org.opennms.features.topology.api.BoundingBox in project opennms by OpenNMS.
the class MapViewPortTest method testGetBounds.
@Test
public void testGetBounds() {
DefaultMapViewManager viewManager = new DefaultMapViewManager();
viewManager.setMapBounds(new BoundingBox(0, 0, 8000, 4000));
viewManager.setViewPort(400, 300);
BoundingBox boundingBox = viewManager.getCurrentBoundingBox();
assertNotNull(boundingBox);
assertEquals(4000.0, boundingBox.getCenter().getX(), 0.001);
assertEquals(2000.0, boundingBox.getCenter().getY(), 0.001);
assertEquals(8000, boundingBox.getWidth());
assertEquals(6000, boundingBox.getHeight());
assertEquals(0, boundingBox.getX());
assertEquals(-1000, boundingBox.getY());
assertEquals(0.0, viewManager.getScale(), 0.0);
viewManager.setScale(1.0);
boundingBox = viewManager.getCurrentBoundingBox();
assertEquals(4000, boundingBox.getCenter().getX(), m_delta);
assertEquals(2000, boundingBox.getCenter().getY(), m_delta);
assertEquals(200, boundingBox.getWidth());
assertEquals(150, boundingBox.getHeight());
assertEquals(3900, boundingBox.getX());
assertEquals(1925, boundingBox.getY());
viewManager.setBoundingBox(new BoundingBox(0, 0, 1265, 600));
assertEquals(0.5, viewManager.getScale(), 0.0001);
}
use of org.opennms.features.topology.api.BoundingBox in project opennms by OpenNMS.
the class GridLayoutAlgorithmTest method calculateGrid.
void calculateGrid(int N, int width, int height, int expectedWidth, int expectedHeight) {
BoundingBox grid = GridLayoutAlgorithm.calculateGrid(N, width, height);
System.out.printf("Generated a grid of width: %d and height: %d for N: %d, w: %d and h: %d\n", grid.getWidth(), grid.getHeight(), N, width, height);
assertEquals(expectedWidth, grid.getWidth());
assertEquals(expectedHeight, grid.getHeight());
}
use of org.opennms.features.topology.api.BoundingBox in project opennms by OpenNMS.
the class GridLayoutAlgorithm method updateLayout.
/**
* Updates the current layout by extracting the containers graph and then perform a (x,y) transformation
* of all vertices.
*
* @param graph The container of the current graph. Contains all relevant information to perform the transformation
* of the {@link Graph} by changing its {@link Layout}
*/
@Override
public void updateLayout(Graph graph) {
final Layout graphLayout = graph.getLayout();
// Sort the vertices
final List<Vertex> sortedVertices = graph.getDisplayVertices().stream().sorted(new Comparator<Vertex>() {
@Override
public int compare(Vertex v1, Vertex v2) {
return ComparisonChain.start().compare(getIndex(v1), getIndex(v2)).compare(v1.getLabel(), v2.getLabel()).compare(v1.getId(), v2.getId()).result();
}
}).collect(Collectors.toList());
// Find the smallest rectangle (grid) that will fit all the vertices
// while attempting to preserve the aspect ration of the view port
final int numberOfVertices = sortedVertices.size();
final BoundingBox layoutBounds = graphLayout.computeBoundingBox(new ArrayList<>(sortedVertices));
final BoundingBox grid = calculateGrid(numberOfVertices, layoutBounds.getWidth(), layoutBounds.getHeight());
// Layout the (sorted) vertices in the grid
int k = 0;
for (int y = 0; y < grid.getHeight(); y++) {
for (int x = 0; x < grid.getWidth(); x++) {
if (k >= numberOfVertices) {
break;
}
graphLayout.setLocation(sortedVertices.get(k++), new Point(x * ELBOW_ROOM * 2, y * ELBOW_ROOM * 2));
}
}
}
use of org.opennms.features.topology.api.BoundingBox in project opennms by OpenNMS.
the class DefaultMapViewManager method getCurrentBoundingBox.
@Override
public BoundingBox getCurrentBoundingBox() {
if (m_viewPortWidth < 0 || m_mapBounds == null) {
//return m_mapBounds;
//throw new IllegalStateException("View port and maps bounds must be set");
}
BoundingBox mPrime = m_mapBounds.computeWithAspectRatio(getViewPortAspectRatio());
int width = (int) Math.round(Math.pow((double) mPrime.getWidth(), 1.0 - m_scale) * Math.pow((double) m_viewPortWidth / 2.0, m_scale));
int height = (int) Math.round(Math.pow((double) mPrime.getHeight(), 1.0 - m_scale) * Math.pow((double) m_viewPortHeight / 2.0, m_scale));
return new BoundingBox(m_center, width, height);
}
use of org.opennms.features.topology.api.BoundingBox in project opennms by OpenNMS.
the class DefaultMapViewManager method setMapBounds.
@Override
public void setMapBounds(BoundingBox boundingBox) {
// notifications, because the m_mapBounds equals the bounding box with aspect ratio
if (boundingBox.getWidth() < m_viewPortWidth && boundingBox.getHeight() < m_viewPortHeight) {
boundingBox = boundingBox.computeWithAspectRatio(getViewPortAspectRatio());
}
if (!m_mapBounds.equals(boundingBox)) {
if (boundingBox.getHeight() < m_viewPortHeight / 2) {
//Don't allow the height to be less than half the viewport height
m_mapBounds = new BoundingBox(boundingBox.getCenter(), boundingBox.getWidth(), m_viewPortHeight / 2);
} else {
m_mapBounds = boundingBox;
}
m_center = m_mapBounds.getCenter();
fireUpdate();
}
}
Aggregations