mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-05 05:46:44 +00:00
switch mempool size chart to kvB when max Y value is less than 1 MvB
This commit is contained in:
parent
ea2f858dc9
commit
b6a353815c
1 changed files with 43 additions and 16 deletions
|
@ -68,19 +68,6 @@ public class MempoolSizeFeeRatesChart extends StackedAreaChart<String, Number> {
|
||||||
categoryAxis.setTickLabelRotation(0);
|
categoryAxis.setTickLabelRotation(0);
|
||||||
|
|
||||||
NumberAxis numberAxis = (NumberAxis)getYAxis();
|
NumberAxis numberAxis = (NumberAxis)getYAxis();
|
||||||
numberAxis.setTickLabelFormatter(new StringConverter<Number>() {
|
|
||||||
@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 -> {
|
this.setOnMouseMoved(mouseEvent -> {
|
||||||
Point2D sceneCoords = this.localToScene(mouseEvent.getX(), mouseEvent.getY());
|
Point2D sceneCoords = this.localToScene(mouseEvent.getX(), mouseEvent.getY());
|
||||||
String category = categoryAxis.getValueForDisplay(categoryAxis.sceneToLocal(sceneCoords).getX());
|
String category = categoryAxis.getValueForDisplay(categoryAxis.sceneToLocal(sceneCoords).getX());
|
||||||
|
@ -116,6 +103,24 @@ public class MempoolSizeFeeRatesChart extends StackedAreaChart<String, Number> {
|
||||||
previousFeeRate = feeRate;
|
previousFeeRate = feeRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final double maxMvB = getMaxMvB(getData());
|
||||||
|
numberAxis.setTickLabelFormatter(new StringConverter<Number>() {
|
||||||
|
@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()) {
|
if(categories.keySet().iterator().hasNext()) {
|
||||||
String time = categories.values().iterator().next();
|
String time = categories.values().iterator().next();
|
||||||
tooltip.setGraphic(new ChartTooltip(time, time, getData()));
|
tooltip.setGraphic(new ChartTooltip(time, time, getData()));
|
||||||
|
@ -159,20 +164,42 @@ public class MempoolSizeFeeRatesChart extends StackedAreaChart<String, Number> {
|
||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static double getMaxMvB(List<Series<String, Number>> seriesList) {
|
||||||
|
double maxTotal = 0d;
|
||||||
|
for(Series<String, Number> series : seriesList) {
|
||||||
|
maxTotal = Math.max(maxTotal, getMaxMvB(series));
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double getMaxMvB(Series<String, Number> series) {
|
||||||
|
double total = 0d;
|
||||||
|
for(XYChart.Data<String, Number> data : series.getData()) {
|
||||||
|
double mvb = data.getYValue().doubleValue() / (1000 * 1000);
|
||||||
|
total += mvb;
|
||||||
|
}
|
||||||
|
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
private static class ChartTooltip extends VBox {
|
private static class ChartTooltip extends VBox {
|
||||||
public ChartTooltip(String category, String time, List<Series<String, Number>> seriesList) {
|
public ChartTooltip(String category, String time, List<Series<String, Number>> seriesList) {
|
||||||
Label title = new Label("At " + time);
|
Label title = new Label("At " + time);
|
||||||
HBox titleBox = new HBox(title);
|
HBox titleBox = new HBox(title);
|
||||||
title.setStyle("-fx-alignment: center; -fx-font-size: 12px; -fx-padding: 0 0 5 0;");
|
title.setStyle("-fx-alignment: center; -fx-font-size: 12px; -fx-padding: 0 0 5 0;");
|
||||||
getChildren().add(titleBox);
|
getChildren().add(titleBox);
|
||||||
|
double maxMvB = getMaxMvB(seriesList);
|
||||||
|
|
||||||
for(int i = seriesList.size() - 1; i >= 0; i--) {
|
for(int i = seriesList.size() - 1; i >= 0; i--) {
|
||||||
Series<String, Number> series = seriesList.get(i);
|
Series<String, Number> series = seriesList.get(i);
|
||||||
for(XYChart.Data<String, Number> data : series.getData()) {
|
for(XYChart.Data<String, Number> data : series.getData()) {
|
||||||
if(data.getXValue().equals(category)) {
|
if(data.getXValue().equals(category)) {
|
||||||
double mvb = data.getYValue().doubleValue() / (1000 * 1000);
|
double kvb = data.getYValue().doubleValue() / 1000;
|
||||||
if(mvb >= 0.01) {
|
double mvb = kvb / 1000;
|
||||||
Label label = new Label(series.getName() + ": " + String.format("%.2f", mvb) + " MvB");
|
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);
|
Glyph circle = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.CIRCLE);
|
||||||
if(i < 8) {
|
if(i < 8) {
|
||||||
circle.setStyle("-fx-text-fill: CHART_COLOR_" + (i+1));
|
circle.setStyle("-fx-text-fill: CHART_COLOR_" + (i+1));
|
||||||
|
|
Loading…
Reference in a new issue