Skip to content

Commit

Permalink
Fix RTT statistics
Browse files Browse the repository at this point in the history
Make them work more than once. Also make the legend deselectable.
  • Loading branch information
zapek committed Jan 3, 2025
1 parent d246d23 commit b07da17
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@

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;

@Component
@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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -108,16 +110,37 @@ public void start()
public void stop()
{
ExecutorUtils.cleanupExecutor(executorService);
peerSeries.clear();
}

private XYChart.Series<Number, Number> createSeries(RttPeer rttPeer)
{
var series = new XYChart.Series<Number, Number>();
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<Number, Number> series, float value)
{
series.getData().forEach(numberNumberData -> numberNumberData.setXValue(numberNumberData.getXValue().intValue() - UPDATE_IN_SECONDS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)

Expand Down Expand Up @@ -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<Number, Number> series, float value)
Expand Down

0 comments on commit b07da17

Please sign in to comment.