Search in sources :

Example 1 with Point

use of eu.hansolo.tilesfx.tools.Point in project tilesfx by HanSolo.

the class GaugeSparkLineTileSkin method smooth.

private void smooth(final List<Double> DATA_LIST) {
    int size = DATA_LIST.size();
    Point[] points = new Point[size];
    low = Statistics.getMin(DATA_LIST);
    high = Statistics.getMax(DATA_LIST);
    if (Helper.equals(low, high)) {
        low = minValue;
        high = maxValue;
    }
    range = high - low;
    double minX = graphBounds.getX();
    double maxX = minX + graphBounds.getWidth();
    double minY = graphBounds.getY();
    double maxY = minY + graphBounds.getHeight();
    double stepX = graphBounds.getWidth() / (noOfDatapoints - 1);
    double stepY = graphBounds.getHeight() / range;
    for (int i = 0; i < size; i++) {
        points[i] = new Point(minX + i * stepX, maxY - Math.abs(low - DATA_LIST.get(i)) * stepY);
    }
    Point[] smoothedPoints = Helper.subdividePoints(points, 16);
    int length = smoothedPoints.length;
    sparkLine.getElements().clear();
    sparkLine.getElements().add(new MoveTo(smoothedPoints[0].getX(), smoothedPoints[0].getY()));
    for (int i = 1; i < length - 1; i++) {
        sparkLine.getElements().add(new LineTo(smoothedPoints[i].getX(), smoothedPoints[i].getY()));
    }
    dot.setCenterX(smoothedPoints[length - 1].getX());
    dot.setCenterY(smoothedPoints[length - 1].getY());
}
Also used : MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) Point(eu.hansolo.tilesfx.tools.Point) CacheHint(javafx.scene.CacheHint) Point(eu.hansolo.tilesfx.tools.Point)

Example 2 with Point

use of eu.hansolo.tilesfx.tools.Point in project tilesfx by HanSolo.

the class SmoothAreaChartTileSkin method handleData.

private void handleData() {
    selectorTooltip.hide();
    selector.setVisible(false);
    List<ChartData> data = tile.getChartData();
    if (null == data || data.isEmpty()) {
        return;
    }
    Optional<ChartData> lastDataEntry = data.stream().reduce((first, second) -> second);
    if (lastDataEntry.isPresent()) {
        valueText.setText(String.format(locale, formatString, lastDataEntry.get().getValue()));
        tile.setValue(lastDataEntry.get().getValue());
        resizeDynamicText();
    }
    dataSize = data.size();
    maxValue = data.stream().max(Comparator.comparing(c -> c.getValue())).get().getValue();
    hStepSize = width / (dataSize - 1);
    vStepSize = (height * 0.5) / maxValue;
    points.clear();
    for (int i = 0; i < dataSize; i++) {
        points.add(new Point((i) * hStepSize, height - data.get(i).getValue() * vStepSize));
    }
    drawChart(points);
}
Also used : ChartData(eu.hansolo.tilesfx.chart.ChartData) Point(eu.hansolo.tilesfx.tools.Point) Point(eu.hansolo.tilesfx.tools.Point)

Example 3 with Point

use of eu.hansolo.tilesfx.tools.Point in project tilesfx by HanSolo.

the class SmoothAreaChartTileSkin method drawChart.

private void drawChart(final List<Point> POINTS) {
    if (POINTS.isEmpty())
        return;
    Point[] points = smoothing ? Helper.subdividePoints(POINTS.toArray(new Point[0]), 8) : POINTS.toArray(new Point[0]);
    fillPath.getElements().clear();
    fillPath.getElements().add(new MoveTo(0, height));
    strokePath.getElements().clear();
    strokePath.getElements().add(new MoveTo(points[0].getX(), points[0].getY()));
    for (Point p : points) {
        fillPath.getElements().add(new LineTo(p.getX(), p.getY()));
        strokePath.getElements().add(new LineTo(p.getX(), p.getY()));
    }
    fillPath.getElements().add(new LineTo(width, height));
    fillPath.getElements().add(new LineTo(0, height));
    fillPath.getElements().add(new ClosePath());
    if (dataPointsVisible) {
        drawDataPoints(POINTS, tile.isFillWithGradient() ? tile.getGradientStops().get(0).getColor() : tile.getBarColor());
    }
}
Also used : ClosePath(javafx.scene.shape.ClosePath) MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) Point(eu.hansolo.tilesfx.tools.Point)

Example 4 with Point

use of eu.hansolo.tilesfx.tools.Point in project tilesfx by HanSolo.

the class SmoothAreaChartTileSkin method drawDataPoints.

private void drawDataPoints(final List<Point> DATA, final Color COLOR) {
    if (DATA.isEmpty()) {
        return;
    }
    final double LOWER_BOUND_X = 0;
    final double LOWER_BOUND_Y = tile.getMinValue();
    ctx.clearRect(0, 0, width, height);
    for (Point point : DATA) {
        double x = (point.getX() - LOWER_BOUND_X);
        double y = (point.getY() - LOWER_BOUND_Y);
        drawDataPoint(x, y, COLOR);
    }
}
Also used : Point(eu.hansolo.tilesfx.tools.Point)

Example 5 with Point

use of eu.hansolo.tilesfx.tools.Point in project tilesfx by HanSolo.

the class SparkLineTileSkin method smooth.

private void smooth(final List<Double> DATA_LIST) {
    int size = DATA_LIST.size();
    Point[] points = new Point[size];
    low = Statistics.getMin(DATA_LIST);
    high = Statistics.getMax(DATA_LIST);
    if (Helper.equals(low, high)) {
        low = minValue;
        high = maxValue;
    }
    range = high - low;
    double minX = graphBounds.getX();
    double maxX = minX + graphBounds.getWidth();
    double minY = graphBounds.getY();
    double maxY = minY + graphBounds.getHeight();
    double stepX = graphBounds.getWidth() / (noOfDatapoints - 1);
    double stepY = graphBounds.getHeight() / range;
    for (int i = 0; i < size; i++) {
        points[i] = new Point(minX + i * stepX, maxY - Math.abs(low - DATA_LIST.get(i)) * stepY);
    }
    Point[] smoothedPoints = Helper.subdividePoints(points, 16);
    int length = smoothedPoints.length;
    sparkLine.getElements().clear();
    sparkLine.getElements().add(new MoveTo(smoothedPoints[0].getX(), smoothedPoints[0].getY()));
    for (int i = 1; i < length - 1; i++) {
        sparkLine.getElements().add(new LineTo(smoothedPoints[i].getX(), smoothedPoints[i].getY()));
    }
    dot.setCenterX(smoothedPoints[length - 1].getX());
    dot.setCenterY(smoothedPoints[length - 1].getY());
}
Also used : MoveTo(javafx.scene.shape.MoveTo) LineTo(javafx.scene.shape.LineTo) Point(eu.hansolo.tilesfx.tools.Point) Point(eu.hansolo.tilesfx.tools.Point)

Aggregations

Point (eu.hansolo.tilesfx.tools.Point)8 LineTo (javafx.scene.shape.LineTo)4 MoveTo (javafx.scene.shape.MoveTo)4 CacheHint (javafx.scene.CacheHint)3 Paint (javafx.scene.paint.Paint)3 ClosePath (javafx.scene.shape.ClosePath)2 ChartData (eu.hansolo.tilesfx.chart.ChartData)1 ArrayList (java.util.ArrayList)1 RadialGradient (javafx.scene.paint.RadialGradient)1 PathElement (javafx.scene.shape.PathElement)1