use of eu.hansolo.tilesfx.tools.GradientLookup in project tilesfx by HanSolo.
the class GaugeSparkLineTileSkin method initGraphics.
// ******************** Initialization ************************************
@Override
protected void initGraphics() {
super.initGraphics();
averagingListener = o -> handleEvents("AVERAGING_PERIOD");
highlightSectionListener = o -> handleEvents("HIGHLIGHT_SECTIONS");
timeFormatter = DateTimeFormatter.ofPattern("HH:mm", tile.getLocale());
if (tile.isAutoScale())
tile.calcAutoScale();
niceScaleY = new NiceScale(tile.getMinValue(), tile.getMaxValue());
niceScaleY.setMaxTicks(5);
tickLineColor = Color.color(Tile.FOREGROUND.getRed(), Tile.FOREGROUND.getGreen(), Tile.FOREGROUND.getBlue(), 0.50);
horizontalTickLines = new ArrayList<>(5);
tickLabelsY = new ArrayList<>(5);
for (int i = 0; i < 5; i++) {
Line hLine = new Line(0, 0, 0, 0);
hLine.getStrokeDashArray().addAll(1.0, 2.0);
hLine.setStroke(Color.TRANSPARENT);
horizontalTickLines.add(hLine);
Text tickLabelY = new Text("");
tickLabelY.setFill(Color.TRANSPARENT);
tickLabelsY.add(tickLabelY);
}
gradientLookup = new GradientLookup(tile.getGradientStops());
low = tile.getMaxValue();
high = tile.getMinValue();
stdDeviation = 0;
movingAverage = tile.getMovingAverage();
noOfDatapoints = tile.getAveragingPeriod();
dataList = new LinkedList<>();
// To get smooth lines in the chart we need at least 4 values
if (noOfDatapoints < 4)
throw new IllegalArgumentException("Please increase the averaging period to a value larger than 3.");
graphBounds = new Rectangle(PREFERRED_WIDTH * 0.05, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.9, PREFERRED_HEIGHT * 0.45);
titleText = new Text(tile.getTitle());
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
valueText = new Text(String.format(locale, formatString, tile.getValue()));
valueText.setFill(tile.getValueColor());
Helper.enableNode(valueText, tile.isValueVisible());
unitText = new Text(tile.getUnit());
unitText.setFill(tile.getUnitColor());
Helper.enableNode(unitText, !tile.getUnit().isEmpty());
valueUnitFlow = new TextFlow(valueText, unitText);
valueUnitFlow.setTextAlignment(TextAlignment.CENTER);
averageText = new Text(String.format(locale, formatString, tile.getAverage()));
averageText.setFill(Tile.FOREGROUND);
Helper.enableNode(averageText, tile.isAverageVisible());
text = new Text(tile.getText());
text.setTextOrigin(VPos.TOP);
text.setFill(tile.getTextColor());
timeSpanText = new Text("");
timeSpanText.setTextOrigin(VPos.TOP);
timeSpanText.setFill(tile.getTextColor());
Helper.enableNode(timeSpanText, !tile.isTextVisible());
stdDeviationArea = new Rectangle();
Helper.enableNode(stdDeviationArea, tile.isAverageVisible());
averageLine = new Line();
averageLine.setStroke(Tile.FOREGROUND);
averageLine.getStrokeDashArray().addAll(PREFERRED_WIDTH * 0.005, PREFERRED_WIDTH * 0.005);
Helper.enableNode(averageLine, tile.isAverageVisible());
pathElements = new ArrayList<>(noOfDatapoints);
pathElements.add(0, new MoveTo());
for (int i = 1; i < noOfDatapoints; i++) {
pathElements.add(i, new LineTo());
}
sparkLine = new Path();
sparkLine.getElements().addAll(pathElements);
sparkLine.setFill(null);
sparkLine.setStroke(tile.getBarColor());
sparkLine.setStrokeWidth(PREFERRED_WIDTH * 0.0075);
sparkLine.setStrokeLineCap(StrokeLineCap.ROUND);
sparkLine.setStrokeLineJoin(StrokeLineJoin.ROUND);
dot = new Circle();
dot.setFill(tile.getBarColor());
sectionCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
sectionCtx = sectionCanvas.getGraphicsContext2D();
highlightSectionCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
highlightSectionCtx = sectionCanvas.getGraphicsContext2D();
barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.4, PREFERRED_HEIGHT * 0.4, tile.getStartAngle() - 45, tile.getAngleRange());
barBackground.setType(ArcType.OPEN);
barBackground.setStroke(tile.getBarBackgroundColor());
barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.125);
barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
barBackground.setFill(null);
bar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.4, PREFERRED_HEIGHT * 0.4, tile.getStartAngle() - 135, 0);
bar.setType(ArcType.OPEN);
bar.setStroke(tile.getBarColor());
bar.setStrokeWidth(PREFERRED_WIDTH * 0.125);
bar.setStrokeLineCap(StrokeLineCap.BUTT);
bar.setFill(null);
minValueText = new Text();
maxValueText = new Text();
getPane().getChildren().addAll(sectionCanvas, highlightSectionCanvas, barBackground, bar, minValueText, maxValueText, titleText, valueUnitFlow, stdDeviationArea, averageLine, sparkLine, dot, averageText, timeSpanText, text);
getPane().getChildren().addAll(horizontalTickLines);
getPane().getChildren().addAll(tickLabelsY);
}
use of eu.hansolo.tilesfx.tools.GradientLookup in project tilesfx by HanSolo.
the class SparkLineTileSkin method initGraphics.
// ******************** Initialization ************************************
@Override
protected void initGraphics() {
super.initGraphics();
averagingListener = o -> handleEvents("AVERAGING");
timeFormatter = DateTimeFormatter.ofPattern("HH:mm", tile.getLocale());
if (tile.isAutoScale())
tile.calcAutoScale();
niceScaleY = new NiceScale(tile.getMinValue(), tile.getMaxValue());
niceScaleY.setMaxTicks(5);
tickLineColor = Color.color(tile.getChartGridColor().getRed(), tile.getChartGridColor().getGreen(), tile.getChartGridColor().getBlue(), 0.5);
horizontalTickLines = new ArrayList<>(5);
tickLabelsY = new ArrayList<>(5);
for (int i = 0; i < 5; i++) {
Line hLine = new Line(0, 0, 0, 0);
hLine.getStrokeDashArray().addAll(1.0, 2.0);
hLine.setStroke(Color.TRANSPARENT);
horizontalTickLines.add(hLine);
Text tickLabelY = new Text("");
tickLabelY.setFill(Color.TRANSPARENT);
tickLabelsY.add(tickLabelY);
}
gradientLookup = new GradientLookup(tile.getGradientStops());
low = tile.getMaxValue();
high = tile.getMinValue();
stdDeviation = 0;
movingAverage = tile.getMovingAverage();
noOfDatapoints = tile.getAveragingPeriod();
dataList = new LinkedList<>();
// To get smooth lines in the chart we need at least 4 values
if (noOfDatapoints < 4)
throw new IllegalArgumentException("Please increase the averaging period to a value larger than 3.");
graphBounds = new Rectangle(PREFERRED_WIDTH * 0.05, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.9, PREFERRED_HEIGHT * 0.45);
titleText = new Text(tile.getTitle());
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
valueText = new Text(String.format(locale, formatString, tile.getValue()));
valueText.setFill(tile.getValueColor());
Helper.enableNode(valueText, tile.isValueVisible());
unitText = new Text(tile.getUnit());
unitText.setFill(tile.getUnitColor());
Helper.enableNode(unitText, !tile.getUnit().isEmpty());
valueUnitFlow = new TextFlow(valueText, unitText);
valueUnitFlow.setTextAlignment(TextAlignment.RIGHT);
averageText = new Text(String.format(locale, formatString, tile.getAverage()));
averageText.setFill(Tile.FOREGROUND);
Helper.enableNode(averageText, tile.isAverageVisible());
highText = new Text();
highText.setTextOrigin(VPos.BOTTOM);
highText.setFill(tile.getValueColor());
lowText = new Text();
lowText.setTextOrigin(VPos.TOP);
lowText.setFill(tile.getValueColor());
text = new Text(tile.getText());
text.setTextOrigin(VPos.TOP);
text.setFill(tile.getTextColor());
timeSpanText = new Text("");
timeSpanText.setTextOrigin(VPos.TOP);
timeSpanText.setFill(tile.getTextColor());
Helper.enableNode(timeSpanText, !tile.isTextVisible());
stdDeviationArea = new Rectangle();
Helper.enableNode(stdDeviationArea, tile.isAverageVisible());
averageLine = new Line();
averageLine.setStroke(Tile.FOREGROUND);
averageLine.getStrokeDashArray().addAll(PREFERRED_WIDTH * 0.005, PREFERRED_WIDTH * 0.005);
Helper.enableNode(averageLine, tile.isAverageVisible());
pathElements = new ArrayList<>(noOfDatapoints);
pathElements.add(0, new MoveTo());
for (int i = 1; i < noOfDatapoints; i++) {
pathElements.add(i, new LineTo());
}
sparkLine = new Path();
sparkLine.getElements().addAll(pathElements);
sparkLine.setFill(null);
sparkLine.setStroke(tile.getBarColor());
sparkLine.setStrokeWidth(PREFERRED_WIDTH * 0.0075);
sparkLine.setStrokeLineCap(StrokeLineCap.ROUND);
sparkLine.setStrokeLineJoin(StrokeLineJoin.ROUND);
dot = new Circle();
dot.setFill(tile.getBarColor());
getPane().getChildren().addAll(titleText, valueUnitFlow, stdDeviationArea, averageLine, sparkLine, dot, averageText, highText, lowText, timeSpanText, text);
getPane().getChildren().addAll(horizontalTickLines);
getPane().getChildren().addAll(tickLabelsY);
}
Aggregations