Search in sources :

Example 11 with XYChart

use of org.achartengine.chart.XYChart in project sensorreadout by onyxbits.

the class Pan method apply.

/**
   * Apply the tool.
   * 
   * @param oldX the previous location on X axis
   * @param oldY the previous location on Y axis
   * @param newX the current location on X axis
   * @param newY the current location on the Y axis
   */
public void apply(float oldX, float oldY, float newX, float newY) {
    boolean notLimitedUp = true;
    boolean notLimitedBottom = true;
    boolean notLimitedLeft = true;
    boolean notLimitedRight = true;
    if (mChart instanceof XYChart) {
        int scales = mRenderer.getScalesCount();
        double[] limits = mRenderer.getPanLimits();
        boolean limited = limits != null && limits.length == 4;
        XYChart chart = (XYChart) mChart;
        for (int i = 0; i < scales; i++) {
            double[] range = getRange(i);
            double[] calcRange = chart.getCalcRange(i);
            if (limitsReachedX && limitsReachedY && (range[0] == range[1] && calcRange[0] == calcRange[1] || range[2] == range[3] && calcRange[2] == calcRange[3])) {
                return;
            }
            checkRange(range, i);
            double[] realPoint = chart.toRealPoint(oldX, oldY, i);
            double[] realPoint2 = chart.toRealPoint(newX, newY, i);
            double deltaX = realPoint[0] - realPoint2[0];
            double deltaY = realPoint[1] - realPoint2[1];
            double ratio = getAxisRatio(range);
            if (chart.isVertical(mRenderer)) {
                double newDeltaX = -deltaY * ratio;
                double newDeltaY = deltaX / ratio;
                deltaX = newDeltaX;
                deltaY = newDeltaY;
            }
            if (mRenderer.isPanXEnabled()) {
                if (limits != null) {
                    if (notLimitedLeft) {
                        notLimitedLeft = limits[0] <= range[0] + deltaX;
                    }
                    if (notLimitedRight) {
                        notLimitedRight = limits[1] >= range[1] + deltaX;
                    }
                }
                if (!limited || (notLimitedLeft && notLimitedRight)) {
                    setXRange(range[0] + deltaX, range[1] + deltaX, i);
                    limitsReachedX = false;
                } else {
                    limitsReachedX = true;
                }
            }
            if (mRenderer.isPanYEnabled()) {
                if (limits != null) {
                    if (notLimitedBottom) {
                        notLimitedBottom = limits[2] <= range[2] + deltaY;
                    }
                    if (notLimitedUp) {
                        notLimitedUp = limits[3] >= range[3] + deltaY;
                    }
                }
                if (!limited || (notLimitedBottom && notLimitedUp)) {
                    setYRange(range[2] + deltaY, range[3] + deltaY, i);
                    limitsReachedY = false;
                } else {
                    limitsReachedY = true;
                }
            }
        }
    } else {
        RoundChart chart = (RoundChart) mChart;
        chart.setCenterX(chart.getCenterX() + (int) (newX - oldX));
        chart.setCenterY(chart.getCenterY() + (int) (newY - oldY));
    }
    notifyPanListeners();
}
Also used : XYChart(org.achartengine.chart.XYChart) RoundChart(org.achartengine.chart.RoundChart)

Example 12 with XYChart

use of org.achartengine.chart.XYChart 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 13 with XYChart

use of org.achartengine.chart.XYChart in project sensorreadout by onyxbits.

the class ChartFactory method getCubicLineChartIntent.

/**
   * Creates a line chart intent that can be used to start the graphical view
   * activity.
   * 
   * @param context the context
   * @param dataset the multiple series dataset (cannot be null)
   * @param renderer the multiple series renderer (cannot be null)
   * @param activityTitle the graphical chart activity title. If this is null,
   *          then the title bar will be hidden. If a blank title is passed in,
   *          then the title bar will be the default. Pass in any other string
   *          to set a custom title.
   * @return a line chart intent
   * @throws IllegalArgumentException if dataset is null or renderer is null or
   *           if the dataset and the renderer don't include the same number of
   *           series
   */
public static final Intent getCubicLineChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, float smoothness, String activityTitle) {
    checkParameters(dataset, renderer);
    Intent intent = new Intent(context, GraphicalActivity.class);
    XYChart chart = new CubicLineChart(dataset, renderer, smoothness);
    intent.putExtra(CHART, chart);
    intent.putExtra(TITLE, activityTitle);
    return intent;
}
Also used : CubicLineChart(org.achartengine.chart.CubicLineChart) XYChart(org.achartengine.chart.XYChart) CombinedXYChart(org.achartengine.chart.CombinedXYChart) Intent(android.content.Intent)

Example 14 with XYChart

use of org.achartengine.chart.XYChart in project sensorreadout by onyxbits.

the class ChartFactory method getLineChartIntent.

/**
   * Creates a line chart intent that can be used to start the graphical view
   * activity.
   * 
   * @param context the context
   * @param dataset the multiple series dataset (cannot be null)
   * @param renderer the multiple series renderer (cannot be null)
   * @param activityTitle the graphical chart activity title. If this is null,
   *          then the title bar will be hidden. If a blank title is passed in,
   *          then the title bar will be the default. Pass in any other string
   *          to set a custom title.
   * @return a line chart intent
   * @throws IllegalArgumentException if dataset is null or renderer is null or
   *           if the dataset and the renderer don't include the same number of
   *           series
   */
public static final Intent getLineChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, String activityTitle) {
    checkParameters(dataset, renderer);
    Intent intent = new Intent(context, GraphicalActivity.class);
    XYChart chart = new LineChart(dataset, renderer);
    intent.putExtra(CHART, chart);
    intent.putExtra(TITLE, activityTitle);
    return intent;
}
Also used : XYChart(org.achartengine.chart.XYChart) CombinedXYChart(org.achartengine.chart.CombinedXYChart) Intent(android.content.Intent) LineChart(org.achartengine.chart.LineChart) CubicLineChart(org.achartengine.chart.CubicLineChart)

Example 15 with XYChart

use of org.achartengine.chart.XYChart in project sensorreadout by onyxbits.

the class ChartFactory method getRangeBarChartView.

/**
   * Creates a range bar chart view.
   * 
   * @param context the context
   * @param dataset the multiple series dataset (cannot be null)
   * @param renderer the multiple series renderer (cannot be null)
   * @param type the range bar chart type
   * @return a bar chart graphical view
   * @throws IllegalArgumentException if dataset is null or renderer is null or
   *           if the dataset and the renderer don't include the same number of
   *           series
   */
public static final GraphicalView getRangeBarChartView(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, Type type) {
    checkParameters(dataset, renderer);
    XYChart chart = new RangeBarChart(dataset, renderer, type);
    return new GraphicalView(context, chart);
}
Also used : RangeBarChart(org.achartengine.chart.RangeBarChart) XYChart(org.achartengine.chart.XYChart) CombinedXYChart(org.achartengine.chart.CombinedXYChart)

Aggregations

XYChart (org.achartengine.chart.XYChart)26 CombinedXYChart (org.achartengine.chart.CombinedXYChart)20 Intent (android.content.Intent)8 CubicLineChart (org.achartengine.chart.CubicLineChart)8 RoundChart (org.achartengine.chart.RoundChart)6 BubbleChart (org.achartengine.chart.BubbleChart)4 LineChart (org.achartengine.chart.LineChart)4 RangeBarChart (org.achartengine.chart.RangeBarChart)4 ScatterChart (org.achartengine.chart.ScatterChart)4 DefaultRenderer (org.achartengine.renderer.DefaultRenderer)4 BarChart (org.achartengine.chart.BarChart)2 XYSeries (org.achartengine.model.XYSeries)2