Skip to content

Commit

Permalink
Feat: Fixed Stats jittering and valuta
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 27, 2026
1 parent 28ce6a1 commit c2147f0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,8 @@ public ComboBox<DashBoardTimeRange> getTimeRangeSelector() {
* @param amount the amount of shares to show.
* */
private String formatShares(final float amount) {
String formatted = String.format(java.util.Locale.US, "%.3f", amount);
return formatted.replaceAll("0+$", "").replaceAll("\\.$", "");
String formatted = String.format(java.util.Locale.of("no", "NO"), "%.3f", amount);
return formatted.replaceAll("0+$", "").replaceAll(",$", "");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected void initLayout() {
VBox balanceInfo = new VBox();

titleLabel = new Label("Balance/NetWorth");
balanceLabel = new Label("0$");
balanceLabel = new Label("0NOK");
statusLabel = new Label(PlayerStatus.NOOB.getDisplayName());

Region spacerL = new Region();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private VBox buildStockCard(final Stock stock) {
VBox tickerBox = new VBox(2, ticker, company);
tickerBox.setAlignment(Pos.TOP_LEFT);

Label price = new Label(String.format("$%.2f", stock.getSalesPrice().doubleValue()));
Label price = new Label(String.format("%.2f NOK", stock.getSalesPrice().doubleValue()));
price.getStyleClass().add("market-price");

Region headerSpacer = new Region();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,17 @@ private VBox buildChartPanel() {
balanceChartPane = new Pane();
balanceChartPane.setMinHeight(120);
VBox.setVgrow(balanceChartPane, Priority.ALWAYS);
// Re-render whenever the area is resized.
balanceChartPane.widthProperty().addListener((obs, o, n) -> renderBalanceChart());
balanceChartPane.heightProperty().addListener((obs, o, n) -> renderBalanceChart());
// Re-render whenever the area is resized. (Ignores changes under 2 pixels)
balanceChartPane.widthProperty().addListener((obs, o, n) -> {
if (Math.abs(n.doubleValue() - o.doubleValue()) > 2.0) {
renderBalanceChart();
}
});
balanceChartPane.heightProperty().addListener((obs, o, n) -> {
if (Math.abs(n.doubleValue() - o.doubleValue()) > 2.0) {
renderBalanceChart();
}
});

VBox panel = new VBox(6, title, balanceChartPane);
panel.getStyleClass().add("stats-panel");
Expand Down Expand Up @@ -407,7 +415,7 @@ private void renderBalanceChart() {
balanceChartPane.getChildren().add(grid);

double v = min + range * i / yTicks;
Text yLabel = new Text(0, y + 3, "$" + (long) v);
Text yLabel = new Text(0, y + 3, "NOK" + (long) v);
yLabel.getStyleClass().add("stats-chart-axis");
yLabel.setX(padL - 4 - yLabel.getLayoutBounds().getWidth());
balanceChartPane.getChildren().add(yLabel);
Expand Down Expand Up @@ -564,7 +572,7 @@ private HBox buildHoldingRow(final HoldingData h) {
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);

Label value = new Label(String.format("$%.2f", h.getValue().doubleValue()));
Label value = new Label(String.format("%.2f NOK", h.getValue().doubleValue()));
value.getStyleClass().add("stats-holding-value");

boolean up = h.getPnl().signum() >= 0;
Expand Down Expand Up @@ -600,11 +608,11 @@ private static BigDecimal sumCost(final List<HoldingData> holdings) {
}

private static String formatMoney(final BigDecimal v) {
return "$" + (long) v.doubleValue();
return (long) v.doubleValue() + "NOK";
}

private static String formatSigned(final double v) {
return (v >= 0 ? "+" : "") + "$" + (long) v;
return (v >= 0 ? "+" : "") + (long) v + "NOK";
}

private static String formatSignedPct(final double v) {
Expand Down

0 comments on commit c2147f0

Please sign in to comment.