Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
eu.hansolo.tilesfx.Test Maven / Gradle / Ivy
/*
* Copyright (c) 2017 by Gerrit Grunwald
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.hansolo.tilesfx;
import eu.hansolo.tilesfx.Tile.SkinType;
import eu.hansolo.tilesfx.chart.ChartData;
import eu.hansolo.tilesfx.chart.SmoothedChart;
import eu.hansolo.tilesfx.chart.TilesFXSeries;
import eu.hansolo.tilesfx.events.TileEvent.EventType;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.XYChart.Series;
import javafx.scene.effect.BlurType;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.InnerShadow;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.StrokeLineCap;
import javafx.stage.Stage;
import java.util.ArrayList;
import java.util.List;
import static eu.hansolo.tilesfx.chart.SmoothedChart.TRANSPARENT_BACKGROUND;
import static eu.hansolo.tilesfx.tools.Country.BE;
import static eu.hansolo.tilesfx.tools.Country.LU;
import static eu.hansolo.tilesfx.tools.Country.NL;
/**
* User: hansolo
* Date: 13.10.17
* Time: 14:52
*/
public class Test extends Application {
private static int noOfNodes = 0;
private TilesFXSeries product1Series;
private TilesFXSeries product2Series;
private TilesFXSeries product3Series;
private ChartData product1Data;
private ChartData product2Data;
private ChartData product3Data;
private Tile product1Tile;
private Tile product2Tile;
private Tile product3Tile;
private Tile last7DaysTile;
private SmoothedChart chart;
@Override public void init() {
List product1Stops = new ArrayList<>();
product1Stops.add(new Stop(0, Color.web("#54D1FF")));
product1Stops.add(new Stop(1, Color.web("#016AED")));
List product2Stops = new ArrayList<>();
product2Stops.add(new Stop(0, Color.web("#F9348A")));
product2Stops.add(new Stop(1, Color.web("#EB123A")));
List product3Stops = new ArrayList<>();
product3Stops.add(new Stop(0, Color.web("#7BFB00")));
product3Stops.add(new Stop(1, Color.web("#FCE207")));
XYChart.Series series1 = new XYChart.Series();
series1.setName("Product 1");
series1.getData().add(new XYChart.Data<>("MO", 105));
series1.getData().add(new XYChart.Data<>("TU", 95));
series1.getData().add(new XYChart.Data<>("WE", 112));
series1.getData().add(new XYChart.Data<>("TH", 165));
series1.getData().add(new XYChart.Data<>("FR", 132));
series1.getData().add(new XYChart.Data<>("SA", 120));
series1.getData().add(new XYChart.Data<>("SU", 153));
product1Series = new TilesFXSeries<>(series1,
new LinearGradient(0, 0, 1, 0,
true, CycleMethod.NO_CYCLE,
new Stop(0, Color.web("#54D1FF")),
new Stop(1, Color.web("#016AED"))),
Color.TRANSPARENT,
Color.web("#54D1FF"));
XYChart.Series series2 = new XYChart.Series();
series2.setName("Product 2");
series2.getData().add(new XYChart.Data<>("MO", 75));
series2.getData().add(new XYChart.Data<>("TU", 98));
series2.getData().add(new XYChart.Data<>("WE", 145));
series2.getData().add(new XYChart.Data<>("TH", 150));
series2.getData().add(new XYChart.Data<>("FR", 125));
series2.getData().add(new XYChart.Data<>("SA", 141));
series2.getData().add(new XYChart.Data<>("SU", 250));
product2Series = new TilesFXSeries<>(series2,
new LinearGradient(0, 0, 1, 0,
true, CycleMethod.NO_CYCLE,
new Stop(0, Color.web("#F9348A")),
new Stop(1, Color.web("#EB123A"))),
Color.TRANSPARENT,
Color.web("#F9348A"));
XYChart.Series series3 = new XYChart.Series();
series3.setName("Product 3");
series3.getData().add(new XYChart.Data<>("MO", 150));
series3.getData().add(new XYChart.Data<>("TU", 140));
series3.getData().add(new XYChart.Data<>("WE", 125));
series3.getData().add(new XYChart.Data<>("TH", 130));
series3.getData().add(new XYChart.Data<>("FR", 127));
series3.getData().add(new XYChart.Data<>("SA", 150));
series3.getData().add(new XYChart.Data<>("SU", 165));
product3Series = new TilesFXSeries<>(series3,
new LinearGradient(0, 0, 1, 0,
true, CycleMethod.NO_CYCLE,
new Stop(0, Color.web("#7BFB00")),
new Stop(1, Color.web("#FCE207"))),
Color.TRANSPARENT,
Color.web("#7BFB00"));
double sumProduct1 = getSumOfProduct(series1);
double sumProduct2 = getSumOfProduct(series2);
double sumProduct3 = getSumOfProduct(series3);
double sumOfAllProducts = sumProduct1 + sumProduct2 + sumProduct3;
double allOverSales = sumOfAllProducts + sumOfAllProducts * 0.25;
product1Data = new ChartData("Product 1", sumProduct1, Color.web("#54D1FF"));
product2Data = new ChartData("Product 2", sumProduct2, Color.web("#F9348A"));
product3Data = new ChartData("Product 3", sumProduct3, Color.web("#7BFB00"));
product1Tile = createProductTile(product1Data, allOverSales, product1Stops, product1Data, product2Data, product3Data);
product2Tile = createProductTile(product2Data, allOverSales, product2Stops, product1Data, product2Data, product3Data);
product3Tile = createProductTile(product3Data, allOverSales, product3Stops, product1Data, product2Data, product3Data);
last7DaysTile = TileBuilder.create()
.skinType(SkinType.SMOOTHED_CHART)
.prefSize(450, 300)
.maxSize(900, 300)
.maxValue(250)
.snapToTicks(true)
.backgroundColor(Color.web("#26262D"))
.textVisible(false)
.xAxis(new CategoryAxis())
.yAxis(new NumberAxis())
.tilesFxSeries(product1Series, product2Series, product3Series)
.dataPointsVisible(true)
.smoothing(true)
.build();
last7DaysTile.setOnTileEvent(e -> {
if (e.getEventType() == EventType.SELECTED_CHART_DATA) {
System.out.println(e.getData());
}
});
GridPane.setColumnSpan(last7DaysTile, 3);
GridPane.setHgrow(last7DaysTile, Priority.ALWAYS);
GridPane.setVgrow(last7DaysTile, Priority.ALWAYS);
chart = new SmoothedChart<>(new CategoryAxis(), new NumberAxis());
chart.getData().addAll(series1, series2, series3);
chart.setChartType(SmoothedChart.ChartType.AREA);
chart.setSeriesColor(series1, new LinearGradient(0, 0, 1, 0,
true, CycleMethod.NO_CYCLE,
new Stop(0, Color.web("#54D1FF")),
new Stop(1, Color.web("#016AED"))),
Color.TRANSPARENT);
chart.setSeriesColor(series2, new LinearGradient(0, 0, 1, 0,
true, CycleMethod.NO_CYCLE,
new Stop(0, Color.web("#F9348A")),
new Stop(1, Color.web("#EB123A"))),
Color.TRANSPARENT);
chart.setSeriesColor(series3, new LinearGradient(0, 0, 1, 0,
true, CycleMethod.NO_CYCLE,
new Stop(0, Color.web("#7BFB00")),
new Stop(1, Color.web("#FCE207"))),
Color.TRANSPARENT);
chart.getChartPlotBackground().setBackground(TRANSPARENT_BACKGROUND);
//chart.setLegendBackground(TRANSPARENT_BACKGROUND);
//chart.setLegendTextFill(Color.WHITE);
chart.setXAxisTickLabelFill(Color.web("#7A808D"));
chart.setYAxisTickLabelFill(Color.web("#7A808D"));
chart.setAxisTickMarkFill(Color.TRANSPARENT);
chart.setXAxisBorderColor(Color.TRANSPARENT);
chart.setYAxisBorderColor(Color.TRANSPARENT);
chart.getHorizontalGridLines().setStroke(Color.TRANSPARENT);
LinearGradient verticalGridLineGradient = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE,
new Stop(0, Color.TRANSPARENT),
new Stop(0.35, Color.TRANSPARENT),
new Stop(1, Color.web("#7A808D")));
chart.getVerticalGridLines().setStroke(verticalGridLineGradient);
chart.setHorizontalZeroLineVisible(false);
chart.setSymbolSize(series1, 10);
chart.setSymbolSize(series2, 10);
chart.setSymbolSize(series3, 10);
chart.setSymbolsVisible(false);
chart.getStrokePath(series1).setStrokeWidth(4);
chart.getStrokePath(series2).setStrokeWidth(4);
chart.getStrokePath(series3).setStrokeWidth(4);
chart.getStrokePath(series1).setStrokeLineCap(StrokeLineCap.ROUND);
chart.getStrokePath(series2).setStrokeLineCap(StrokeLineCap.ROUND);
chart.getStrokePath(series3).setStrokeLineCap(StrokeLineCap.ROUND);
InnerShadow lightEffect = new InnerShadow(BlurType.GAUSSIAN, Color.rgb(255, 255, 255, 0.65), 3, 0, 0, 2);
DropShadow lineEffect = new DropShadow(BlurType.GAUSSIAN, Color.rgb(0, 0, 0, 0.45), 10, 0.0, 0.0, 15.0);
lineEffect.setInput(lightEffect);
chart.getStrokePath(series1).setEffect(lineEffect);
chart.getStrokePath(series2).setEffect(lineEffect);
chart.getStrokePath(series3).setEffect(lineEffect);
GridPane.setColumnSpan(chart, 3);
GridPane.setHgrow(chart, Priority.ALWAYS);
GridPane.setVgrow(chart, Priority.ALWAYS);
}
@Override public void start(Stage stage) {
GridPane pane = new GridPane();
pane.setPadding(new Insets(10));
pane.setHgap(0);
pane.setVgap(10);
pane.add(chart, 0, 0);
pane.add(product1Tile, 0, 1);
pane.add(product2Tile, 1, 1);
pane.add(product3Tile, 2, 1);
RadialGradient gradient = new RadialGradient(0, 0, 0.5, 0.25, 0.5, true, CycleMethod.NO_CYCLE,
new Stop(0, Color.web("#313A48")),
new Stop(1, Color.web("#26262D")));
pane.setBackground(new Background(new BackgroundFill(gradient, CornerRadii.EMPTY, Insets.EMPTY)));
Scene scene = new Scene(pane);
stage.setTitle("Tile");
stage.setScene(scene);
stage.show();
product1Tile.showNotifier(true);
// Calculate number of nodes
calcNoOfNodes(pane);
System.out.println(noOfNodes + " Nodes in SceneGraph");
}
@Override public void stop() {
System.exit(0);
}
private Tile createProductTile(final ChartData PRODUCT_DATA, final double REFERENCE_VALUE, final List STOPS, ChartData... ALL_PRODUCTS) {
Tile tile = TileBuilder.create().skinType(SkinType.RADIAL_PERCENTAGE)
.prefSize(150, 150)
.maxSize(300, 300)
.backgroundColor(Color.web("#26262D"))
.maxValue(1000)
.title("")
.description(PRODUCT_DATA.getName())
.text("TEXT")
.textVisible(false)
.chartData(ALL_PRODUCTS)
.animated(true)
.referenceValue(REFERENCE_VALUE)
.value(PRODUCT_DATA.getValue())
.descriptionColor(Tile.GRAY)
.valueColor(PRODUCT_DATA.getFillColor())
.unitColor(PRODUCT_DATA.getFillColor())
.barColor(PRODUCT_DATA.getFillColor())
.gradientStops(STOPS)
.fillWithGradient(true)
.decimals(0)
.build();
GridPane.setHgrow(tile, Priority.ALWAYS);
GridPane.setVgrow(tile, Priority.ALWAYS);
return tile;
}
private double getSumOfProduct(final Series PRODUCT_SERIES) {
return PRODUCT_SERIES.getData().stream().mapToDouble(data -> data.getYValue().doubleValue()).sum();
}
// ******************** Misc **********************************************
private static void calcNoOfNodes(Node node) {
if (node instanceof Parent) {
if (((Parent) node).getChildrenUnmodifiable().size() != 0) {
ObservableList tempChildren = ((Parent) node).getChildrenUnmodifiable();
noOfNodes += tempChildren.size();
for (Node n : tempChildren) { calcNoOfNodes(n); }
}
}
}
public static void main(String[] args) {
launch(args);
}
}