Skip to content

Commit

Permalink
Merge pull request AY2425S1-CS2103T-T14-4#178 from iamdiluxedbutcoole…
Browse files Browse the repository at this point in the history
…r/ui-diagram-update-panel

Add panel and graph
  • Loading branch information
iamdiluxedbutcooler authored Nov 6, 2024
2 parents a1a7567 + 03b5ff6 commit a9f7338
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 15 deletions.
67 changes: 65 additions & 2 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.logging.Logger;

import javafx.application.Platform;
import javafx.collections.ListChangeListener;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.MenuItem;
Expand Down Expand Up @@ -30,19 +32,30 @@ public class MainWindow extends UiPart<Stage> {

private final Logger logger = LogsCenter.getLogger(getClass());

private final ListChangeListener<Client> clientListListener = change -> {
while (change.next()) {
if (change.wasAdded() || change.wasRemoved() || change.wasUpdated()) {
updateStatusChart();
}
}
};

private Stage primaryStage;
private Logic logic;

private ClientListPanel clientListPanel;
private ClientDetailPanel clientDetailPanel;
private ResultDisplay resultDisplay;
private StatusPieChart statusPieChart;
private HelpWindow helpWindow;

@FXML
private StackPane commandBoxPlaceholder;

@FXML
private MenuItem helpMenuItem;
@FXML
private SplitPane topSplitPane;

@FXML
private SplitPane splitPane;
Expand All @@ -55,6 +68,8 @@ public class MainWindow extends UiPart<Stage> {

@FXML
private StackPane resultDisplayPlaceholder;
@FXML
private StackPane statusChartPlaceholder;

@FXML
private StackPane statusbarPlaceholder;
Expand All @@ -76,6 +91,7 @@ public MainWindow(Stage primaryStage, Logic logic) {
setWindowDefaultSize(logic.getGuiSettings());
setAccelerators();
helpWindow = new HelpWindow();
logic.getFilteredClientList().addListener(clientListListener);
}

/**
Expand Down Expand Up @@ -128,15 +144,49 @@ void fillInnerParts() {
CommandBox commandBox = new CommandBox(this::executeCommand);
commandBoxPlaceholder.getChildren().add(commandBox.getRoot());

splitPane.setDividerPositions(0.6);
statusPieChart = new StatusPieChart();
statusChartPlaceholder.getChildren().add(statusPieChart.getRoot());

setupSplitPanes();
splitPane.setDividerPositions(0.5);

splitPane.getDividers().get(0).positionProperty().addListener((observable, oldValue, newValue) -> {
splitPane.setDividerPositions(0.6);
splitPane.setDividerPositions(0.5);
});

splitPane.getItems().remove(clientDetailsPanelPlaceholder);
topSplitPane.getStyleClass().add("top-split-pane");
statusChartPlaceholder.getStyleClass().add("chart-container");
updateStatusChart();
}

/**
* Updates the status pie chart with current data
*/
private void updateStatusChart() {
final int[] counts = new int[3]; // [none, nonUrgent, urgent]

for (Client client : logic.getFilteredClientList()) {
switch (client.getStatus().status) {
case NONE -> counts[0]++;
case NON_URGENT -> counts[1]++;
case URGENT -> counts[2]++;
default -> {
logger.warning("Unexpected status value: " + client.getStatus().status);
}
}
}

Platform.runLater(() -> {
statusPieChart.updateChartData(counts[0], counts[1], counts[2]);

int total = counts[0] + counts[1] + counts[2];
logger.info(String.format("Chart updated - None: %d, Non-Urgent: %d, Urgent: %d (Total: %d)",
counts[0], counts[1], counts[2], total));
});
}


/**
* Sets the default size based on {@code guiSettings}.
*/
Expand Down Expand Up @@ -245,4 +295,17 @@ private CommandResult executeCommand(String commandText) throws CommandException
throw e;
}
}

/**
* Sets up the split panes and their divider positions
*/
private void setupSplitPanes() {
topSplitPane.setDividerPositions(0.8);

topSplitPane.getDividers().get(0).positionProperty().addListener((observable, oldValue, newValue) -> {
if (Math.abs(newValue.doubleValue() - 0.8) > 0.05) {
Platform.runLater(() -> topSplitPane.setDividerPositions(0.8));
}
});
}
}
90 changes: 90 additions & 0 deletions src/main/java/seedu/address/ui/StatusPieChart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package seedu.address.ui;

import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.geometry.Side;
import javafx.scene.chart.PieChart;
import javafx.scene.control.Label;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;

/**
* Panel containing the status distribution pie chart.
*/
public class StatusPieChart extends UiPart<Region> {

private static final String FXML = "StatusPieChart.fxml";
@FXML
private VBox chartContainer;

@FXML
private Label chartTitle;

@FXML
private PieChart statusChart;

/**
* Creates a new StatusPieChart.
* Initializes the chart with default settings by calling setupChart().
*/
public StatusPieChart() {
super(FXML);
setupChart();
}

/**
* Sets up the initial configuration of the pie chart.
* This includes:
* - Setting the chart title
* - Configuring chart display properties (labels, legend, size)
* - Setting up the chart container
* - Applying custom styling
*/
private void setupChart() {
chartTitle.setText("CLIENT STATUS");
statusChart.setTitle("");
statusChart.setLabelsVisible(false);
statusChart.setLegendVisible(true);
statusChart.setLegendSide(Side.BOTTOM);

statusChart.setPrefSize(200, 200);
statusChart.setMinSize(180, 180);
statusChart.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);

chartContainer.setPadding(new Insets(2));

statusChart.getStyleClass().add("status-chart");
}

/**
* Updates the pie chart with new status counts.
*
* @param noneCount Number of clients with NONE status
* @param nonUrgentCount Number of clients with NON_URGENT status
* @param urgentCount Number of clients with URGENT status
*/
public void updateChartData(int noneCount, int nonUrgentCount, int urgentCount) {
Platform.runLater(() -> {
statusChart.getData().clear();

PieChart.Data noneData = new PieChart.Data("None (" + noneCount + ")", noneCount);
PieChart.Data nonUrgentData = new PieChart.Data("Non-Urgent (" + nonUrgentCount + ")", nonUrgentCount);
PieChart.Data urgentData = new PieChart.Data("Urgent (" + urgentCount + ")", urgentCount);

ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
noneData, nonUrgentData, urgentData
);

statusChart.setData(pieChartData);

noneData.getNode().getStyleClass().add("data0");
nonUrgentData.getNode().getStyleClass().add("data1");
urgentData.getNode().getStyleClass().add("data2");

statusChart.applyCss();
});
}
}
34 changes: 22 additions & 12 deletions src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<?import javafx.scene.layout.VBox?>

<fx:root type="javafx.stage.Stage" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1"
title="AgentAssist" minWidth="450" minHeight="600" onCloseRequest="#handleExit">
title="AgentAssist" minWidth="800" minHeight="600" onCloseRequest="#handleExit">
<icons>
<Image url="@/images/agent_assist_logo.png" />
</icons>
Expand All @@ -34,18 +34,27 @@
</Menu>
</MenuBar>

<StackPane VBox.vgrow="NEVER" fx:id="commandBoxPlaceholder" styleClass="pane-with-border">
<padding>
<Insets top="5" right="10" bottom="5" left="10" />
</padding>
</StackPane>
<SplitPane fx:id="topSplitPane" VBox.vgrow="NEVER" styleClass="top-split-pane">
<VBox minWidth="400">
<StackPane VBox.vgrow="NEVER" fx:id="commandBoxPlaceholder" styleClass="pane-with-border" minHeight="50">
<padding>
<Insets top="5" right="10" bottom="5" left="10" />
</padding>
</StackPane>

<StackPane VBox.vgrow="NEVER" fx:id="resultDisplayPlaceholder" styleClass="pane-with-border"
minHeight="100" prefHeight="100" maxHeight="100">
<padding>
<Insets top="5" right="10" bottom="5" left="10" />
</padding>
</StackPane>
<StackPane VBox.vgrow="ALWAYS" fx:id="resultDisplayPlaceholder" styleClass="pane-with-border">
<padding>
<Insets top="5" right="10" bottom="5" left="10" />
</padding>
</StackPane>
</VBox>

<StackPane fx:id="statusChartPlaceholder" styleClass="chart-container" minWidth="150">
<padding>
<Insets top="2" right="2" bottom="2" left="2" />
</padding>
</StackPane>
</SplitPane>

<SplitPane fx:id="splitPane" VBox.vgrow="ALWAYS" dividerPositions="0.5">
<VBox fx:id="clientList" styleClass="pane-with-border" minWidth="340" prefWidth="340">
Expand All @@ -63,6 +72,7 @@
</ImageView>
</StackPane>
</SplitPane>

<StackPane fx:id="statusbarPlaceholder" VBox.vgrow="NEVER" />
</VBox>
</Scene>
Expand Down
18 changes: 18 additions & 0 deletions src/main/resources/view/StatusPieChart.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.chart.PieChart?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<?import java.net.URL?>

<VBox fx:id="chartContainer" alignment="CENTER" spacing="0" fillWidth="true"
xmlns="http://javafx.com/javafx/17"
xmlns:fx="http://javafx.com/fxml/1">
<stylesheets>
<URL value="@css/DarkTheme.css" />
<URL value="@css/StatusPieChart.css" />
</stylesheets>

<Label fx:id="chartTitle" styleClass="chart-title"/>
<PieChart fx:id="statusChart" VBox.vgrow="ALWAYS" legendSide="BOTTOM"/>
</VBox>
23 changes: 22 additions & 1 deletion src/main/resources/view/css/DarkTheme.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.background {
-fx-background-color: derive(#1d1d1d, 20%);
background-color: #383838; /* Used in the default.html file */
background-color: #383838;
}

.label {
Expand Down Expand Up @@ -312,6 +312,7 @@
-fx-font-weight: bold;
}

/* Tier label styles */
.detail-tier-label {
-fx-text-fill: white;
-fx-padding: 2 5 2 5;
Expand Down Expand Up @@ -406,6 +407,26 @@
-fx-background-color: #383838;
}

.top-split-pane {
-fx-background-color: derive(#1d1d1d, 20%);
-fx-border-color: transparent;
}

.top-split-pane:horizontal > .split-pane-divider {
-fx-background-color: derive(#1d1d1d, 40%);
-fx-padding: 0 1 0 1;
}

#cardPane {
-fx-background-color: transparent;
-fx-border-width: 0;
}

#commandTypeLabel {
-fx-font-size: 11px;
-fx-text-fill: #1C1C1C;
}

.scroll-pane {
-fx-background-color: #383838;
}
Expand Down
55 changes: 55 additions & 0 deletions src/main/resources/view/css/StatusPieChart.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* Chart container styles */
.chart-container {
-fx-background-color: #1C1C1C;
-fx-padding: 2;
}

/* Chart title styles */
.chart-title {
-fx-text-fill: white;
-fx-font-size: 16px;
-fx-padding: 0 0 -2 0;
-fx-font-weight: bold;
}

/* General pie chart styles */
.chart-pie {
-fx-border-width: 0;
-fx-padding: 0 0 0 2;
}

/* Data-specific styles for pie slices */
.chart-pie.data0 {
-fx-pie-color: #009E60;
}

.chart-pie.data1 {
-fx-pie-color: #c46210;
}

.chart-pie.data2 {
-fx-pie-color: #FF2400;
}

/* Legend styles */
.chart-legend {
-fx-background-color: transparent;
-fx-padding: 10 5 5 5;
}

.chart-legend-item {
-fx-text-fill: white;
-fx-font-size: 14px;
}

.chart-legend-item-symbol {
-fx-padding: 3px;
-fx-min-width: 8px;
-fx-min-height: 8px;
}

/* Status chart placeholder dimensions */
.status-chart-placeholder {
-fx-min-height: 220px;
-fx-max-height: 220px;
}

0 comments on commit a9f7338

Please sign in to comment.