Search in sources :

Example 1 with ZoomType

use of lecho.lib.hellocharts.gesture.ZoomType in project hellocharts-android by lecho.

the class AbstractChartView method computeZoomViewport.

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;
}
Also used : ZoomType(lecho.lib.hellocharts.gesture.ZoomType) Viewport(lecho.lib.hellocharts.model.Viewport)

Aggregations

ZoomType (lecho.lib.hellocharts.gesture.ZoomType)1 Viewport (lecho.lib.hellocharts.model.Viewport)1