From b6a353815c95bcc63b5659e205e60b38e7da3890 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 28 Jun 2021 14:14:22 +0200 Subject: [PATCH] switch mempool size chart to kvB when max Y value is less than 1 MvB --- .../control/MempoolSizeFeeRatesChart.java | 59 ++++++++++++++----- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/MempoolSizeFeeRatesChart.java b/src/main/java/com/sparrowwallet/sparrow/control/MempoolSizeFeeRatesChart.java index 02a36a00..97134e50 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/MempoolSizeFeeRatesChart.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/MempoolSizeFeeRatesChart.java @@ -68,19 +68,6 @@ public class MempoolSizeFeeRatesChart extends StackedAreaChart { categoryAxis.setTickLabelRotation(0); NumberAxis numberAxis = (NumberAxis)getYAxis(); - numberAxis.setTickLabelFormatter(new StringConverter() { - @Override - public String toString(Number object) { - long vSizeBytes = object.longValue(); - return (vSizeBytes / (1000 * 1000)) + " MvB"; - } - - @Override - public Number fromString(String string) { - return null; - } - }); - this.setOnMouseMoved(mouseEvent -> { Point2D sceneCoords = this.localToScene(mouseEvent.getX(), mouseEvent.getY()); String category = categoryAxis.getValueForDisplay(categoryAxis.sceneToLocal(sceneCoords).getX()); @@ -116,6 +103,24 @@ public class MempoolSizeFeeRatesChart extends StackedAreaChart { previousFeeRate = feeRate; } + final double maxMvB = getMaxMvB(getData()); + numberAxis.setTickLabelFormatter(new StringConverter() { + @Override + public String toString(Number object) { + long vSizeBytes = object.longValue(); + if(maxMvB > 1.0) { + return (vSizeBytes / (1000 * 1000)) + " MvB"; + } else { + return (vSizeBytes / (1000)) + " kvB"; + } + } + + @Override + public Number fromString(String string) { + return null; + } + }); + if(categories.keySet().iterator().hasNext()) { String time = categories.values().iterator().next(); tooltip.setGraphic(new ChartTooltip(time, time, getData())); @@ -159,20 +164,42 @@ public class MempoolSizeFeeRatesChart extends StackedAreaChart { return categories; } + private static double getMaxMvB(List> seriesList) { + double maxTotal = 0d; + for(Series series : seriesList) { + maxTotal = Math.max(maxTotal, getMaxMvB(series)); + } + + return maxTotal; + } + + private static double getMaxMvB(Series series) { + double total = 0d; + for(XYChart.Data data : series.getData()) { + double mvb = data.getYValue().doubleValue() / (1000 * 1000); + total += mvb; + } + + return total; + } + private static class ChartTooltip extends VBox { public ChartTooltip(String category, String time, List> seriesList) { Label title = new Label("At " + time); HBox titleBox = new HBox(title); title.setStyle("-fx-alignment: center; -fx-font-size: 12px; -fx-padding: 0 0 5 0;"); getChildren().add(titleBox); + double maxMvB = getMaxMvB(seriesList); for(int i = seriesList.size() - 1; i >= 0; i--) { Series series = seriesList.get(i); for(XYChart.Data data : series.getData()) { if(data.getXValue().equals(category)) { - double mvb = data.getYValue().doubleValue() / (1000 * 1000); - if(mvb >= 0.01) { - Label label = new Label(series.getName() + ": " + String.format("%.2f", mvb) + " MvB"); + double kvb = data.getYValue().doubleValue() / 1000; + double mvb = kvb / 1000; + if(mvb >= 0.01 || (maxMvB < 1.0 && mvb > 0.001)) { + String amount = (maxMvB < 1.0 ? (int)kvb + " kvB" : String.format("%.2f", mvb) + " MvB"); + Label label = new Label(series.getName() + ": " + amount); Glyph circle = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.CIRCLE); if(i < 8) { circle.setStyle("-fx-text-fill: CHART_COLOR_" + (i+1));