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 45ab0ff..1564f91 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 @@ -31,6 +31,8 @@ public class DashBoardView extends ViewElement { private NumberAxis yAxis; private Label selectedStockPriceLabel; private TextField shareQuantityInputField; + private Label lowPriceLabel; + private Label highPriceLabel; private Button m5QtyBtn; private Button m1QtyBtn; private Button p1QtyBtn; @@ -124,8 +126,8 @@ protected void initLayout() { selectedStockPriceLabel.getStyleClass().add("price-large"); HBox lowHighBox = new HBox(10); - Label lowPriceLabel = new Label("Low: 0.0 NOK"); - Label highPriceLabel = new Label("High: 0.0 NOK"); + lowPriceLabel = new Label("Low: 0.0 NOK"); + highPriceLabel = new Label("High: 0.0 NOK"); lowHighBox.getChildren().addAll(lowPriceLabel, highPriceLabel); priceStats.getChildren().addAll(selectedStockPriceLabel, lowHighBox); @@ -231,6 +233,8 @@ public void updateGraph() { dataSeries.getData().clear(); List prices = selectedStock.getHistoricalPrices(); updateStockPrice(prices.getLast().floatValue(), selectedStock.getLatestPriceChange().floatValue()); + setHighPriceLabel(selectedStock.getHighestPrice().floatValue()); + setLowPriceLabel(selectedStock.getLowestPrice().floatValue()); xAxis.setLowerBound(Math.max(1, prices.size() - 22)); xAxis.setUpperBound(Math.max(22, prices.size())); @@ -255,14 +259,28 @@ public void updateGraph() { } } - private void updateStockPrice(final float value, final float changeSinceLast) { + private void updateStockPrice(final float value, + final float changeSinceLast) { String changeSinceLastString; - if (changeSinceLast >= 0) { - changeSinceLastString = "+ " + Math.round(changeSinceLast*100f)/100f; + float oldVal = value - changeSinceLast; + float changePercent = (value/oldVal - 1) * 100; + if (changeSinceLast > 0) { + changeSinceLastString = "(+ " + Math.round(changePercent*100f)/100f + "%)"; + } else if (changeSinceLast < 0) { + changeSinceLastString = "(- " + Math.round(Math.abs(changePercent)*100f)/100f + "%)"; } else { - changeSinceLastString = "- " + Math.abs(changeSinceLast*100f)/100f; + changeSinceLastString = ""; } - selectedStockPriceLabel.setText(Float.toString(Math.round(value*100f)/100f) + "NOK (" + changeSinceLastString + ")"); + + selectedStockPriceLabel.setText(Float.toString(Math.round(value*100f)/100f) + "NOK " + changeSinceLastString); + } + + private void setLowPriceLabel(float value) { + lowPriceLabel.setText("Low: " + Math.round(value*100f)/100f + " NOK"); + } + + private void setHighPriceLabel(float value) { + highPriceLabel.setText("High: " + Math.round(value*100f)/100f + " NOK"); } public Stock getCurrentStock() {