Skip to content

Commit

Permalink
Updated CharityPageController
Browse files Browse the repository at this point in the history
Added method to set arc fill. Controller now sets both the arc fill and label of the key values correctly per Charity.
  • Loading branch information
roaraf committed Apr 18, 2026
1 parent bed9fe4 commit fa81001
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ntnu.systemutvikling.team6.controller;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
Expand All @@ -9,6 +11,7 @@
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.shape.Arc;
import ntnu.systemutvikling.team6.controller.components.LoaderScene;
import ntnu.systemutvikling.team6.models.Charity;

Expand All @@ -27,6 +30,18 @@ public class CharityPageController {

@FXML private Hyperlink CharityURL;

@FXML private Arc keyValueInnsamlingArc;

@FXML private Label keyValueInnsamlingLabel;

@FXML private Arc keyValueAdminArc;

@FXML private Label keyValueAdminLabel;

@FXML private Arc keyValueFormaalArc;

@FXML private Label keyValueFormaalLabel;

@FXML
public void initialize() {}

Expand Down Expand Up @@ -60,6 +75,25 @@ public void setCharity(Charity charity) {
Image placeholderImage = new Image(placeholderImagePath);
this.CharityLogo.setImage(placeholderImage);
}

// Sets key values to a List<Double>
String input = charity.getKeyValues();

String[] parts = input.split(":");
List<Double> numbers = new ArrayList<>();

for (String part : parts) {
part = part.replace(",", ".");
numbers.add(Double.parseDouble(part));
}

// Sets the value of each arc and label
setArc(keyValueInnsamlingArc, numbers.getFirst());
keyValueInnsamlingLabel.setText(String.format("%.1f%%", numbers.getFirst()));
setArc(keyValueAdminArc, numbers.get(1));
keyValueAdminLabel.setText(String.format("%.1f%%", numbers.get(1)));
setArc(keyValueFormaalArc, numbers.getLast());
keyValueFormaalLabel.setText(String.format("%.1f%%", numbers.getLast()));
}

/**
Expand Down Expand Up @@ -105,4 +139,9 @@ public void handleHomepageClick(ActionEvent event) {
e.printStackTrace();
}
}

private void setArc(Arc arc, double percent) {
double angle = -360 * (percent / 100.0);
arc.setLength(angle);
}
}

0 comments on commit fa81001

Please sign in to comment.