Skip to content

Commit

Permalink
Merge 8e6cac1 into 7eef614
Browse files Browse the repository at this point in the history
  • Loading branch information
AmabelYeo committed Nov 5, 2018
2 parents 7eef614 + 8e6cac1 commit d00c7dc
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 18 deletions.
59 changes: 58 additions & 1 deletion src/main/java/seedu/address/ui/OverviewPanel.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package seedu.address.ui;

import java.util.Arrays;
import java.util.logging.Logger;

import com.google.common.eventbus.Subscribe;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.PieChart;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Label;
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.events.ui.OverviewPanelChangedEvent;
import seedu.address.model.Overview;
import seedu.address.model.event.Event;
import seedu.address.model.record.Record;
import seedu.address.model.volunteer.Volunteer;
Expand All @@ -27,15 +35,27 @@ public class OverviewPanel extends UiPart<Region> {
private Label ongoingLabel;
@FXML
private Label completedLabel;
@FXML
private PieChart genderPieChart;
@FXML
private BarChart ageBarChart;
@FXML
private NumberAxis yAxis;
@FXML
private CategoryAxis xAxis;

private ObservableList<Volunteer> volunteerList;
private ObservableList<Event> eventList;
private ObservableList<Record> recordList;

private Overview overview;

public OverviewPanel(ObservableList<Volunteer> volunteerList, ObservableList<Event> eventList,
ObservableList<Record> recordList) {
ObservableList<Record> recordList) {
super(FXML);
Overview overview = new Overview(volunteerList, eventList, recordList);
this.overview = overview;

this.volunteerList = volunteerList;
this.eventList = eventList;
this.recordList = recordList;
Expand All @@ -46,9 +66,46 @@ private void setLabelText() {
upcomingLabel.setText("Number of events: " + Integer.toString(eventList.size()));
}

/**
* This method creates a pie chart which shows the gender ratio.
*/
private void createGenderPieChart() {
String male = "Male (" + overview.getNumOfMale() + ")";
String female = "Female (" + overview.getNumOfFemale() + ")";

ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
new PieChart.Data(male, overview.getNumOfMale()),
new PieChart.Data(female, overview.getNumOfFemale()));

genderPieChart.setData(pieChartData);
genderPieChart.setTitle("Gender Ratio");
genderPieChart.setLabelsVisible(true);
}

/**
* This method creates a bar chart which shows the age distribution.
*/
private void createAgeBarChart() {
xAxis.setCategories(FXCollections
.observableArrayList(Arrays.asList("14 and Below", "15 to 24", "24 to 64", "65 and Above")));
yAxis.setLabel("Number");

//Prepare XYChart.Series objects by setting data
XYChart.Series<String, Number> series = new XYChart.Series<>();
series.getData().add(new XYChart.Data<>("14 and Below", overview.getNumOfChildren()));
series.getData().add(new XYChart.Data<>("15 to 24", overview.getNumOfYouth()));
series.getData().add(new XYChart.Data<>("24 to 64", overview.getNumOfAdult()));
series.getData().add(new XYChart.Data<>("65 and Above", overview.getNumOfSenior()));

ageBarChart.setTitle("Age Distribution of Volunteers");
ageBarChart.getData().add(series);
}

@Subscribe
private void handleOverviewPanelSelectionChangedEvent(OverviewPanelChangedEvent event) {
logger.info(LogsCenter.getEventHandlingLogMessage(event));
setLabelText();
createGenderPieChart();
createAgeBarChart();
}
}
50 changes: 33 additions & 17 deletions src/main/resources/view/OverviewPanel.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,70 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<VBox fx:id="overviewPanel" styleClass="browser-panel" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1">
<?import javafx.scene.chart.PieChart?>
<?import javafx.scene.chart.BarChart?>
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.chart.CategoryAxis?>
<VBox fx:id="overviewPanel" styleClass="browser-panel" xmlns="http://javafx.com/javafx/8.0.121"
xmlns:fx="http://javafx.com/fxml/1">
<VBox alignment="CENTER_LEFT">
<Label fx:id="eventOverviewLabel" styleClass="event-name" text="Events"/>
</VBox>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
</columnConstraints>
<HBox id="upcomingPane" fx:id="upcomingPane" styleClass="overviewEvent" GridPane.columnIndex="0" GridPane.rowIndex="0" GridPane.columnSpan="1">
<HBox id="upcomingPane" fx:id="upcomingPane" styleClass="overviewEvent" GridPane.columnIndex="0"
GridPane.rowIndex="0" GridPane.columnSpan="1">
<GridPane HBox.hgrow="NEVER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150"/>
</columnConstraints>
<VBox alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0">
<Label text="Upcoming" styleClass="cell_big_label" />
<Label fx:id="upcomingLabel" styleClass="cell_small_label" text="-" />
<Label text="Upcoming" styleClass="cell_big_label"/>
<Label fx:id="upcomingLabel" styleClass="cell_small_label" text="-"/>
</VBox>
</GridPane>
</HBox>
<HBox id="ongoingPane" fx:id="ongoingPane" styleClass="overviewEvent" GridPane.columnIndex="1" GridPane.rowIndex="0" GridPane.columnSpan="1">
<HBox id="ongoingPane" fx:id="ongoingPane" styleClass="overviewEvent" GridPane.columnIndex="1"
GridPane.rowIndex="0" GridPane.columnSpan="1">
<GridPane HBox.hgrow="NEVER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150"/>
</columnConstraints>
<VBox alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0">
<Label text="Ongoing" styleClass="cell_big_label" />
<Label fx:id="ongoingLabel" styleClass="cell_small_label" text="-" />
<Label text="Ongoing" styleClass="cell_big_label"/>
<Label fx:id="ongoingLabel" styleClass="cell_small_label" text="-"/>
</VBox>
</GridPane>
</HBox>
<HBox id="ongoingPane" fx:id="completedPane" styleClass="overviewEvent" GridPane.columnIndex="2" GridPane.rowIndex="0" GridPane.columnSpan="1">
<HBox id="ongoingPane" fx:id="completedPane" styleClass="overviewEvent" GridPane.columnIndex="2"
GridPane.rowIndex="0" GridPane.columnSpan="1">
<GridPane HBox.hgrow="NEVER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150"/>
</columnConstraints>
<VBox alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0">
<Label text="Completed" styleClass="cell_big_label" />
<Label fx:id="completedLabel" styleClass="cell_small_label" text="-" />
<Label text="Completed" styleClass="cell_big_label"/>
<Label fx:id="completedLabel" styleClass="cell_small_label" text="-"/>
</VBox>
</GridPane>
</HBox>
</GridPane>
<VBox>
<Label fx:id="volunteerOverviewLabel" styleClass="event-name" text="Volunteers"/>
<HBox>
<Label text="Play area"></Label>
<PieChart fx:id="genderPieChart"/>
<BarChart fx:id="ageBarChart">
<xAxis>
<CategoryAxis fx:id="xAxis" side="BOTTOM"/>
</xAxis>
<yAxis>
<NumberAxis fx:id="yAxis" side="LEFT"/>
</yAxis>
</BarChart>
</HBox>
</VBox>
</VBox>
Expand Down

0 comments on commit d00c7dc

Please sign in to comment.