fix: pie chart refreshing improperly
This commit is contained in:
parent
7946cd3df2
commit
bc852ce3d6
1 changed files with 29 additions and 5 deletions
|
|
@ -175,7 +175,15 @@ public class NutritionPieChartCtrl implements LocaleAware {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateText() {
|
public void updateText() {
|
||||||
this.refresh();
|
List<PieChart.Data> data = this.pieChart.getData();
|
||||||
|
if (data.isEmpty()) return;
|
||||||
|
final int EXPECTED_DATA_SIZE = 3;
|
||||||
|
if (data.size() != EXPECTED_DATA_SIZE) return;
|
||||||
|
|
||||||
|
data.get(0).setName(this.getLocaleString("menu.nutrition.protein"));
|
||||||
|
data.get(1).setName(this.getLocaleString("menu.nutrition.fat"));
|
||||||
|
final int TWO = 2;
|
||||||
|
data.get(TWO).setName(this.getLocaleString("menu.nutrition.carbs"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -186,7 +194,8 @@ public class NutritionPieChartCtrl implements LocaleAware {
|
||||||
/**
|
/**
|
||||||
* Refresh the data in this pie chart.
|
* Refresh the data in this pie chart.
|
||||||
*/
|
*/
|
||||||
private void refresh() {
|
@SuppressWarnings("checkstyle:MagicNumber")
|
||||||
|
public void refresh() {
|
||||||
if (this.recipe == null) {
|
if (this.recipe == null) {
|
||||||
this.pieChart.setVisible(false);
|
this.pieChart.setVisible(false);
|
||||||
logger.info("Refreshing pie chart with no recipe");
|
logger.info("Refreshing pie chart with no recipe");
|
||||||
|
|
@ -195,9 +204,24 @@ public class NutritionPieChartCtrl implements LocaleAware {
|
||||||
|
|
||||||
logger.info("Refreshing pie chart with recipe");
|
logger.info("Refreshing pie chart with recipe");
|
||||||
this.pieChart.setVisible(true);
|
this.pieChart.setVisible(true);
|
||||||
|
if (this.pieChart.getData().isEmpty()) {
|
||||||
this.pieChart.getData().setAll(
|
this.pieChart.getData().setAll(
|
||||||
this.getPieChartData()
|
this.getPieChartData()
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
List<PieChart.Data> fresh = this.getPieChartData();
|
||||||
|
List<PieChart.Data> data = this.pieChart.getData();
|
||||||
|
|
||||||
|
if (fresh.isEmpty()) {
|
||||||
|
data.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.get(0).setPieValue(fresh.get(0).getPieValue());
|
||||||
|
data.get(1).setPieValue(fresh.get(1).getPieValue());
|
||||||
|
final int TWO = 2;
|
||||||
|
data.get(TWO).setPieValue(fresh.get(TWO).getPieValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeComponents() {
|
public void initializeComponents() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue