Search in sources :

Example 6 with RoundChart

use of org.achartengine.chart.RoundChart in project Anki-Android by Ramblurr.

the class Zoom method apply.

/**
   * Apply the zoom.
   */
public void apply() {
    if (mChart instanceof XYChart) {
        int scales = mRenderer.getScalesCount();
        for (int i = 0; i < scales; i++) {
            double[] range = getRange(i);
            checkRange(range, i);
            double[] limits = mRenderer.getZoomLimits();
            boolean limited = limits != null && limits.length == 4;
            double centerX = (range[0] + range[1]) / 2;
            double centerY = (range[2] + range[3]) / 2;
            double newWidth = range[1] - range[0];
            double newHeight = range[3] - range[2];
            if (mZoomIn) {
                if (mRenderer.isZoomXEnabled()) {
                    limitsReachedX = false;
                    newWidth /= mZoomRate;
                }
                if (mRenderer.isZoomYEnabled()) {
                    limitsReachedY = false;
                    newHeight /= mZoomRate;
                }
            } else {
                if (mRenderer.isZoomXEnabled()) {
                    if (limitsReachedX) {
                        newWidth *= mZoomRate;
                    }
                }
                if (mRenderer.isZoomYEnabled()) {
                    if (limitsReachedY) {
                        newHeight *= mZoomRate;
                    }
                }
            }
            if (mRenderer.isZoomXEnabled()) {
                double newXMin = centerX - newWidth / 2;
                double newXMax = centerX + newWidth / 2;
                if (!limited || limits[0] <= newXMin && limits[1] >= newXMax) {
                    setXRange(newXMin, newXMax, i);
                } else {
                    limitsReachedX = true;
                }
            }
            if (mRenderer.isZoomYEnabled()) {
                double newYMin = centerY - newHeight / 2;
                double newYMax = centerY + newHeight / 2;
                if (!limited || limits[2] <= newYMin && limits[3] >= newYMax) {
                    setYRange(newYMin, newYMax, i);
                } else {
                    limitsReachedY = true;
                }
            }
        }
    } else {
        DefaultRenderer renderer = ((RoundChart) mChart).getRenderer();
        if (mZoomIn) {
            renderer.setScale(renderer.getScale() * mZoomRate);
        } else {
            renderer.setScale(renderer.getScale() / mZoomRate);
        }
    }
    notifyZoomListeners(new ZoomEvent(mZoomIn, mZoomRate));
}
Also used : DefaultRenderer(org.achartengine.renderer.DefaultRenderer) XYChart(org.achartengine.chart.XYChart) RoundChart(org.achartengine.chart.RoundChart)

Aggregations

RoundChart (org.achartengine.chart.RoundChart)6 XYChart (org.achartengine.chart.XYChart)6 DefaultRenderer (org.achartengine.renderer.DefaultRenderer)4 XYSeries (org.achartengine.model.XYSeries)2