Skip to content

Commit

Permalink
Split the css for pie chart and fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdiluxedbutcooler committed Nov 2, 2024
1 parent c2cfc5a commit 179e31e
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 213 deletions.
25 changes: 12 additions & 13 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public class MainWindow extends UiPart<Stage> {

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

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

private Stage primaryStage;
private Logic logic;

Expand Down Expand Up @@ -163,6 +171,9 @@ private void updateStatusChart() {
case NONE -> counts[0]++;
case NON_URGENT -> counts[1]++;
case URGENT -> counts[2]++;
default -> {
logger.warning("Unexpected status value: " + person.getStatus().status);
}
}
}

Expand Down Expand Up @@ -240,7 +251,6 @@ private void handleViewCommand(String commandText) {
Person personToView = logic.getFilteredPersonList().get(index);
personDetailPanel.setPersonDetails(personToView);
} catch (NumberFormatException | IndexOutOfBoundsException e) {
// Handle invalid index
resultDisplay.setFeedbackToUser("Invalid person index.");
}
} else {
Expand Down Expand Up @@ -285,27 +295,16 @@ private CommandResult executeCommand(String commandText) throws CommandException
}
}

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

/**
* Sets up the split panes and their divider positions
*/
private void setupSplitPanes() {
topSplitPane.setDividerPositions(0.8); // 80:20 ratio
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));
}
});
}



}
32 changes: 14 additions & 18 deletions src/main/java/seedu/address/ui/StatusPieChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,16 @@
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;
import javafx.scene.control.Label;
import javafx.scene.Node;
import javafx.scene.paint.Color;

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

private static final String FXML = "StatusPieChart.fxml";

private static final String NONE_COLOR = "#009E60";
private static final String NON_URGENT_COLOR = "#c46210";
private static final String URGENT_COLOR = "#FF2400";

@FXML
private VBox chartContainer;

Expand All @@ -33,11 +26,23 @@ public class StatusPieChart extends UiPart<Region> {
@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("");
Expand All @@ -51,7 +56,6 @@ private void setupChart() {

chartContainer.setPadding(new Insets(2));

// Add default style classes to ensure proper initialization
statusChart.getStyleClass().add("status-chart");
}

Expand All @@ -66,7 +70,6 @@ public void updateChartData(int noneCount, int nonUrgentCount, int urgentCount)
Platform.runLater(() -> {
statusChart.getData().clear();

// Create data pieces
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);
Expand All @@ -77,18 +80,11 @@ public void updateChartData(int noneCount, int nonUrgentCount, int urgentCount)

statusChart.setData(pieChartData);

// Apply styles to pie slices first
noneData.getNode().setStyle("-fx-pie-color: " + NONE_COLOR + ";");
nonUrgentData.getNode().setStyle("-fx-pie-color: " + NON_URGENT_COLOR + ";");
urgentData.getNode().setStyle("-fx-pie-color: " + URGENT_COLOR + ";");

// Add style classes for CSS styling
noneData.getNode().getStyleClass().add("data0");
nonUrgentData.getNode().getStyleClass().add("data1");
urgentData.getNode().getStyleClass().add("data2");

// Force a style refresh
statusChart.applyCss();
});
}
}
}
6 changes: 1 addition & 5 deletions src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
</Menu>
</MenuBar>

<!-- Top section with command/result and chart -->
<SplitPane fx:id="topSplitPane" VBox.vgrow="NEVER" styleClass="top-split-pane">
<!-- Left side: Command and Result -->
<VBox minWidth="400">
<StackPane VBox.vgrow="NEVER" fx:id="commandBoxPlaceholder" styleClass="pane-with-border" minHeight="50">
<padding>
Expand All @@ -51,15 +49,13 @@
</StackPane>
</VBox>

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

<!-- Bottom section for person list -->
<SplitPane fx:id="splitPane" VBox.vgrow="ALWAYS" dividerPositions="0.5">
<VBox fx:id="personList" styleClass="pane-with-border" minWidth="340" prefWidth="340">
<padding>
Expand All @@ -81,4 +77,4 @@
</VBox>
</Scene>
</scene>
</fx:root>
</fx:root>
3 changes: 2 additions & 1 deletion src/main/resources/view/StatusPieChart.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
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>
</VBox>
Loading

0 comments on commit 179e31e

Please sign in to comment.