Search in sources :

Example 1 with MoveTo

use of javafx.scene.shape.MoveTo in project FXyzLib by Birdasaur.

the class Text3DHelper method generatePath.

private Path generatePath() {
    Path path = new Path(new MoveTo(list.get(0).x, list.get(0).y));
    list.stream().skip(1).forEach(p -> path.getElements().add(new LineTo(p.x, p.y)));
    path.getElements().add(new ClosePath());
    path.setStroke(Color.GREEN);
    // Path must be filled to allow Shape.intersect
    path.setFill(Color.RED);
    return path;
}
Also used : Path(javafx.scene.shape.Path) ClosePath(javafx.scene.shape.ClosePath) ClosePath(javafx.scene.shape.ClosePath) MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo)

Example 2 with MoveTo

use of javafx.scene.shape.MoveTo in project FXyzLib by Birdasaur.

the class Text3DHelper method getPoints.

private void getPoints(PathElement elem) {
    if (elem instanceof MoveTo) {
        list = new ArrayList<>();
        p0 = new Point3D((float) ((MoveTo) elem).getX(), (float) ((MoveTo) elem).getY(), 0f);
        list.add(p0);
    } else if (elem instanceof LineTo) {
        list.add(new Point3D((float) ((LineTo) elem).getX(), (float) ((LineTo) elem).getY(), 0f));
    } else if (elem instanceof CubicCurveTo) {
        Point3D ini = (list.size() > 0 ? list.get(list.size() - 1) : p0);
        IntStream.rangeClosed(1, POINTS_CURVE).forEach(i -> list.add(evalCubicBezier((CubicCurveTo) elem, ini, ((double) i) / POINTS_CURVE)));
    } else if (elem instanceof QuadCurveTo) {
        Point3D ini = (list.size() > 0 ? list.get(list.size() - 1) : p0);
        IntStream.rangeClosed(1, POINTS_CURVE).forEach(i -> list.add(evalQuadBezier((QuadCurveTo) elem, ini, ((double) i) / POINTS_CURVE)));
    } else if (elem instanceof ClosePath) {
        list.add(p0);
        // stored in a LineSegment: a continuous line that can change direction
        if (Math.abs(getArea()) > 0.001) {
            LineSegment line = new LineSegment(text);
            line.setHole(isHole());
            line.setPoints(list);
            line.setPath(generatePath());
            line.setOrigen(p0);
            polis.add(line);
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) Path(javafx.scene.shape.Path) QuadCurveTo(javafx.scene.shape.QuadCurveTo) Color(javafx.scene.paint.Color) ClosePath(javafx.scene.shape.ClosePath) CubicCurveTo(javafx.scene.shape.CubicCurveTo) LineTo(javafx.scene.shape.LineTo) Font(javafx.scene.text.Font) PathElement(javafx.scene.shape.PathElement) Rectangle(javafx.scene.shape.Rectangle) DoubleProperty(javafx.beans.property.DoubleProperty) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Text(javafx.scene.text.Text) List(java.util.List) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) MoveTo(javafx.scene.shape.MoveTo) Point2D(javafx.geometry.Point2D) Shape(javafx.scene.shape.Shape) Point3D(org.fxyz.geometry.Point3D) ClosePath(javafx.scene.shape.ClosePath) MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) QuadCurveTo(javafx.scene.shape.QuadCurveTo) Point3D(org.fxyz.geometry.Point3D) CubicCurveTo(javafx.scene.shape.CubicCurveTo)

Example 3 with MoveTo

use of javafx.scene.shape.MoveTo in project fxexperience2 by EricCanull.

the class SplineEditor method layoutPlotChildren.

@Override
protected void layoutPlotChildren() {
    double cp1x = getXAxis().getDisplayPosition(controlPoint1x.get());
    double cp1y = getYAxis().getDisplayPosition(controlPoint1y.get());
    double cp2x = getXAxis().getDisplayPosition(controlPoint2x.get());
    double cp2y = getYAxis().getDisplayPosition(controlPoint2y.get());
    double minx = getXAxis().getZeroPosition();
    double miny = getYAxis().getZeroPosition();
    double maxx = getXAxis().getDisplayPosition(1);
    double maxy = getYAxis().getDisplayPosition(1);
    controlPoint1Circle.setLayoutX(cp1x);
    controlPoint1Circle.setLayoutY(cp1y);
    controlPoint2Circle.setLayoutX(cp2x);
    controlPoint2Circle.setLayoutY(cp2y);
    cp1Line.setStartX(minx);
    cp1Line.setStartY(miny);
    cp1Line.setEndX(cp1x);
    cp1Line.setEndY(cp1y);
    cp2Line.setStartX(maxx);
    cp2Line.setStartY(maxy);
    cp2Line.setEndX(cp2x);
    cp2Line.setEndY(cp2y);
    dottedLinesPath.getElements().setAll(new MoveTo(minx - 0.5, cp1y - 0.5), new LineTo(cp1x - 0.5, cp1y - 0.5), new LineTo(cp1x - 0.5, miny - 0.5), new MoveTo(minx - 0.5, cp2y - 0.5), new LineTo(cp2x - 0.5, cp2y - 0.5), new LineTo(cp2x - 0.5, miny - 0.5));
    splinePath.getElements().setAll(new MoveTo(minx, miny), new CubicCurveTo(cp1x, cp1y, cp2x, cp2y, maxx, maxy));
}
Also used : MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) CubicCurveTo(javafx.scene.shape.CubicCurveTo)

Example 4 with MoveTo

use of javafx.scene.shape.MoveTo in project bitsquare by bitsquare.

the class CandleStickChart method layoutPlotChildren.

// -------------- METHODS ------------------------------------------------------------------------------------------
/**
     * Called to update and layout the content for the plot
     */
@Override
protected void layoutPlotChildren() {
    // we have nothing to layout if no data is present
    if (getData() == null) {
        return;
    }
    // update candle positions
    for (int seriesIndex = 0; seriesIndex < getData().size(); seriesIndex++) {
        XYChart.Series<Number, Number> series = getData().get(seriesIndex);
        Iterator<XYChart.Data<Number, Number>> iter = getDisplayedDataIterator(series);
        Path seriesPath = null;
        if (series.getNode() instanceof Path) {
            seriesPath = (Path) series.getNode();
            seriesPath.getElements().clear();
        }
        while (iter.hasNext()) {
            XYChart.Data<Number, Number> item = iter.next();
            double x = getXAxis().getDisplayPosition(getCurrentDisplayedXValue(item));
            double y = getYAxis().getDisplayPosition(getCurrentDisplayedYValue(item));
            Node itemNode = item.getNode();
            CandleData candleData = (CandleData) item.getExtraValue();
            if (itemNode instanceof Candle && candleData != null) {
                Candle candle = (Candle) itemNode;
                double close = getYAxis().getDisplayPosition(candleData.close);
                double high = getYAxis().getDisplayPosition(candleData.high);
                double low = getYAxis().getDisplayPosition(candleData.low);
                // calculate candle width
                double candleWidth = -1;
                if (getXAxis() instanceof NumberAxis) {
                    NumberAxis xa = (NumberAxis) getXAxis();
                    // use 90% width between ticks
                    candleWidth = xa.getDisplayPosition(xa.getTickUnit()) * 0.90;
                }
                // update candle
                candle.update(close - y, high - y, low - y, candleWidth);
                candle.updateTooltip(candleData);
                // position the candle
                candle.setLayoutX(x);
                candle.setLayoutY(y);
            }
            if (seriesPath != null && candleData != null) {
                final double displayPosition = getYAxis().getDisplayPosition(candleData.average);
                if (seriesPath.getElements().isEmpty())
                    seriesPath.getElements().add(new MoveTo(x, displayPosition));
                else
                    seriesPath.getElements().add(new LineTo(x, displayPosition));
            }
        }
    }
}
Also used : Path(javafx.scene.shape.Path) NumberAxis(javafx.scene.chart.NumberAxis) LineTo(javafx.scene.shape.LineTo) CandleData(io.bitsquare.gui.main.market.trades.charts.CandleData) Node(javafx.scene.Node) CandleData(io.bitsquare.gui.main.market.trades.charts.CandleData) MoveTo(javafx.scene.shape.MoveTo) XYChart(javafx.scene.chart.XYChart)

Aggregations

LineTo (javafx.scene.shape.LineTo)4 MoveTo (javafx.scene.shape.MoveTo)4 Path (javafx.scene.shape.Path)3 ClosePath (javafx.scene.shape.ClosePath)2 CubicCurveTo (javafx.scene.shape.CubicCurveTo)2 CandleData (io.bitsquare.gui.main.market.trades.charts.CandleData)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 DoubleProperty (javafx.beans.property.DoubleProperty)1 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)1 Point2D (javafx.geometry.Point2D)1 Node (javafx.scene.Node)1 NumberAxis (javafx.scene.chart.NumberAxis)1 XYChart (javafx.scene.chart.XYChart)1 Color (javafx.scene.paint.Color)1 PathElement (javafx.scene.shape.PathElement)1 QuadCurveTo (javafx.scene.shape.QuadCurveTo)1 Rectangle (javafx.scene.shape.Rectangle)1