Skip to content

Commit

Permalink
Feat: Updated price section
Browse files Browse the repository at this point in the history
Updated price section of dashboard view to show percent change since last week as well as highest and lowest price of the selected stock
  • Loading branch information
tommyah committed May 15, 2026
1 parent 91aff4f commit 258fbaf
Showing 1 changed file with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class DashBoardView extends ViewElement<HBox, DashBoardActions> {
private NumberAxis yAxis;
private Label selectedStockPriceLabel;
private TextField shareQuantityInputField;
private Label lowPriceLabel;
private Label highPriceLabel;
private Button m5QtyBtn;
private Button m1QtyBtn;
private Button p1QtyBtn;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -231,6 +233,8 @@ public void updateGraph() {
dataSeries.getData().clear();
List<BigDecimal> 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()));

Expand All @@ -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() {
Expand Down

0 comments on commit 258fbaf

Please sign in to comment.