From b07da1738de582da548f4e6a892fa32e74aaa6bf Mon Sep 17 00:00:00 2001 From: David Gerber Date: Sat, 4 Jan 2025 00:15:11 +0100 Subject: [PATCH] Fix RTT statistics Make them work more than once. Also make the legend deselectable. --- .../statistics/StatisticsMapper.java | 2 +- .../StatisticsMainWindowController.java | 6 ++++- .../statistics/StatisticsRttController.java | 23 +++++++++++++++++++ .../StatisticsTurtleController.java | 12 ++++++---- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/xeres/app/api/controller/statistics/StatisticsMapper.java b/app/src/main/java/io/xeres/app/api/controller/statistics/StatisticsMapper.java index cc9995a20..6fac252e0 100644 --- a/app/src/main/java/io/xeres/app/api/controller/statistics/StatisticsMapper.java +++ b/app/src/main/java/io/xeres/app/api/controller/statistics/StatisticsMapper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 by David Gerber - https://zapek.com + * Copyright (c) 2024-2025 by David Gerber - https://zapek.com * * This file is part of Xeres. * diff --git a/ui/src/main/java/io/xeres/ui/controller/statistics/StatisticsMainWindowController.java b/ui/src/main/java/io/xeres/ui/controller/statistics/StatisticsMainWindowController.java index 736b935fd..2a2996c9c 100644 --- a/ui/src/main/java/io/xeres/ui/controller/statistics/StatisticsMainWindowController.java +++ b/ui/src/main/java/io/xeres/ui/controller/statistics/StatisticsMainWindowController.java @@ -21,6 +21,7 @@ import io.xeres.ui.controller.WindowController; import javafx.fxml.FXML; +import javafx.scene.control.TabPane; import net.rgielen.fxweaver.core.FxmlView; import org.springframework.stereotype.Component; @@ -28,6 +29,9 @@ @FxmlView(value = "/view/statistics/main.fxml") public class StatisticsMainWindowController implements WindowController { + @FXML + private TabPane tabPane; + // This field name to get the controller is some black magic, see last answer at https://stackoverflow.com/questions/40754454/get-controller-instance-from-node @FXML private StatisticsTurtleController statisticsTurtleController; @@ -38,7 +42,7 @@ public class StatisticsMainWindowController implements WindowController @Override public void initialize() { - // XXX: the start/stop should be done on tab switch maybe... but check later on when I have more tabs + } @Override diff --git a/ui/src/main/java/io/xeres/ui/controller/statistics/StatisticsRttController.java b/ui/src/main/java/io/xeres/ui/controller/statistics/StatisticsRttController.java index 4d4e8fa0d..023bad609 100644 --- a/ui/src/main/java/io/xeres/ui/controller/statistics/StatisticsRttController.java +++ b/ui/src/main/java/io/xeres/ui/controller/statistics/StatisticsRttController.java @@ -25,9 +25,11 @@ import io.xeres.ui.controller.Controller; import javafx.application.Platform; import javafx.fxml.FXML; +import javafx.scene.Cursor; import javafx.scene.chart.LineChart; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; +import javafx.scene.control.Label; import net.rgielen.fxweaver.core.FxmlView; import org.springframework.stereotype.Component; @@ -108,6 +110,7 @@ public void start() public void stop() { ExecutorUtils.cleanupExecutor(executorService); + peerSeries.clear(); } private XYChart.Series createSeries(RttPeer rttPeer) @@ -115,9 +118,29 @@ private XYChart.Series createSeries(RttPeer rttPeer) var series = new XYChart.Series(); series.setName(rttPeer.name()); lineChart.getData().add(series); + setLegend(); return series; } + private void setLegend() + { + lineChart.lookupAll("Label.chart-legend-item").forEach(node -> { + if (node instanceof Label label && label.getCursor() == null) // Make sure we only do the job once for each + { + label.setCursor(Cursor.HAND); + label.setOnMouseClicked(event -> { + label.setOpacity(label.getOpacity() > 0.75 ? 0.5 : 1.0); + lineChart.getData().forEach(series -> { + if (series.getName().equals(label.getText())) + { + series.getNode().setVisible(!series.getNode().isVisible()); + } + }); + }); + } + }); + } + private static void updateData(XYChart.Series series, float value) { series.getData().forEach(numberNumberData -> numberNumberData.setXValue(numberNumberData.getXValue().intValue() - UPDATE_IN_SECONDS)); diff --git a/ui/src/main/java/io/xeres/ui/controller/statistics/StatisticsTurtleController.java b/ui/src/main/java/io/xeres/ui/controller/statistics/StatisticsTurtleController.java index abebd82ce..0a6036aa5 100644 --- a/ui/src/main/java/io/xeres/ui/controller/statistics/StatisticsTurtleController.java +++ b/ui/src/main/java/io/xeres/ui/controller/statistics/StatisticsTurtleController.java @@ -31,8 +31,6 @@ import javafx.scene.chart.XYChart; import javafx.scene.control.Label; import net.rgielen.fxweaver.core.FxmlView; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import java.util.Map; @@ -43,8 +41,6 @@ @FxmlView(value = "/view/statistics/turtle.fxml") public class StatisticsTurtleController implements Controller { - private static final Logger log = LoggerFactory.getLogger(StatisticsTurtleController.class); - private static final int UPDATE_IN_SECONDS = 2; private static final int DATA_WINDOW_SIZE = 60; // 2 minutes of data (one data each 2 seconds) @@ -150,6 +146,14 @@ public void start() public void stop() { ExecutorUtils.cleanupExecutor(executorService); + + dataDownload.getData().clear(); + dataUpload.getData().clear(); + forwardTotal.getData().clear(); + tunnelRequestsDownload.getData().clear(); + tunnelRequestsUpload.getData().clear(); + searchRequestsDownload.getData().clear(); + searchRequestsUpload.getData().clear(); } private static void updateData(XYChart.Series series, float value)