From c7a3bc724e0f829c41f705c2df43e5fbf00035be Mon Sep 17 00:00:00 2001 From: EspenTinius Date: Wed, 27 May 2026 05:36:34 +0200 Subject: [PATCH] Revert "fiks" This reverts commit 8781ccfeeab9d7872f6d4f10a1aa68fe2e6a6808. --- .../g40/mappe/service/GameStateLoader.java | 8 ++-- .../view/widgets/dashboard/DashBoardView.java | 17 +------ .../view/widgets/stats/StatsController.java | 2 + .../mappe/view/widgets/stats/StatsView.java | 44 +------------------ 4 files changed, 7 insertions(+), 64 deletions(-) diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/service/GameStateLoader.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/service/GameStateLoader.java index 9ea6883..6f67aa5 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/service/GameStateLoader.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/service/GameStateLoader.java @@ -254,13 +254,11 @@ private void applySave(final SaveGame save) { if (save.getNetWorthHistory() != null && !save.getNetWorthHistory().isEmpty()) { player.setNetWorthHistory(save.getNetWorthHistory()); } else { - // No recorded history available - seed a single-point history - // anchored at the starting capital. The chart needs at least - // two points to draw a line, so it will stay empty until the - // first week is advanced, which is the correct behaviour for - // a brand-new game on week 1. + // No recorded history available - seed a minimal two-point + // history so the chart still has something to render. List seed = new ArrayList<>(); seed.add(BigDecimal.valueOf(save.getStartingCapital())); + seed.add(player.getNetWorth()); player.setNetWorthHistory(seed); } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardView.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardView.java index d8d1db9..1079fcf 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardView.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/dashboard/DashBoardView.java @@ -282,22 +282,7 @@ protected void initLayout() { yAxis.setTickMarkVisible(true); yAxis.setMinorTickVisible(false); yAxis.setAutoRanging(false); - // The default rotated axis label ("Price (NOK)" sideways along - // the y-axis) is hard to read, so we drop the label and suffix - // every tick value with " NOK" instead - same currency cue, but - // readable in the same horizontal orientation as the rest of the - // app. - yAxis.setTickLabelFormatter(new javafx.util.StringConverter() { - @Override - public String toString(final Number value) { - return Math.round(value.floatValue() * 100f) / 100f + " NOK"; - } - - @Override - public Number fromString(final String string) { - return 0; - } - }); + yAxis.setLabel("Price (NOK)"); chart = new LineChart<>(xAxis, yAxis); chart.setCreateSymbols(false); diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/stats/StatsController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/stats/StatsController.java index 5fe9992..b934d50 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/stats/StatsController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/stats/StatsController.java @@ -176,6 +176,7 @@ public void handleEvent(final EventData data) { balanceHistory.addAll(player.getNetWorthHistory()); } else { balanceHistory.add(player.getStartingMoney()); + balanceHistory.add(player.getNetWorth()); } pushSnapshot(); } @@ -276,6 +277,7 @@ public void handleContextUpdate(final Exchange updatedExchange, final Player upd this.balanceHistory.addAll(this.player.getNetWorthHistory()); } else { this.balanceHistory.add(this.player.getStartingMoney()); + this.balanceHistory.add(this.player.getNetWorth()); } pushSnapshot(); } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/stats/StatsView.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/stats/StatsView.java index 3122904..f3d6129 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/stats/StatsView.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/stats/StatsView.java @@ -452,21 +452,8 @@ private void renderBalanceChart() { balanceChartPane.getChildren().add(seg); } - // X-axis labels (week numbers). When the chart shows many weeks - // the labels overlap and become unreadable, so we thin them out: - // pick a step that guarantees at least ~28 px between labels and - // always render the first and last week. To avoid the last-week - // label colliding with the previous step-aligned label, we skip - // any step label that lands within one stride of the final week. - int xLabelStep = computeXLabelStep(n, stepX); - int lastIndex = n - 1; + // X-axis labels (week numbers). for (int i = 0; i < n; i++) { - boolean isEdge = (i == 0 || i == lastIndex); - boolean isStepAligned = (i % xLabelStep == 0) - && (lastIndex - i >= xLabelStep || i == 0); - if (!isEdge && !isStepAligned) { - continue; - } double x = padL + i * stepX; Text xLabel = new Text(0, h - 6, String.valueOf(i + 1)); xLabel.getStyleClass().add("stats-chart-axis"); @@ -662,35 +649,6 @@ private static String stripTrailingZeros(final BigDecimal v) { return v.stripTrailingZeros().toPlainString(); } - /** - * Picks a stride that lets us draw every {@code step}-th week label - * along the x-axis without overlap. - * - *

Targets at least ~28 px of horizontal space between adjacent - * rendered labels. The step is also rounded to a "nice" value - * (1, 2, 5, 10, 20, 50, ...) so the labels read as a clean - * progression rather than landing on awkward weeks.

- * - * @param n the total number of data points on the chart. - * @param stepX the horizontal spacing between consecutive points. - * @return the index stride to use when rendering x-axis labels. - * */ - private static int computeXLabelStep(final int n, final double stepX) { - final double minLabelSpacing = 28.0; - if (stepX >= minLabelSpacing || n <= 1) { - return 1; - } - int rawStep = (int) Math.ceil(minLabelSpacing / stepX); - // Snap to a nice 1-2-5 progression so labels land on tidy weeks. - int[] niceSteps = {1, 2, 5, 10, 20, 50, 100}; - for (int s : niceSteps) { - if (s >= rawStep) { - return s; - } - } - return rawStep; - } - /** Internal data carrier for a single pie slice. */ private static final class Segment { final String label;