use of y.geom.YRectangle in project binnavi by google.
the class MoveFunctions method centerEdgeLable.
public static <EdgeType extends ZyGraphEdge<?, ?, ?>> void centerEdgeLable(final AbstractZyGraph<?, EdgeType> graph, final EdgeType edge) {
Preconditions.checkNotNull(edge, "Error: Edge can't be null.");
if (edge.isVisible()) {
final YRectangle box = edge.getRealizer().getLabel().getBox();
final double x = box.x + (box.width / 2);
final double y = box.y + (box.height / 2);
graph.getView().focusView(graph.getView().getZoom(), new Point2D.Double(x, y), graph.getSettings().getLayoutSettings().getAnimateLayout());
graph.updateViews();
} else {
throw new IllegalStateException("Error: Edge does not belong to graph.");
}
}
use of y.geom.YRectangle in project binnavi by google.
the class ZoomFunctions method zoomToEdgeLabel.
public static <EdgeType extends ZyGraphEdge<?, ?, ?>> void zoomToEdgeLabel(final AbstractZyGraph<?, EdgeType> graph, final EdgeType edge) {
final EdgeLabel label = edge.getRealizer().getLabel();
final YRectangle labelBounds = label.getBox();
final Rectangle viewBounds = graph.getView().getBounds();
final double widthZoom = viewBounds.getWidth() / labelBounds.getWidth();
final double heightZoom = viewBounds.getHeight() / labelBounds.getHeight();
final double oldZoom = graph.getView().getZoom();
graph.getView().setZoom(0.8 * Math.min(widthZoom, heightZoom));
ZoomHelpers.keepZoomValid(graph.getView());
final double newZoom = graph.getView().getZoom();
graph.getView().setZoom(oldZoom);
final Point2D newCenter = new Point2D.Double(labelBounds.getX() + (0.5 * labelBounds.getWidth()), labelBounds.getY() + (0.5 * labelBounds.getHeight()));
graph.getView().focusView(newZoom, newCenter, true);
graph.updateViews();
}
Aggregations