Search in sources :

Example 1 with Section

use of eu.hansolo.tilesfx.Section in project tilesfx by HanSolo.

the class GaugeSparkLineTileSkin method setBar.

private void setBar(final double VALUE) {
    double barLength = 0;
    double barStart = 0;
    double min = tile.getMinValue();
    double max = tile.getMaxValue();
    double step = tile.getAngleStep();
    double clampedValue = Helper.clamp(min, max, VALUE);
    if (tile.isStartFromZero()) {
        if ((VALUE > min || min < 0) && (VALUE < max || max > 0)) {
            if (max < 0) {
                barStart = tile.getStartAngle() - 135 - tile.getAngleRange();
                barLength = (max - clampedValue) * step;
            } else if (min > 0) {
                barStart = tile.getStartAngle() - 135;
                barLength = (min - clampedValue) * step;
            } else {
                barStart = tile.getStartAngle() - 135 + min * step;
                barLength = -clampedValue * step;
            }
        }
    } else {
        barStart = tile.getStartAngle() - 135;
        barLength = (min - clampedValue) * step;
    }
    bar.setStartAngle(barStart);
    bar.setLength(barLength);
    if (tile.getSectionsVisible() && !sections.isEmpty()) {
        bar.setStroke(tile.getBarColor());
        for (Section section : sections) {
            if (section.contains(VALUE)) {
                bar.setStroke(section.getColor());
                break;
            }
        }
    }
}
Also used : Section(eu.hansolo.tilesfx.Section)

Example 2 with Section

use of eu.hansolo.tilesfx.Section in project tilesfx by HanSolo.

the class PercentageTileSkin method setBarColor.

private void setBarColor(final double VALUE) {
    Color color = barColor;
    for (Section section : sections) {
        if (section.contains(VALUE)) {
            color = section.getColor();
            break;
        }
    }
    bar.setFill(color);
    percentageText.setFill(color);
    percentageUnitText.setFill(color);
}
Also used : Color(javafx.scene.paint.Color) Section(eu.hansolo.tilesfx.Section)

Example 3 with Section

use of eu.hansolo.tilesfx.Section in project tilesfx by HanSolo.

the class GaugeSparkLineTileSkin method drawHighLightSections.

private void drawHighLightSections(final double VALUE) {
    highlightSectionCtx.setLineCap(StrokeLineCap.BUTT);
    highlightSectionCtx.clearRect(0, 0, width, height);
    if (tile.getSectionsVisible() && !sections.isEmpty()) {
        double x = (width - size * 0.7) * 0.5;
        double y = (height - size * 0.7) * 0.5;
        double wh = size * 0.7;
        double minValue = tile.getMinValue();
        double maxValue = tile.getMaxValue();
        double angleStep = tile.getAngleStep();
        highlightSectionCtx.setLineWidth(size * 0.01);
        highlightSectionCtx.setLineCap(StrokeLineCap.BUTT);
        for (int i = 0; i < sections.size(); i++) {
            Section section = sections.get(i);
            double sectionStartAngle;
            if (Double.compare(section.getStart(), maxValue) <= 0 && Double.compare(section.getStop(), minValue) >= 0) {
                if (Double.compare(section.getStart(), minValue) < 0 && Double.compare(section.getStop(), maxValue) < 0) {
                    sectionStartAngle = 15;
                } else {
                    sectionStartAngle = (section.getStart() - minValue) * angleStep + 15;
                }
                double sectionAngleExtend;
                if (Double.compare(section.getStop(), maxValue) > 0) {
                    sectionAngleExtend = (maxValue - section.getStart()) * angleStep;
                } else if (Double.compare(section.getStart(), minValue) < 0) {
                    sectionAngleExtend = (section.getStop() - minValue) * tile.getAngleStep();
                } else {
                    sectionAngleExtend = (section.getStop() - section.getStart()) * angleStep;
                }
                highlightSectionCtx.save();
                highlightSectionCtx.setStroke(section.contains(VALUE) ? section.getColor() : section.getColor().darker().darker());
                highlightSectionCtx.strokeArc(x, y, wh, wh, -(120 + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN);
                highlightSectionCtx.restore();
            }
        }
    }
}
Also used : Section(eu.hansolo.tilesfx.Section) CacheHint(javafx.scene.CacheHint) Point(eu.hansolo.tilesfx.tools.Point)

Example 4 with Section

use of eu.hansolo.tilesfx.Section in project tilesfx by HanSolo.

the class GaugeSparkLineTileSkin method drawBackground.

private void drawBackground() {
    sectionCanvas.setCache(false);
    sectionCtx.setLineCap(StrokeLineCap.BUTT);
    sectionCtx.clearRect(0, 0, width, height);
    if (tile.getSectionsVisible() && !sections.isEmpty()) {
        double x = (width - size * 0.7) * 0.5;
        double y = (height - size * 0.7) * 0.5;
        double wh = size * 0.7;
        double minValue = tile.getMinValue();
        double maxValue = tile.getMaxValue();
        double angleStep = tile.getAngleStep();
        sectionCtx.setLineWidth(size * 0.01);
        sectionCtx.setLineCap(StrokeLineCap.BUTT);
        for (int i = 0; i < sections.size(); i++) {
            Section section = sections.get(i);
            double sectionStartAngle;
            if (Double.compare(section.getStart(), maxValue) <= 0 && Double.compare(section.getStop(), minValue) >= 0) {
                if (Double.compare(section.getStart(), minValue) < 0 && Double.compare(section.getStop(), maxValue) < 0) {
                    sectionStartAngle = 15;
                } else {
                    sectionStartAngle = (section.getStart() - minValue) * angleStep + 15;
                }
                double sectionAngleExtend;
                if (Double.compare(section.getStop(), maxValue) > 0) {
                    sectionAngleExtend = (maxValue - section.getStart()) * angleStep;
                } else if (Double.compare(section.getStart(), minValue) < 0) {
                    sectionAngleExtend = (section.getStop() - minValue) * tile.getAngleStep();
                } else {
                    sectionAngleExtend = (section.getStop() - section.getStart()) * angleStep;
                }
                sectionCtx.save();
                sectionCtx.setStroke(section.getColor());
                sectionCtx.strokeArc(x, y, wh, wh, -(120 + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN);
                sectionCtx.restore();
            }
        }
    }
    sectionCanvas.setCache(true);
    sectionCanvas.setCacheHint(CacheHint.QUALITY);
    barBackground.setStroke(tile.getBarBackgroundColor());
}
Also used : Section(eu.hansolo.tilesfx.Section) CacheHint(javafx.scene.CacheHint) Point(eu.hansolo.tilesfx.tools.Point)

Example 5 with Section

use of eu.hansolo.tilesfx.Section in project tilesfx by HanSolo.

the class GaugeTileSkin method initGraphics.

// ******************** Initialization ************************************
@Override
protected void initGraphics() {
    super.initGraphics();
    if (tile.isAutoScale())
        tile.calcAutoScale();
    oldValue = tile.getValue();
    sectionMap = new HashMap<>(sections.size());
    for (Section section : sections) {
        sectionMap.put(section, new Arc());
    }
    barColor = tile.getBarColor();
    thresholdColor = tile.getThresholdColor();
    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, -angleRange);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(barColor);
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);
    thresholdBar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, -angleRange * 0.5 + 90, 0);
    thresholdBar.setType(ArcType.OPEN);
    thresholdBar.setStroke(tile.getThresholdColor());
    thresholdBar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    thresholdBar.setStrokeLineCap(StrokeLineCap.BUTT);
    thresholdBar.setFill(null);
    Helper.enableNode(thresholdBar, !tile.getSectionsVisible());
    sectionPane = new Pane();
    Helper.enableNode(sectionPane, tile.getSectionsVisible());
    if (sectionsVisible) {
        drawSections();
    }
    alertIcon = new Path();
    alertIcon.setFillRule(FillRule.EVEN_ODD);
    alertIcon.setFill(Color.YELLOW);
    alertIcon.setStroke(null);
    Helper.enableNode(alertIcon, tile.isAlert());
    alertTooltip = new Tooltip(tile.getAlertMessage());
    Tooltip.install(alertIcon, alertTooltip);
    needleRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
    needleRectRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
    needleRect = new Rectangle();
    needleRect.setFill(tile.getBackgroundColor());
    needleRect.getTransforms().setAll(needleRectRotate);
    needle = new Path();
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getTransforms().setAll(needleRotate);
    needle.setFill(tile.getNeedleColor());
    needle.setStrokeWidth(0);
    needle.setStroke(Color.TRANSPARENT);
    titleText = new Text(tile.getTitle());
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());
    valueText = new Text(String.format(locale, formatString, tile.getCurrentValue()));
    valueText.setFill(tile.getValueColor());
    valueText.setTextOrigin(VPos.BASELINE);
    Helper.enableNode(valueText, tile.isValueVisible() && !tile.isAlert());
    unitText = new Text(tile.getUnit());
    unitText.setFill(tile.getUnitColor());
    unitText.setTextOrigin(VPos.BASELINE);
    Helper.enableNode(unitText, tile.isValueVisible() && !tile.isAlert());
    valueUnitFlow = new TextFlow(valueText, unitText);
    valueUnitFlow.setTextAlignment(TextAlignment.CENTER);
    minValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMinValue()));
    minValueText.setFill(tile.getTitleColor());
    maxValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMaxValue()));
    maxValueText.setFill(tile.getTitleColor());
    thresholdRect = new Rectangle();
    thresholdRect.setFill(sectionsVisible ? Color.TRANSPARENT : tile.getValue() > tile.getThreshold() ? tile.getThresholdColor() : Tile.GRAY);
    Helper.enableNode(thresholdRect, tile.isThresholdVisible());
    thresholdText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getThreshold()));
    thresholdText.setFill(sectionsVisible ? Color.TRANSPARENT : Tile.GRAY);
    Helper.enableNode(thresholdText, tile.isThresholdVisible());
    getPane().getChildren().addAll(barBackground, thresholdBar, sectionPane, alertIcon, needleRect, needle, titleText, valueUnitFlow, minValueText, maxValueText, thresholdRect, thresholdText);
}
Also used : Path(javafx.scene.shape.Path) ClosePath(javafx.scene.shape.ClosePath) Arc(javafx.scene.shape.Arc) Rotate(javafx.scene.transform.Rotate) Tooltip(javafx.scene.control.Tooltip) Rectangle(javafx.scene.shape.Rectangle) Text(javafx.scene.text.Text) TextFlow(javafx.scene.text.TextFlow) Section(eu.hansolo.tilesfx.Section) Pane(javafx.scene.layout.Pane)

Aggregations

Section (eu.hansolo.tilesfx.Section)6 CacheHint (javafx.scene.CacheHint)3 Point (eu.hansolo.tilesfx.tools.Point)2 Tooltip (javafx.scene.control.Tooltip)2 Arc (javafx.scene.shape.Arc)2 ArrayList (java.util.ArrayList)1 Pane (javafx.scene.layout.Pane)1 Color (javafx.scene.paint.Color)1 ClosePath (javafx.scene.shape.ClosePath)1 Line (javafx.scene.shape.Line)1 Path (javafx.scene.shape.Path)1 Rectangle (javafx.scene.shape.Rectangle)1 Text (javafx.scene.text.Text)1 TextFlow (javafx.scene.text.TextFlow)1 Rotate (javafx.scene.transform.Rotate)1