From 41686a8534c209234bb6d67564a884ac9dfc03c0 Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Sat, 28 Oct 2023 17:12:41 +0800 Subject: [PATCH] Add reactive score component --- .../seedu/staffsnap/ui/ApplicantCard.java | 29 +++++++++++++++++-- .../seedu/staffsnap/ui/ApplicantCardTest.java | 18 ++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src/test/java/seedu/staffsnap/ui/ApplicantCardTest.java diff --git a/src/main/java/seedu/staffsnap/ui/ApplicantCard.java b/src/main/java/seedu/staffsnap/ui/ApplicantCard.java index f0d0f0bf0b9..46e9c8b01e9 100644 --- a/src/main/java/seedu/staffsnap/ui/ApplicantCard.java +++ b/src/main/java/seedu/staffsnap/ui/ApplicantCard.java @@ -63,6 +63,8 @@ public ApplicantCard(Applicant applicant, int displayedIndex) { displayApplicantInterviews(); displayApplicantScore(); } + + private void displayApplicantId(int displayedIndex) { id.setText(displayedIndex + ". "); } @@ -173,11 +175,32 @@ private void displayApplicantScore() { ratingLabel.getStyleClass().add("overall_rating_label"); Label scoreLabel = new Label(); - scoreLabel.setText(applicant.getScore().hasRating() - ? applicant.getScore().toString() - : "-"); + String labelText = applicant.getScore().hasRating() ? applicant.getScore().toString() : "N.A."; + scoreLabel.setText(labelText); scoreLabel.getStyleClass().add("score_label"); + Color[] colours = { Color.TRANSPARENT, Color.web("#1a8cff"), Color.web("#3333cc"), + Color.web("#7a00cc"), Color.web("#cc0099"), Color.web("#ff0066"), + Color.web("#ff6600"), Color.web("#ffcc00"), Color.web("#ccff33"), + Color.web("#66ff33"), Color.web("#00ffcc")}; + + for (int i = 0; i < 10; i++) { + Arc arc = new Arc(0, 0, 43, 43, + 90 + i * 36, -30); + arc.setType(ArcType.ROUND); + arc.setFill(Color.GREY); + stackedArcs.getChildren().add(arc); + } + + double applicantRating = labelText.equals("N.A.") ? 0 : Double.parseDouble(labelText); + double ratingArcLength = -360 * (applicantRating / 10); + Arc ratingArc = new Arc(0, 0, 43, 43, 90, ratingArcLength); + Color arcColour = colours[(int) Math.floor(applicantRating)]; + ratingArc.setFill(arcColour); + ratingArc.setType(ArcType.ROUND); + + stackedArcs.getChildren().add(ratingArc); + overallRating.getChildren().addAll(stackedArcs, innerCircle, scoreLabel); } diff --git a/src/test/java/seedu/staffsnap/ui/ApplicantCardTest.java b/src/test/java/seedu/staffsnap/ui/ApplicantCardTest.java new file mode 100644 index 00000000000..67da21324fe --- /dev/null +++ b/src/test/java/seedu/staffsnap/ui/ApplicantCardTest.java @@ -0,0 +1,18 @@ +package seedu.staffsnap.ui; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static seedu.staffsnap.testutil.Assert.assertThrows; + +import java.net.URL; +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import javafx.fxml.FXML; +import seedu.staffsnap.MainApp; + +public class ApplicantCardTest { + +}