Search in sources :

Example 6 with XYChart

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

the class ChartFactory method getCubeLineChartView.

/**
   * Creates a cubic line chart view.
   * 
   * @param context the context
   * @param dataset the multiple series dataset (cannot be null)
   * @param renderer the multiple series renderer (cannot be null)
   * @return a line 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 getCubeLineChartView(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, float smoothness) {
    checkParameters(dataset, renderer);
    XYChart chart = new CubicLineChart(dataset, renderer, smoothness);
    return new GraphicalView(context, chart);
}
Also used : CubicLineChart(org.achartengine.chart.CubicLineChart) XYChart(org.achartengine.chart.XYChart) CombinedXYChart(org.achartengine.chart.CombinedXYChart)

Example 7 with XYChart

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

the class ChartFactory method getBubbleChartIntent.

/**
   * Creates a bubble 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
   * @return a scatter 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 getBubbleChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, String activityTitle) {
    checkParameters(dataset, renderer);
    Intent intent = new Intent(context, GraphicalActivity.class);
    XYChart chart = new BubbleChart(dataset, renderer);
    intent.putExtra(CHART, chart);
    intent.putExtra(TITLE, activityTitle);
    return intent;
}
Also used : BubbleChart(org.achartengine.chart.BubbleChart) XYChart(org.achartengine.chart.XYChart) CombinedXYChart(org.achartengine.chart.CombinedXYChart) Intent(android.content.Intent)

Example 8 with XYChart

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

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

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 (notLimitedBottom && limits != null) {
                    notLimitedBottom = limits[2] <= range[2] - deltaY;
                }
                if (notLimitedUp && limits != null) {
                    notLimitedUp = limits[3] >= range[3] - deltaY;
                }
                if (limited && (!notLimitedBottom && !notLimitedUp)) {
                    limitsReachedY = true;
                } else {
                    if (!notLimitedUp && deltaY < 0) {
                        setYRange(range[2] + deltaY, range[3] + deltaY, i);
                        notLimitedUp = true;
                    } else if (!notLimitedBottom && deltaY > 0) {
                        setYRange(range[2] + deltaY, range[3] + deltaY, i);
                        notLimitedBottom = true;
                    } else if (notLimitedBottom && notLimitedUp) {
                        setYRange(range[2] + deltaY, range[3] + deltaY, i);
                    }
                    limitsReachedY = false;
                }
            }
        }
    } 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 10 with XYChart

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

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