Search in sources :

Example 16 with Point

use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.

the class ChartComponent method getBBox.

private BBox getBBox(double minX, double maxX, double minY, double maxY, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY) {
    Point topLeft = new Point(topLeftX, topLeftY);
    Point bottomRight = new Point(bottomRightX, bottomRightY);
    if (bottomRight.getX() == topLeft.getX() || topLeft.getY() == bottomRight.getY()) {
        // If the we don't have height or width, forget about scaling
        return null;
    }
    double xScale = (bottomRight.getX() - topLeft.getX()) / (maxX - minX);
    double yScale = (bottomRight.getY() - topLeft.getY()) / (maxY - minY);
    BBox out = new BBox();
    out.topLeft = topLeft;
    out.bottomRight = bottomRight;
    out.minX = minX;
    out.maxX = maxX;
    out.minY = minY;
    out.maxY = maxY;
    out.scaleX = xScale;
    out.scaleY = yScale;
    return out;
}
Also used : Point(com.codename1.charts.models.Point)

Example 17 with Point

use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.

the class ChartComponent method screenToChartCoord.

/**
 * Converts screen coordinates to chart coordinates.
 * @param x screen x position
 * @param y screen y position
 * @return The chart coordinate corresponding to the given screen coordinate.
 */
public Point screenToChartCoord(int x, int y) {
    if (currentTransform != null) {
        Transform inverse = currentTransform.getInverse();
        float[] pt = inverse.transformPoint(new float[] { x, y, 0 });
        x = (int) pt[0];
        y = (int) pt[1];
    }
    return new Point(x - getAbsoluteX(), y - getAbsoluteY());
}
Also used : Point(com.codename1.charts.models.Point) Transform(com.codename1.ui.Transform)

Example 18 with Point

use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.

the class ChartComponent method pointerPressed.

@Override
public void pointerPressed(int x, int y) {
    Point chartCoord = screenToChartCoord(x, y);
    SeriesSelection sel = chart.getSeriesAndPointForScreenCoordinate(chartCoord);
    if (sel == null) {
        super.pointerPressed(x, y);
        return;
    }
    seriesPressed(sel);
    // To change body of generated methods, choose Tools | Templates.
    super.pointerPressed(x, y);
}
Also used : SeriesSelection(com.codename1.charts.models.SeriesSelection) Point(com.codename1.charts.models.Point)

Example 19 with Point

use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.

the class AbstractChart method drawPath.

/**
 * The graphical representation of a path.
 *
 * @param canvas the canvas to paint to
 * @param points the points that are contained in the path to paint
 * @param paint the paint to be used for painting
 * @param circular if the path ends with the start point
 */
protected void drawPath(Canvas canvas, List<Float> points, Paint paint, boolean circular) {
    GeneralPath path = new GeneralPath();
    int height = canvas.getHeight();
    int width = canvas.getWidth();
    float[] tempDrawPoints;
    if (points.size() < 4) {
        return;
    }
    tempDrawPoints = calculateDrawPoints(points.get(0), points.get(1), points.get(2), points.get(3), height, width);
    path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
    path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
    int length = points.size();
    for (int i = 4; i < length; i += 2) {
        if ((points.get(i - 1) < 0 && points.get(i + 1) < 0) || (points.get(i - 1) > height && points.get(i + 1) > height)) {
            continue;
        }
        tempDrawPoints = calculateDrawPoints(points.get(i - 2), points.get(i - 1), points.get(i), points.get(i + 1), height, width);
        if (!circular) {
            path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
        }
        path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
    }
    if (circular) {
        path.lineTo(points.get(0), points.get(1));
    }
    canvas.drawPath(path, paint);
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 20 with Point

use of com.codename1.ui.geom.Point in project CodenameOne by codenameone.

the class AbstractChart method drawPath.

/**
 * The graphical representation of a path.
 *
 * @param canvas the canvas to paint to
 * @param points the points that are contained in the path to paint
 * @param paint the paint to be used for painting
 * @param circular if the path ends with the start point
 */
protected void drawPath(Canvas canvas, float[] points, Paint paint, boolean circular) {
    GeneralPath path = new GeneralPath();
    int height = canvas.getHeight();
    int width = canvas.getWidth();
    float[] tempDrawPoints;
    if (points.length < 4) {
        return;
    }
    tempDrawPoints = calculateDrawPoints(points[0], points[1], points[2], points[3], height, width);
    path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
    path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
    int length = points.length;
    for (int i = 4; i < length; i += 2) {
        if ((points[i - 1] < 0 && points[i + 1] < 0) || (points[i - 1] > height && points[i + 1] > height)) {
            continue;
        }
        tempDrawPoints = calculateDrawPoints(points[i - 2], points[i - 1], points[i], points[i + 1], height, width);
        if (!circular) {
            path.moveTo(tempDrawPoints[0], tempDrawPoints[1]);
        }
        path.lineTo(tempDrawPoints[2], tempDrawPoints[3]);
    }
    if (circular) {
        path.lineTo(points[0], points[1]);
    }
    canvas.drawPath(path, paint);
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Aggregations

Point (com.codename1.ui.geom.Point)11 Point (com.codename1.charts.models.Point)10 Coord (com.codename1.maps.Coord)9 Paint (com.codename1.charts.compat.Paint)7 Component (com.codename1.ui.Component)5 TextArea (com.codename1.ui.TextArea)3 Dimension (com.codename1.ui.geom.Dimension)3 GeneralPath (com.codename1.ui.geom.GeneralPath)3 Rectangle (com.codename1.ui.geom.Rectangle)3 Border (com.codename1.ui.plaf.Border)3 ArrayList (java.util.ArrayList)3 SeriesSelection (com.codename1.charts.models.SeriesSelection)2 Container (com.codename1.ui.Container)2 EncodedImage (com.codename1.ui.EncodedImage)2 Form (com.codename1.ui.Form)2 Image (com.codename1.ui.Image)2 Label (com.codename1.ui.Label)2 ActionEvent (com.codename1.ui.events.ActionEvent)2 ActionListener (com.codename1.ui.events.ActionListener)2 Style (com.codename1.ui.plaf.Style)2