use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class SavedHistory method getFragment.
public String getFragment() {
final StringBuilder retval = new StringBuilder().append("(").append(m_szl).append("),").append(m_boundBox.fragment()).append(",").append(m_boundBox.getCenter());
// Add a CRC of all of the key-value pairs in m_settings to make the fragment unique
CRC32 settingsCrc = new CRC32();
for (Map.Entry<String, String> entry : m_settings.entrySet()) {
settingsCrc.update(entry.getKey().getBytes(StandardCharsets.UTF_8));
settingsCrc.update(entry.getValue().getBytes(StandardCharsets.UTF_8));
}
retval.append(String.format(",(%X)", settingsCrc.getValue()));
CRC32 locationsCrc = new CRC32();
for (Map.Entry<VertexRef, Point> entry : m_locations.entrySet()) {
locationsCrc.update(entry.getKey().getId().getBytes(StandardCharsets.UTF_8));
// TODO cast to int for now
locationsCrc.update((int) entry.getValue().getX());
locationsCrc.update((int) entry.getValue().getY());
}
retval.append(String.format(",(%X)", locationsCrc.getValue()));
CRC32 selectionsCrc = new CRC32();
for (VertexRef entry : m_selectedVertices) {
selectionsCrc.update(entry.getNamespace().getBytes(StandardCharsets.UTF_8));
selectionsCrc.update(entry.getId().getBytes(StandardCharsets.UTF_8));
}
retval.append(String.format(",(%X)", selectionsCrc.getValue()));
CRC32 focusCrc = new CRC32();
for (VertexRef entry : m_focusVertices) {
focusCrc.update(entry.getNamespace().getBytes(StandardCharsets.UTF_8));
focusCrc.update(entry.getId().getBytes(StandardCharsets.UTF_8));
}
retval.append(String.format(",(%X)", focusCrc.getValue()));
CRC32 historyCrc = new CRC32();
for (SearchResult query : m_searchQueries) {
historyCrc.update(query.toString().getBytes(StandardCharsets.UTF_8));
}
retval.append(String.format(",(%X)", historyCrc.getValue()));
return retval.toString();
}
use of org.opennms.features.topology.api.Point 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.Point in project opennms by OpenNMS.
the class LayoutManager method isPersistedLayoutEqualToCurrentLayout.
public boolean isPersistedLayoutEqualToCurrentLayout(Graph graph) {
LayoutEntity layoutEntity = loadLayout(graph);
if (layoutEntity != null) {
// If we have a layout persisted, we verify if it is equal.
final Map<VertexRef, Point> persistedLocations = layoutEntity.getVertexPositions().stream().collect(Collectors.toMap((Function<VertexPositionEntity, VertexRef>) vertexPositionEntity -> {
VertexRefEntity vertexRefEntity = vertexPositionEntity.getVertexRef();
return new DefaultVertexRef(vertexRefEntity.getNamespace(), vertexRefEntity.getId());
}, vertexPositionEntity -> {
PointEntity position = vertexPositionEntity.getPosition();
return new Point(position.getX(), position.getY());
}));
// The locations may contain elements currently not visible, we filter them
final Map<VertexRef, Point> manualLocations = new HashMap<>();
graph.getLayout().getLocations().forEach((key, value) -> {
if (persistedLocations.containsKey(key)) {
// layoutEntity stores int coordinates, but manualLocations are stored as double.
// Convert to int to make it comparable.
manualLocations.put(key, new Point((int) value.getX(), (int) value.getY()));
}
});
final boolean layoutIsEqual = manualLocations.equals(persistedLocations);
return layoutIsEqual;
}
// We don't have anything persisted, so they are not equal
return false;
}
use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class FRLayoutTest method runFRLayout.
private TopoFRLayout<VertexRef, EdgeRef> runFRLayout(Graph g, Layout graphLayout, List<Vertex> vertices) {
TopoFRLayout<VertexRef, EdgeRef> layout = new TopoFRLayout<>(createJungGraph(g));
Dimension size = selectLayoutSize(m_graphContainer);
// layout.setRepulsionMultiplier(3/8.0);
// layout.setAttractionMultiplier(3/8.0);
layout.setInitializer(initializer(graphLayout, size));
layout.setSize(size);
while (!layout.done()) {
layout.step();
}
LOG.info("/******** FRLayout 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 FRLayout Run **********/");
return layout;
}
use of org.opennms.features.topology.api.Point in project opennms by OpenNMS.
the class TopoFRLayoutAlgorithm method updateLayout.
@Override
public void updateLayout(final 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());
}
TopoFRLayout<VertexRef, EdgeRef> layout = new TopoFRLayout<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), (int) layout.getY(v) - (size.getHeight() / 2)));
}
}
Aggregations