From 05154cf6aa2e0a930a5b97f99da2004977dbcd69 Mon Sep 17 00:00:00 2001 From: Martin Beyer Date: Wed, 10 Jun 2020 11:55:08 +0200 Subject: [PATCH] Added Graph to statistics window --- .../VaultStatisticsController.java | 55 ++++++++++++++++++- .../VaultStatisticsModule.java | 4 +- .../ui/src/main/resources/css/light_theme.css | 34 ++++++++++++ .../main/resources/fxml/vault_statistics.fxml | 18 ++++++ .../main/resources/i18n/strings.properties | 6 ++ 5 files changed, 113 insertions(+), 4 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsController.java b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsController.java index 30292f4c7..fcf941590 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsController.java @@ -1,5 +1,12 @@ package org.cryptomator.ui.vaultstatistics; +import javafx.beans.property.LongProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.fxml.FXML; +import javafx.scene.chart.LineChart; +import javafx.scene.chart.XYChart; import javafx.stage.Stage; import org.cryptomator.common.vaults.Vault; import org.cryptomator.ui.common.FxController; @@ -10,11 +17,55 @@ import javax.inject.Inject; public class VaultStatisticsController implements FxController { private final Stage window; - private final Vault vault; + private final ReadOnlyObjectProperty vault; + @FXML + private LineChart lineGraph; + private final LongProperty currentReadData; + private final LongProperty currentWriteData; + private final XYChart.Series readData; + private final XYChart.Series writeData; + private long timeAtStartOfTracking; @Inject - public VaultStatisticsController(@VaultStatisticsWindow Stage window, @VaultStatisticsWindow Vault vault) { + public VaultStatisticsController(@VaultStatisticsWindow Stage window, ObjectProperty vault) { this.window = window; this.vault = vault; + + readData = new XYChart.Series<>(); + readData.setName("Read Data"); // For Legend + //TODO Add Name to strings.properties + writeData = new XYChart.Series<>(); + writeData.setName("Write Data"); + //TODO Add Name to strings.properties + + + currentReadData = new SimpleLongProperty(); + currentReadData.bind(getVault().getStats().bytesPerSecondReadProperty()); + currentReadData.addListener((observable, oldValue, newValue) -> updateReadWriteData()); + + currentWriteData = new SimpleLongProperty(); + currentWriteData.bind(getVault().getStats().bytesPerSecondWrittenProperty()); + currentWriteData.addListener((observable, oldValue, newValue) -> updateReadWriteData()); + } + + @FXML + public void initialize() { + window.setTitle(window.getTitle() + " - " + vault.get().getDisplayableName()); + } + + public Vault getVault() { + return vault.get(); + } + + private void updateReadWriteData() { + //So the graphs start at x = 0 + if (timeAtStartOfTracking == 0) { + timeAtStartOfTracking = System.currentTimeMillis(); + } + readData.getData().add(new XYChart.Data((System.currentTimeMillis() - timeAtStartOfTracking) / 1000.0, ((getVault().getStats().bytesPerSecondReadProperty().get()) / 1024.0))); + writeData.getData().add(new XYChart.Data((System.currentTimeMillis() - timeAtStartOfTracking) / 1000.0, ((getVault().getStats().bytesPerSecondWrittenProperty().get()) / 1024.0))); + lineGraph.getData().addAll(writeData, readData); + //TODO + //Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Duplicate series added } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsModule.java b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsModule.java index a129c0eb7..81a9724f6 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsModule.java @@ -35,9 +35,9 @@ abstract class VaultStatisticsModule { @VaultStatisticsScoped static Stage provideStage(StageFactory factory, @MainWindow Stage owner, ResourceBundle resourceBundle) { Stage stage = factory.create(); - stage.setTitle(resourceBundle.getString("removeVault.title")); + stage.setTitle(resourceBundle.getString("vaultstatistics.title")); stage.setResizable(false); - stage.initModality(Modality.APPLICATION_MODAL); + stage.initModality(Modality.NONE); stage.initOwner(owner); return stage; } diff --git a/main/ui/src/main/resources/css/light_theme.css b/main/ui/src/main/resources/css/light_theme.css index 42f93bfbf..f87d2338b 100644 --- a/main/ui/src/main/resources/css/light_theme.css +++ b/main/ui/src/main/resources/css/light_theme.css @@ -868,3 +868,37 @@ -fx-background-color: PROGRESS_BAR_BG; -fx-background-radius: 4px; } +/******************************************************************************* + * * + * Vault Statistics * + * * + ******************************************************************************/ +.chart-plot-background { + -fx-background-color: #F7F7F7; +} +.chart-vertical-grid-lines { + -fx-stroke: #49B04A; +} +.chart-horizontal-grid-lines { + -fx-stroke: #49B04A; +} +.chart-alternative-row-fill { + -fx-fill: #E1E1E1; + -fx-stroke: transparent; + -fx-stroke-width: 0; +} +.default-color0.chart-series-line { -fx-stroke: #2D4D2E; } +.default-color1.chart-series-line { -fx-stroke: #66CC68 ; } + +.chart-legend { + -fx-background-color: transparent; + -fx-padding: 20px; +} + +.chart-legend-item-symbol{ + -fx-background-radius: 0; +} + +.chart-legend-item{ + -fx-text-fill: #191970; +} diff --git a/main/ui/src/main/resources/fxml/vault_statistics.fxml b/main/ui/src/main/resources/fxml/vault_statistics.fxml index 4d5edfde6..b4891eec8 100644 --- a/main/ui/src/main/resources/fxml/vault_statistics.fxml +++ b/main/ui/src/main/resources/fxml/vault_statistics.fxml @@ -1,6 +1,9 @@ + + + @@ -20,4 +23,19 @@ + + + + + + + + + + + + diff --git a/main/ui/src/main/resources/i18n/strings.properties b/main/ui/src/main/resources/i18n/strings.properties index 416971ef2..133b99c23 100644 --- a/main/ui/src/main/resources/i18n/strings.properties +++ b/main/ui/src/main/resources/i18n/strings.properties @@ -160,6 +160,12 @@ preferences.donationKey.getDonationKey=Get a donation key ## About preferences.about=About +# Vault Statistics +vaultstatistics.title=Vault Statistics +vaultstatistics.xAxisTimeLabel=Seconds +vaultstatistics.yAxisTimeLabel=Throughput in KiB +vaultstatistics.throughputTitle=Read and Writes + # Main Window main.closeBtn.tooltip=Close main.minimizeBtn.tooltip=Minimize