Search in sources :

Example 11 with Point

use of com.codename1.charts.models.Point in project CodenameOne by codenameone.

the class InteractionDialog method showPopupDialog.

/**
 * A popup dialog is shown with the context of a component and  its selection, it is disposed seamlessly if the back button is pressed
 * or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
 * dialog has the PopupDialog style by default.
 *
 * @param c the context component which is used to position the dialog and can also be pointed at
 */
public void showPopupDialog(Component c) {
    disposed = false;
    Rectangle componentPos = c.getSelectedRect();
    componentPos.setX(componentPos.getX() - c.getScrollX());
    componentPos.setY(componentPos.getY() - c.getScrollY());
    showPopupDialog(componentPos);
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle)

Example 12 with Point

use of com.codename1.charts.models.Point in project CodenameOne by codenameone.

the class CubicLineChart method drawPath.

@Override
protected void drawPath(Canvas canvas, List<Float> points, Paint paint, boolean circular) {
    GeneralPath p = new GeneralPath();
    float x = points.get(0);
    float y = points.get(1);
    p.moveTo(x, y);
    int length = points.size();
    if (circular) {
        length -= 4;
    }
    Point p1 = new Point();
    Point p2 = new Point();
    Point p3 = new Point();
    for (int i = 0; i < length; i += 2) {
        int nextIndex = i + 2 < length ? i + 2 : i;
        int nextNextIndex = i + 4 < length ? i + 4 : nextIndex;
        calc(points, p1, i, nextIndex, mSecondMultiplier);
        p2.setX(points.get(nextIndex));
        p2.setY(points.get(nextIndex + 1));
        calc(points, p3, nextIndex, nextNextIndex, mFirstMultiplier);
        // From last point, approaching x1/y1 and x2/y2 and ends up at x3/y3
        p.curveTo(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY());
    }
    mPathMeasure = new PathMeasure(p, false);
    if (circular) {
        for (int i = length; i < length + 4; i += 2) {
            p.lineTo(points.get(i), points.get(i + 1));
        }
        p.lineTo(points.get(0), points.get(1));
    }
    canvas.drawPath(p, paint);
}
Also used : GeneralPath(com.codename1.ui.geom.GeneralPath) PathMeasure(com.codename1.charts.compat.PathMeasure) Point(com.codename1.charts.models.Point) Point(com.codename1.charts.models.Point) Paint(com.codename1.charts.compat.Paint)

Example 13 with Point

use of com.codename1.charts.models.Point in project CodenameOne by codenameone.

the class ChartComponent method pointerReleased.

@Override
public void pointerReleased(int x, int y) {
    dragStart = null;
    zoomStartBBox = null;
    dragStartBBox = null;
    dragTransformStart = null;
    zoomStart = null;
    zoomDistStart = 0;
    zoomTransformStart = null;
    Point chartCoord = screenToChartCoord(x, y);
    SeriesSelection sel = chart.getSeriesAndPointForScreenCoordinate(chartCoord);
    if (sel == null) {
        super.pointerReleased(x, y);
        return;
    }
    seriesReleased(sel);
    // To change body of generated methods, choose Tools | Templates.
    super.pointerReleased(x, y);
}
Also used : SeriesSelection(com.codename1.charts.models.SeriesSelection) Point(com.codename1.charts.models.Point)

Example 14 with Point

use of com.codename1.charts.models.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 15 with Point

use of com.codename1.charts.models.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)

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