Skip to content

Commit

Permalink
Merge 2c09b21 into 27b8526
Browse files Browse the repository at this point in the history
  • Loading branch information
jietung committed Nov 6, 2019
2 parents 27b8526 + 2c09b21 commit 112959b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 27 deletions.
8 changes: 5 additions & 3 deletions src/main/java/seedu/exercise/ui/BarChartPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,20 @@ private void display() {
barChart.layout();

xAxis.setLabel(DEFAULT_EXERCISES);
yAxis.setLabel(ChartTextUtil.labelFormatter(statistic.getCategory()));
yAxis.setLabel(ChartUtil.labelFormatter(statistic.getCategory()));

XYChart.Series<String, Double> series = new XYChart.Series<>();

int size = properties.size();
for (int i = 0; i < size; i++) {
String property = ChartTextUtil.propertyFormatter(properties.get(i));
String property = ChartUtil.propertyFormatter(properties.get(i));
series.getData().add(new XYChart.Data<>(property, values.get(i)));
}

barChart.setLegendVisible(false);
barChart.setTitle(ChartTextUtil.lineAndBarChartTitleFormatter(category, startDate, endDate));
barChart.setTitle(ChartUtil.lineAndBarChartTitleFormatter(category, startDate, endDate));
barChart.getData().add(series);

ChartUtil.installToolTipXyChart(series.getData());
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
package seedu.exercise.ui;

import javafx.collections.ObservableList;
import javafx.scene.chart.PieChart;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Tooltip;

/**
* A class to format text in chart panels.
* A class that contains common methods for ChartPanel.
*/
public class ChartTextUtil {
public class ChartUtil {

public static final String TITLE_FORMAT = "%s (%s to %s)";

/**
* Install tooltip for bar chart and line chart.
*/
public static void installToolTipXyChart(ObservableList<XYChart.Data<String, Double>> data) {
data.stream().forEach(d -> {
Tooltip tooltip = new Tooltip();
tooltip.setText(d.getXValue() + "\n" + d.getYValue());
Tooltip.install(d.getNode(), tooltip);
});
}

/**
* Install tooltip for pie chart.
*/
public static void installToolTipPieChart(ObservableList<PieChart.Data> data) {
data.stream().forEach(d -> {
Tooltip tooltip = new Tooltip();
tooltip.setText(d.getName());
Tooltip.install(d.getNode(), tooltip);
});
}

/**
* Returns the formatted title of line chart and bar chart.
*/
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/seedu/exercise/ui/LineChartPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void display() {
lineChart.layout();

xAxis.setLabel(DEFAULT_DATE);
yAxis.setLabel(ChartTextUtil.labelFormatter(category));
yAxis.setLabel(ChartUtil.labelFormatter(category));

XYChart.Series<String, Double> series = new XYChart.Series<>();

Expand All @@ -56,7 +56,9 @@ private void display() {
}

lineChart.setLegendVisible(false);
lineChart.setTitle(ChartTextUtil.lineAndBarChartTitleFormatter(category, startDate, endDate));
lineChart.setTitle(ChartUtil.lineAndBarChartTitleFormatter(category, startDate, endDate));
lineChart.getData().add(series);

ChartUtil.installToolTipXyChart(series.getData());
}
}
4 changes: 2 additions & 2 deletions src/main/java/seedu/exercise/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ private void setChart() {

private String getTotalAndAverage() {
Statistic statistic = logic.getStatistic();
return ChartTextUtil.totalFormatter(statistic.getCategory(), statistic.getTotal()) + "\n"
+ ChartTextUtil.averageFormatter(statistic.getCategory(), statistic.getAverage());
return ChartUtil.totalFormatter(statistic.getCategory(), statistic.getTotal()) + "\n"
+ ChartUtil.averageFormatter(statistic.getCategory(), statistic.getAverage());
}

private void setStats() {
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/seedu/exercise/ui/PieChartPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import javafx.fxml.FXML;
import javafx.scene.chart.PieChart;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.Region;
import seedu.exercise.logic.commands.statistic.Statistic;

Expand Down Expand Up @@ -43,19 +42,15 @@ private void display() {

for (int i = 0; i < size; i++) {
double percentage = Statistic.percentage(values.get(i), statistic.getTotal());
String property = ChartTextUtil.propertyFormatter(properties.get(i));
String propertyWithPercentage = ChartTextUtil.percentageFormatter(property, percentage);
String property = ChartUtil.propertyFormatter(properties.get(i));
String propertyWithPercentage = ChartUtil.percentageFormatter(property, percentage);
PieChart.Data slice = new PieChart.Data(propertyWithPercentage, values.get(i));
pieChart.getData().add(slice);
}

pieChart.getData().stream().forEach(data -> {
Tooltip tooltip = new Tooltip();
tooltip.setText(data.getName());
Tooltip.install(data.getNode(), tooltip);
});
ChartUtil.installToolTipPieChart(pieChart.getData());

pieChart.setLegendVisible(false);
pieChart.setTitle(ChartTextUtil.pieChartTitleFormatter(category, startDate, endDate));
pieChart.setTitle(ChartUtil.pieChartTitleFormatter(category, startDate, endDate));
}
}
6 changes: 3 additions & 3 deletions src/main/resources/view/BarChartPanel.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane minHeight="400.0" minWidth="625.0" prefHeight="400.0" prefWidth="625.0" stylesheets="@Chart.css"
<AnchorPane minHeight="400.0" minWidth="800.0" prefHeight="400.0" prefWidth="800.0" stylesheets="@Chart.css"
xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<children>
<BarChart fx:id="barChart" maxHeight="400.0" maxWidth="625.0" minHeight="400.0" minWidth="625.0"
prefHeight="400.0" prefWidth="625.0" AnchorPane.bottomAnchor="0.0"
<BarChart fx:id="barChart" maxHeight="400.0" maxWidth="800.0" minHeight="400.0" minWidth="800.0"
prefHeight="400.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<xAxis>
<CategoryAxis minHeight="400.0" minWidth="400.0" side="BOTTOM" fx:id="xAxis"/>
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/view/LineChartPanel.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane minHeight="400.0" minWidth="625.0" prefHeight="400.0" prefWidth="625.0" stylesheets="@Chart.css"
<AnchorPane minHeight="400.0" minWidth="800.0" prefHeight="400.0" prefWidth="800.0" stylesheets="@Chart.css"
xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<children>
<LineChart fx:id="lineChart" maxHeight="400.0" maxWidth="625.0" minHeight="400.0" minWidth="625.0"
prefHeight="400.0" prefWidth="625.0" AnchorPane.bottomAnchor="0.0"
<LineChart fx:id="lineChart" maxHeight="400.0" maxWidth="800.0" minHeight="400.0" minWidth="800.0"
prefHeight="400.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<xAxis>
<CategoryAxis minHeight="400.0" minWidth="400.0" side="BOTTOM" fx:id="xAxis"/>
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/view/PieChartPanel.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<?import javafx.scene.layout.*?>
<?import javafx.scene.chart.*?>

<AnchorPane minHeight="400.0" minWidth="625.0" prefHeight="400.0" prefWidth="625.0"
<AnchorPane minHeight="400.0" minWidth="800.0" prefHeight="400.0" prefWidth="800.0"
xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<children>
<PieChart fx:id="pieChart" maxHeight="600.0" maxWidth="625.0" minHeight="400.0" minWidth="625.0"
prefHeight="400.0" prefWidth="625.0" AnchorPane.bottomAnchor="0.0"
<PieChart fx:id="pieChart" maxHeight="600.0" maxWidth="800.0" minHeight="400.0" minWidth="800.0"
prefHeight="400.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
</PieChart>
</children>
Expand Down

0 comments on commit 112959b

Please sign in to comment.