Java Code Examples for lecho.lib.hellocharts.model.Viewport#set()
The following examples show how to use
lecho.lib.hellocharts.model.Viewport#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractChartView.java From hellocharts-android with Apache License 2.0 | 6 votes |
private Viewport computeScrollViewport(float x, float y) { Viewport maxViewport = getMaximumViewport(); Viewport currentViewport = getCurrentViewport(); Viewport scrollViewport = new Viewport(currentViewport); if (maxViewport.contains(x, y)) { final float width = currentViewport.width(); final float height = currentViewport.height(); final float halfWidth = width / 2; final float halfHeight = height / 2; float left = x - halfWidth; float top = y + halfHeight; left = Math.max(maxViewport.left, Math.min(left, maxViewport.right - width)); top = Math.max(maxViewport.bottom + height, Math.min(top, maxViewport.top)); scrollViewport.set(left, top, left + width, top - height); } return scrollViewport; }
Example 2
Source File: AbstractChartView.java From hellocharts-android with Apache License 2.0 | 4 votes |
private Viewport computeZoomViewport(float x, float y, float zoomLevel) { final Viewport maxViewport = getMaximumViewport(); Viewport zoomViewport = new Viewport(getMaximumViewport()); if (maxViewport.contains(x, y)) { if (zoomLevel < 1) { zoomLevel = 1; } else if (zoomLevel > getMaxZoom()) { zoomLevel = getMaxZoom(); } final float newWidth = zoomViewport.width() / zoomLevel; final float newHeight = zoomViewport.height() / zoomLevel; final float halfWidth = newWidth / 2; final float halfHeight = newHeight / 2; float left = x - halfWidth; float right = x + halfWidth; float top = y + halfHeight; float bottom = y - halfHeight; if (left < maxViewport.left) { left = maxViewport.left; right = left + newWidth; } else if (right > maxViewport.right) { right = maxViewport.right; left = right - newWidth; } if (top > maxViewport.top) { top = maxViewport.top; bottom = top - newHeight; } else if (bottom < maxViewport.bottom) { bottom = maxViewport.bottom; top = bottom + newHeight; } ZoomType zoomType = getZoomType(); if (ZoomType.HORIZONTAL_AND_VERTICAL == zoomType) { zoomViewport.set(left, top, right, bottom); } else if (ZoomType.HORIZONTAL == zoomType) { zoomViewport.left = left; zoomViewport.right = right; } else if (ZoomType.VERTICAL == zoomType) { zoomViewport.top = top; zoomViewport.bottom = bottom; } } return zoomViewport; }