Search in sources :

Example 1 with XYChart

use of com.codename1.charts.views.XYChart in project CodenameOne by codenameone.

the class CombinedXYChart method getXYChart.

/**
 * Returns a chart instance based on the provided type.
 *
 * @param type the chart type
 * @return an instance of a chart implementation
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
private XYChart getXYChart(String type) throws IllegalAccessException, InstantiationException {
    XYChart chart = null;
    int length = xyChartTypes.length;
    for (int i = 0; i < length && chart == null; i++) {
        XYChart newChart = (XYChart) xyChartTypes[i].newInstance();
        if (type.equals(newChart.getChartType())) {
            chart = newChart;
        }
    }
    return chart;
}
Also used : Paint(com.codename1.charts.compat.Paint)

Example 2 with XYChart

use of com.codename1.charts.views.XYChart in project CodenameOne by codenameone.

the class ChartComponent method setPanLimits.

/**
 * Sets the pan limits if panning is enabled.
 * @param minX The minimum X-axis value for panning.
 * @param maxX The maximum X-axis value for panning.
 * @param minY The minimum Y-axis value for panning.
 * @param maxY The maximum Y-axis value for panning.
 */
public void setPanLimits(double minX, double maxX, double minY, double maxY) {
    if (chart instanceof XYChart) {
        XYChart xyChart = (XYChart) chart;
        XYMultipleSeriesRenderer r = xyChart.getRenderer();
        r.setPanLimits(new double[] { minX, maxX, minY, maxY });
    } else {
        throw new RuntimeException("setPanLimits() only supported for XYCharts");
    }
}
Also used : XYMultipleSeriesRenderer(com.codename1.charts.renderers.XYMultipleSeriesRenderer) XYChart(com.codename1.charts.views.XYChart)

Example 3 with XYChart

use of com.codename1.charts.views.XYChart in project CodenameOne by codenameone.

the class ChartComponent method setZoomLimits.

/**
 * Sets the zoom limits.
 *
 * <p><strong>NOTE: This method is only applicable when showing an {@link XYChart }</strong>  It will throw a
 * RuntimeException if called while a different kind of chart is being shown.</p>
 *
 * @param minRangeX The minimum distance from {@link XYMultipleSeriesRenderer#getXAxisMin() } to
 * {@link XYMultipleSeriesRenderer#getXAxisMax() } that can be achieved by zooming in.  {@literal 0} means no limit.
 * @param maxRangeX The maximum distance from {@link XYMultipleSeriesRenderer#getXAxisMin() } to
 * {@link XYMultipleSeriesRenderer#getXAxisMax() } that can be achieved by zooming out.  {@literal 0} means no limit.
 * @param minRangeY The minimum distance from {@link XYMultipleSeriesRenderer#getYAxisMin() } to
 * {@link XYMultipleSeriesRenderer#getYAxisMax() } that can be achieved by zooming in. {@literal 0} means no limit.
 * @param maxRangeY The maximum distance from {@link XYMultipleSeriesRenderer#getYAxisMin() } to
 * {@link XYMultipleSeriesRenderer#getYAxisMax() } that can be achieved by zooming out. {@literal 0} means no limit.
 */
public void setZoomLimits(double minRangeX, double maxRangeX, double minRangeY, double maxRangeY) {
    if (chart instanceof XYChart) {
        XYChart xyChart = (XYChart) chart;
        xyChart.getRenderer().setZoomLimits(new double[] { minRangeX, maxRangeX, minRangeY, maxRangeY });
    } else {
        throw new RuntimeException("setZoomLimits() only supported for XY charts");
    }
}
Also used : XYChart(com.codename1.charts.views.XYChart)

Example 4 with XYChart

use of com.codename1.charts.views.XYChart in project CodenameOne by codenameone.

the class ChartComponent method setZoomEnabled.

/**
 * Enables or disables zoom on both x and y axes.
 * @param zoomEnabled the zoomEnabled to set
 */
public void setZoomEnabled(boolean zoomEnabled) {
    this.zoomEnabled = zoomEnabled;
    setFocusable(isFocusable() || zoomEnabled);
    if (chart instanceof XYChart) {
        XYChart xyChart = (XYChart) chart;
        xyChart.getRenderer().setZoomEnabled(zoomEnabled, zoomEnabled);
    }
}
Also used : XYChart(com.codename1.charts.views.XYChart)

Example 5 with XYChart

use of com.codename1.charts.views.XYChart in project CodenameOne by codenameone.

the class ChartComponent method zoomTransition.

private void zoomTransition(double minX, double maxX, double minY, double maxY, int duration) {
    if (chart instanceof XYChart) {
        BBox currentViewPort = getBBox();
        BBox targetViewPort = getBBox(minX, maxX, minY, maxY, (int) currentViewPort.topLeft.getX(), (int) currentViewPort.topLeft.getY(), (int) currentViewPort.bottomRight.getX(), (int) currentViewPort.bottomRight.getY());
        ZoomTransitionXY zt = new ZoomTransitionXY(currentViewPort, targetViewPort, duration);
        animations.add(zt);
        if (animations.size() == 1) {
            zt.start();
        }
    } else {
        Shape currentViewPort = screenToChartShape(new Rectangle(getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight()));
        float[] currentRect = currentViewPort.getBounds2D();
        float[] newRect = new float[] { (float) minX, (float) (maxX - minX), (float) minY, (float) (maxY - minY) };
        float currentAspect = currentRect[2] / currentRect[3];
        float newAspect = newRect[3] / newRect[3];
        Rectangle newViewPort = new Rectangle((int) newRect[0], (int) newRect[1], (int) newRect[2], (int) newRect[3]);
        if (newAspect != currentAspect) {
            newViewPort.setHeight((int) (((double) newViewPort.getWidth()) / currentAspect));
            newRect = newViewPort.getBounds2D();
            newAspect = newRect[2] / newRect[3];
        }
        ZoomTransition zt = new ZoomTransition(currentViewPort.getBounds(), newViewPort, duration);
        animations.add(zt);
        if (animations.size() == 1) {
            zt.start();
        }
    }
}
Also used : Shape(com.codename1.ui.geom.Shape) Rectangle(com.codename1.ui.geom.Rectangle) XYChart(com.codename1.charts.views.XYChart)

Aggregations

XYChart (com.codename1.charts.views.XYChart)7 Paint (com.codename1.charts.compat.Paint)1 Point (com.codename1.charts.models.Point)1 XYMultipleSeriesRenderer (com.codename1.charts.renderers.XYMultipleSeriesRenderer)1 Rectangle (com.codename1.ui.geom.Rectangle)1 Shape (com.codename1.ui.geom.Shape)1