Search in sources :

Example 1 with DefaultRenderer

use of org.achartengine.renderer.DefaultRenderer in project Anki-Android by Ramblurr.

the class FitZoom method apply.

/**
   * Apply the tool.
   */
public void apply() {
    if (mChart instanceof XYChart) {
        if (((XYChart) mChart).getDataset() == null) {
            return;
        }
        int scales = mRenderer.getScalesCount();
        if (mRenderer.isInitialRangeSet()) {
            for (int i = 0; i < scales; i++) {
                if (mRenderer.isInitialRangeSet(i)) {
                    mRenderer.setRange(mRenderer.getInitialRange(i), i);
                }
            }
        } else {
            XYSeries[] series = ((XYChart) mChart).getDataset().getSeries();
            double[] range = null;
            int length = series.length;
            if (length > 0) {
                for (int i = 0; i < scales; i++) {
                    range = new double[] { MathHelper.NULL_VALUE, -MathHelper.NULL_VALUE, MathHelper.NULL_VALUE, -MathHelper.NULL_VALUE };
                    for (int j = 0; j < length; j++) {
                        if (i == series[j].getScaleNumber()) {
                            range[0] = Math.min(range[0], series[j].getMinX());
                            range[1] = Math.max(range[1], series[j].getMaxX());
                            range[2] = Math.min(range[2], series[j].getMinY());
                            range[3] = Math.max(range[3], series[j].getMaxY());
                        }
                    }
                    double marginX = Math.abs(range[1] - range[0]) / 40;
                    double marginY = Math.abs(range[3] - range[2]) / 40;
                    mRenderer.setRange(new double[] { range[0] - marginX, range[1] + marginX, range[2] - marginY, range[3] + marginY }, i);
                }
            }
        }
    } else {
        DefaultRenderer renderer = ((RoundChart) mChart).getRenderer();
        renderer.setScale(renderer.getOriginalScale());
    }
}
Also used : XYSeries(org.achartengine.model.XYSeries) DefaultRenderer(org.achartengine.renderer.DefaultRenderer) XYChart(org.achartengine.chart.XYChart) RoundChart(org.achartengine.chart.RoundChart)

Example 2 with DefaultRenderer

use of org.achartengine.renderer.DefaultRenderer in project sensorreadout by onyxbits.

the class FitZoom method apply.

/**
   * Apply the tool.
   */
public void apply() {
    if (mChart instanceof XYChart) {
        if (((XYChart) mChart).getDataset() == null) {
            return;
        }
        int scales = mRenderer.getScalesCount();
        if (mRenderer.isInitialRangeSet()) {
            for (int i = 0; i < scales; i++) {
                if (mRenderer.isInitialRangeSet(i)) {
                    mRenderer.setRange(mRenderer.getInitialRange(i), i);
                }
            }
        } else {
            XYSeries[] series = ((XYChart) mChart).getDataset().getSeries();
            double[] range = null;
            int length = series.length;
            if (length > 0) {
                for (int i = 0; i < scales; i++) {
                    range = new double[] { MathHelper.NULL_VALUE, -MathHelper.NULL_VALUE, MathHelper.NULL_VALUE, -MathHelper.NULL_VALUE };
                    for (int j = 0; j < length; j++) {
                        if (i == series[j].getScaleNumber()) {
                            range[0] = Math.min(range[0], series[j].getMinX());
                            range[1] = Math.max(range[1], series[j].getMaxX());
                            range[2] = Math.min(range[2], series[j].getMinY());
                            range[3] = Math.max(range[3], series[j].getMaxY());
                        }
                    }
                    double marginX = Math.abs(range[1] - range[0]) / 40;
                    double marginY = Math.abs(range[3] - range[2]) / 40;
                    mRenderer.setRange(new double[] { range[0] - marginX, range[1] + marginX, range[2] - marginY, range[3] + marginY }, i);
                }
            }
        }
    } else {
        DefaultRenderer renderer = ((RoundChart) mChart).getRenderer();
        renderer.setScale(renderer.getOriginalScale());
    }
}
Also used : XYSeries(org.achartengine.model.XYSeries) DefaultRenderer(org.achartengine.renderer.DefaultRenderer) XYChart(org.achartengine.chart.XYChart) RoundChart(org.achartengine.chart.RoundChart)

Example 3 with DefaultRenderer

use of org.achartengine.renderer.DefaultRenderer in project sensorreadout by onyxbits.

the class Zoom method apply.

/**
   * Apply the zoom.
   */
public void apply(int zoom_axis) {
    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();
            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];
            double newXMin = centerX - newWidth / 2;
            double newXMax = centerX + newWidth / 2;
            double newYMin = centerY - newHeight / 2;
            double newYMax = centerY + newHeight / 2;
            // if already reached last zoom, then it will always set to reached
            if (i == 0) {
                limitsReachedX = limits != null && (newXMin <= limits[0] || newXMax >= limits[1]);
                limitsReachedY = limits != null && (newYMin <= limits[2] || newYMax >= limits[3]);
            }
            if (mZoomIn) {
                if (mRenderer.isZoomXEnabled() && (zoom_axis == ZOOM_AXIS_X || zoom_axis == ZOOM_AXIS_XY)) {
                    if (limitsReachedX && mZoomRate < 1) {
                    // ignore pinch zoom out once reached X limit
                    } else {
                        newWidth /= mZoomRate;
                    }
                }
                if (mRenderer.isZoomYEnabled() && (zoom_axis == ZOOM_AXIS_Y || zoom_axis == ZOOM_AXIS_XY)) {
                    if (limitsReachedY && mZoomRate < 1) {
                    } else {
                        newHeight /= mZoomRate;
                    }
                }
            } else {
                if (mRenderer.isZoomXEnabled() && !limitsReachedX && (zoom_axis == ZOOM_AXIS_X || zoom_axis == ZOOM_AXIS_XY)) {
                    newWidth *= mZoomRate;
                }
                if (mRenderer.isZoomYEnabled() && !limitsReachedY && (zoom_axis == ZOOM_AXIS_Y || zoom_axis == ZOOM_AXIS_XY)) {
                    newHeight *= mZoomRate;
                }
            }
            double minX, minY;
            if (limits != null) {
                minX = Math.min(mRenderer.getZoomInLimitX(), limits[1] - limits[0]);
                minY = Math.min(mRenderer.getZoomInLimitY(), limits[3] - limits[2]);
            } else {
                minX = mRenderer.getZoomInLimitX();
                minY = mRenderer.getZoomInLimitY();
            }
            newWidth = Math.max(newWidth, minX);
            newHeight = Math.max(newHeight, minY);
            if (mRenderer.isZoomXEnabled() && (zoom_axis == ZOOM_AXIS_X || zoom_axis == ZOOM_AXIS_XY)) {
                newXMin = centerX - newWidth / 2;
                newXMax = centerX + newWidth / 2;
                setXRange(newXMin, newXMax, i);
            }
            if (mRenderer.isZoomYEnabled() && (zoom_axis == ZOOM_AXIS_Y || zoom_axis == ZOOM_AXIS_XY)) {
                newYMin = centerY - newHeight / 2;
                newYMax = centerY + newHeight / 2;
                setYRange(newYMin, newYMax, i);
            }
        }
    } 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)

Example 4 with DefaultRenderer

use of org.achartengine.renderer.DefaultRenderer 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)4 XYChart (org.achartengine.chart.XYChart)4 DefaultRenderer (org.achartengine.renderer.DefaultRenderer)4 XYSeries (org.achartengine.model.XYSeries)2