Changed time interval cutoff.
This commit is contained in:
parent
6e862a2709
commit
d360de5d6f
|
@ -3,7 +3,6 @@ package com.andrewlalis.perfin.view.component.module;
|
|||
import com.andrewlalis.perfin.data.AccountRepository;
|
||||
import com.andrewlalis.perfin.data.TimestampRange;
|
||||
import com.andrewlalis.perfin.data.TransactionRepository;
|
||||
import com.andrewlalis.perfin.data.util.ColorUtil;
|
||||
import com.andrewlalis.perfin.model.Profile;
|
||||
import com.andrewlalis.perfin.model.Transaction;
|
||||
import javafx.application.Platform;
|
||||
|
@ -13,9 +12,11 @@ import javafx.scene.chart.*;
|
|||
import javafx.scene.control.ChoiceBox;
|
||||
import javafx.scene.layout.Pane;
|
||||
|
||||
import java.time.*;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -86,28 +87,6 @@ public class TotalAssetsGraphModule extends DashboardModule {
|
|||
if (savedTimeRangeLabel != null && Arrays.stream(TIME_RANGE_OPTIONS).anyMatch(o -> o.name().equals(savedTimeRangeLabel))) {
|
||||
timeRangeChoiceBox.getSelectionModel().select(savedTimeRangeLabel);
|
||||
}
|
||||
|
||||
// TODO: Extract logic below.
|
||||
totalAssetDataPoints.clear();
|
||||
String[] dateLabels = new String[12];
|
||||
double[] values = new double[12];
|
||||
CompletableFuture<?>[] futures = new CompletableFuture[12];
|
||||
for (int i = 0; i < 12; i++) {
|
||||
final int idx = i;
|
||||
Instant timestamp = Instant.now().minus((12 - i - 1) * 30, ChronoUnit.DAYS);
|
||||
dateLabels[i] = LocalDate.from(timestamp.atZone(ZoneId.systemDefault())).toString();
|
||||
futures[i] = Profile.getCurrent().dataSource().getCombinedAccountBalances(timestamp)
|
||||
.thenAccept(moneyValues -> {
|
||||
values[idx] = moneyValues.getFirst().amount().doubleValue();
|
||||
});
|
||||
}
|
||||
CompletableFuture.allOf(futures).thenRun(() -> {
|
||||
List<XYChart.Data<String, Number>> dataPoints = new ArrayList<>(12);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
dataPoints.add(new XYChart.Data<>(dateLabels[i], values[i]));
|
||||
}
|
||||
Platform.runLater(() -> totalAssetDataPoints.addAll(dataPoints));
|
||||
});
|
||||
}
|
||||
|
||||
private void renderChart() {
|
||||
|
@ -120,7 +99,7 @@ public class TotalAssetsGraphModule extends DashboardModule {
|
|||
|
||||
getSelectedTimestampRange().thenAccept(range -> {
|
||||
Duration rangeDuration = Duration.between(range.start(), range.end());
|
||||
boolean useMonths = rangeDuration.dividedBy(Duration.ofDays(1)) > 90;
|
||||
boolean useMonths = rangeDuration.dividedBy(Duration.ofDays(1)) > 365;
|
||||
|
||||
|
||||
List<CompletableFuture<Number>> dataFutures = new ArrayList<>();
|
||||
|
|
Loading…
Reference in New Issue