Search in sources :

Example 16 with ChartData

use of eu.hansolo.tilesfx.chart.ChartData in project tilesfx by HanSolo.

the class CalendarTileSkin method checkClick.

private void checkClick(final MouseEvent EVENT) {
    Label selectedLabel = ((Label) EVENT.getSource());
    String selectedText = selectedLabel.getText();
    if (null == selectedText || selectedText.isEmpty() || !Character.isDigit(selectedText.charAt(0))) {
        return;
    }
    if (selectedLabel.getBorder() != null && selectedLabel.getBorder().equals(weekBorder)) {
        return;
    }
    int selectedNo = Integer.parseInt(selectedText);
    if (selectedNo > 31) {
        return;
    }
    List<ChartData> dataList = tile.getChartData();
    ZonedDateTime time = tile.getTime();
    LocalDate selectedDate = LocalDate.of(time.getYear(), time.getMonth(), selectedNo);
    Optional<ChartData> selectedChartData = dataList.stream().filter(data -> data.getTimestampAsLocalDate().isEqual(selectedDate)).findAny();
    if (selectedChartData.isPresent()) {
        tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, selectedChartData.get()));
    }
}
Also used : EventHandler(javafx.event.EventHandler) Pos(javafx.geometry.Pos) Fonts(eu.hansolo.tilesfx.fonts.Fonts) MouseEvent(javafx.scene.input.MouseEvent) ZonedDateTime(java.time.ZonedDateTime) EventType(eu.hansolo.tilesfx.events.TileEvent.EventType) ArrayList(java.util.ArrayList) ChartData(eu.hansolo.tilesfx.chart.ChartData) Insets(javafx.geometry.Insets) Helper(eu.hansolo.tilesfx.tools.Helper) BorderWidths(javafx.scene.layout.BorderWidths) BackgroundFill(javafx.scene.layout.BackgroundFill) Locale(java.util.Locale) Tile(eu.hansolo.tilesfx.Tile) Color(javafx.scene.paint.Color) Label(javafx.scene.control.Label) TextStyle(java.time.format.TextStyle) Border(javafx.scene.layout.Border) Font(javafx.scene.text.Font) Background(javafx.scene.layout.Background) DAY_OF_MONTH(java.time.temporal.ChronoField.DAY_OF_MONTH) BorderStrokeStyle(javafx.scene.layout.BorderStrokeStyle) BorderStroke(javafx.scene.layout.BorderStroke) Text(javafx.scene.text.Text) List(java.util.List) TileEvent(eu.hansolo.tilesfx.events.TileEvent) IsoFields(java.time.temporal.IsoFields) DayOfWeek(java.time.DayOfWeek) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) CornerRadii(javafx.scene.layout.CornerRadii) TileEvent(eu.hansolo.tilesfx.events.TileEvent) ChartData(eu.hansolo.tilesfx.chart.ChartData) ZonedDateTime(java.time.ZonedDateTime) Label(javafx.scene.control.Label) LocalDate(java.time.LocalDate)

Example 17 with ChartData

use of eu.hansolo.tilesfx.chart.ChartData in project tilesfx by HanSolo.

the class MatrixTileSkin method updateMatrixWithChartData.

private void updateMatrixWithChartData() {
    List<ChartData> dataList = tile.getChartData();
    int cols = dataList.size();
    int rows = matrix.getRows();
    double factor = rows / tile.getRange();
    Color offColor = matrix.getPixelOffColor();
    matrix.setAllPixelsOff();
    for (int y = rows; y >= 0; y--) {
        for (int x = 0; x < cols; x++) {
            int noOfActivePixels = Helper.roundDoubleToInt((maxValue - dataList.get(x).getValue()) * factor);
            matrix.setPixel(x, y, noOfActivePixels <= y ? dataList.get(x).getFillColor() : offColor);
        }
    }
    matrix.drawMatrix();
}
Also used : ChartData(eu.hansolo.tilesfx.chart.ChartData) Color(javafx.scene.paint.Color)

Example 18 with ChartData

use of eu.hansolo.tilesfx.chart.ChartData in project tilesfx by HanSolo.

the class WorldMapTileSkin method initGraphics.

// ******************** Initialization ************************************
@Override
protected void initGraphics() {
    super.initGraphics();
    poiLocations = FXCollections.observableHashMap();
    chartDataLocations = FXCollections.observableHashMap();
    handlerMap = new HashMap<>();
    circleHandlerMap = new HashMap<>();
    countryPaths = tile.getCountryPaths();
    String formatString = new StringBuilder("%.").append(tile.getDecimals()).append("f").toString();
    poiListener = new WeakListChangeListener<>(change -> {
        while (change.next()) {
            if (change.wasAdded()) {
                change.getAddedSubList().forEach(addedPoi -> {
                    String tooltipText = new StringBuilder(addedPoi.getName()).append("\n").append(addedPoi.getInfo()).toString();
                    EventHandler<MouseEvent> handler = e -> addedPoi.fireLocationEvent(new LocationEvent(addedPoi));
                    Circle circle = new Circle(3, addedPoi.getColor());
                    Tooltip.install(circle, new Tooltip(tooltipText));
                    circleHandlerMap.put(circle, handler);
                    poiLocations.put(addedPoi, circle);
                    circle.setOnMousePressed(handler);
                    getPane().getChildren().add(circle);
                });
            } else if (change.wasRemoved()) {
                change.getRemoved().forEach(removedPoi -> {
                    if (circleHandlerMap.get(removedPoi) != null) {
                        poiLocations.get(removedPoi).removeEventHandler(MouseEvent.MOUSE_PRESSED, circleHandlerMap.get(removedPoi));
                    }
                    getPane().getChildren().remove(removedPoi);
                });
            }
        }
        resize();
    });
    chartDataListener = new WeakListChangeListener<>(change -> {
        while (change.next()) {
            if (change.wasAdded()) {
                change.getAddedSubList().forEach(addedData -> {
                    String tooltipText = new StringBuilder(addedData.getName()).append("\n").append(String.format(Locale.US, formatString, addedData.getValue())).toString();
                    EventHandler<MouseEvent> handler = e -> tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, addedData));
                    Circle circle = new Circle(3, addedData.getLocation().getColor());
                    Tooltip.install(circle, new Tooltip(tooltipText));
                    circleHandlerMap.put(circle, handler);
                    chartDataLocations.put(addedData.getLocation(), circle);
                    circle.setOnMousePressed(handler);
                    getPane().getChildren().add(circle);
                });
            } else if (change.wasRemoved()) {
                change.getRemoved().forEach(removedData -> {
                    if (circleHandlerMap.get(removedData) != null) {
                        chartDataLocations.get(removedData).removeEventHandler(MouseEvent.MOUSE_PRESSED, circleHandlerMap.get(removedData));
                    }
                    getPane().getChildren().remove(removedData);
                });
            }
        }
        resize();
    });
    tile.getPoiList().forEach(poi -> {
        String tooltipText = new StringBuilder(poi.getName()).append("\n").append(poi.getInfo()).toString();
        Circle circle = new Circle(3, poi.getColor());
        circle.setOnMousePressed(e -> poi.fireLocationEvent(new LocationEvent(poi)));
        Tooltip.install(circle, new Tooltip(tooltipText));
        poiLocations.put(poi, circle);
    });
    tile.getChartData().stream().filter(chartData -> chartData.getLocation() != null).forEach(chartData -> {
        String tooltipText = new StringBuilder(chartData.getName()).append("\n").append(String.format(Locale.US, formatString, chartData.getValue())).toString();
        Circle circle = new Circle(3, chartData.getLocation().getColor());
        circle.setOnMousePressed(e -> tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, chartData)));
        Tooltip.install(circle, new Tooltip(tooltipText));
        chartDataLocations.put(chartData.getLocation(), circle);
    });
    titleText = new Text();
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());
    text = new Text(tile.getUnit());
    text.setFill(tile.getUnitColor());
    Helper.enableNode(text, tile.isTextVisible());
    Color fill = tile.getForegroundColor();
    Color stroke = tile.getBackgroundColor();
    worldPane = new Pane();
    countryPaths.forEach((name, pathList) -> {
        Country country = Country.valueOf(name);
        pathList.forEach(path -> {
            path.setFill(null == country.getColor() ? fill : country.getColor());
            path.setStroke(stroke);
            path.setStrokeWidth(0.2);
        });
        worldPane.getChildren().addAll(pathList);
    });
    group = new Group(worldPane);
    getPane().getChildren().addAll(group, titleText, text);
    getPane().getChildren().addAll(chartDataLocations.values());
    getPane().getChildren().addAll(poiLocations.values());
}
Also used : EventHandler(javafx.event.EventHandler) Fonts(eu.hansolo.tilesfx.fonts.Fonts) Location(eu.hansolo.tilesfx.tools.Location) CacheHint(javafx.scene.CacheHint) MouseEvent(javafx.scene.input.MouseEvent) EventType(eu.hansolo.tilesfx.events.TileEvent.EventType) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) CountryPath(eu.hansolo.tilesfx.tools.CountryPath) ChartData(eu.hansolo.tilesfx.chart.ChartData) Helper(eu.hansolo.tilesfx.tools.Helper) ListChangeListener(javafx.collections.ListChangeListener) Locale(java.util.Locale) Country(eu.hansolo.tilesfx.tools.Country) Map(java.util.Map) Helper.clamp(eu.hansolo.tilesfx.tools.Helper.clamp) Circle(javafx.scene.shape.Circle) Tooltip(javafx.scene.control.Tooltip) Pane(javafx.scene.layout.Pane) Tile(eu.hansolo.tilesfx.Tile) Color(javafx.scene.paint.Color) TextSize(eu.hansolo.tilesfx.Tile.TextSize) Font(javafx.scene.text.Font) ObservableMap(javafx.collections.ObservableMap) Group(javafx.scene.Group) Text(javafx.scene.text.Text) List(java.util.List) TileEvent(eu.hansolo.tilesfx.events.TileEvent) LocationEvent(eu.hansolo.tilesfx.events.LocationEvent) WeakListChangeListener(javafx.collections.WeakListChangeListener) Circle(javafx.scene.shape.Circle) TileEvent(eu.hansolo.tilesfx.events.TileEvent) Group(javafx.scene.Group) Tooltip(javafx.scene.control.Tooltip) Color(javafx.scene.paint.Color) EventHandler(javafx.event.EventHandler) Text(javafx.scene.text.Text) Pane(javafx.scene.layout.Pane) Country(eu.hansolo.tilesfx.tools.Country) LocationEvent(eu.hansolo.tilesfx.events.LocationEvent)

Aggregations

ChartData (eu.hansolo.tilesfx.chart.ChartData)18 Color (javafx.scene.paint.Color)12 Text (javafx.scene.text.Text)11 TileEvent (eu.hansolo.tilesfx.events.TileEvent)10 Helper (eu.hansolo.tilesfx.tools.Helper)9 Tile (eu.hansolo.tilesfx.Tile)8 Fonts (eu.hansolo.tilesfx.fonts.Fonts)8 List (java.util.List)8 Font (javafx.scene.text.Font)8 EventType (eu.hansolo.tilesfx.events.TileEvent.EventType)7 Locale (java.util.Locale)7 EventHandler (javafx.event.EventHandler)7 MouseEvent (javafx.scene.input.MouseEvent)7 ListChangeListener (javafx.collections.ListChangeListener)6 ChartDataEventListener (eu.hansolo.tilesfx.events.ChartDataEventListener)4 Country (eu.hansolo.tilesfx.tools.Country)3 Location (eu.hansolo.tilesfx.tools.Location)3 ZonedDateTime (java.time.ZonedDateTime)3 ArrayList (java.util.ArrayList)3 Insets (javafx.geometry.Insets)3