Fix weekday charts, closes #403

This commit is contained in:
cpfeiffer 2016-10-03 22:41:40 +02:00
parent bbecfbeace
commit 827c99f620
2 changed files with 8 additions and 13 deletions

View File

@ -726,7 +726,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
} }
} }
private static class XIndexLabelFormatter implements IAxisValueFormatter { protected static class XIndexLabelFormatter implements IAxisValueFormatter {
private ArrayList<String> xLabels; private ArrayList<String> xLabels;

View File

@ -47,6 +47,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
private PieChart mTodayStepsChart; private PieChart mTodayStepsChart;
private CombinedChart mWeekStepsChart; private CombinedChart mWeekStepsChart;
private XIndexLabelFormatter xIndexLabelFormatter = new XIndexLabelFormatter();
@Override @Override
protected ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) { protected ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
@ -85,27 +86,20 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
day = (Calendar) day.clone(); // do not modify the caller's argument day = (Calendar) day.clone(); // do not modify the caller's argument
day.add(Calendar.DATE, -7); day.add(Calendar.DATE, -7);
List<BarEntry> entries = new ArrayList<>(); List<BarEntry> entries = new ArrayList<>();
final String[] labels = new String[7]; ArrayList<String> labels = new ArrayList<String>();
for (int counter = 0; counter < 7; counter++) { for (int counter = 0; counter < 7; counter++) {
entries.add(new BarEntry(counter, analysis.calculateTotalSteps(getSamplesOfDay(db, day, device)))); entries.add(new BarEntry(counter, analysis.calculateTotalSteps(getSamplesOfDay(db, day, device))));
labels[counter] = day.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, mLocale); labels.add(day.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, mLocale));
day.add(Calendar.DATE, 1); day.add(Calendar.DATE, 1);
} }
BarDataSet set = new BarDataSet(entries, ""); BarDataSet set = new BarDataSet(entries, "");
set.setColor(akActivity.color); set.setColor(akActivity.color);
// BarData barData = new BarData(labels); xIndexLabelFormatter.setxLabels(labels);
BarData barData = new BarData(); BarData barData = new BarData(set);
barData.setValueTextColor(Color.GRAY); //prevent tearing other graph elements with the black text. Another approach would be to hide the values cmpletely with data.setDrawValues(false); barData.setValueTextColor(Color.GRAY); //prevent tearing other graph elements with the black text. Another approach would be to hide the values cmpletely with data.setDrawValues(false);
IValueFormatter weekDayValueFormatter = new IValueFormatter() {
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return labels[(int) value]; // is value the x or y value?
}
};
barData.setValueFormatter(weekDayValueFormatter);
LimitLine target = new LimitLine(mTargetSteps); LimitLine target = new LimitLine(mTargetSteps);
combinedChart.getAxisLeft().removeAllLimitLines(); combinedChart.getAxisLeft().removeAllLimitLines();
@ -113,7 +107,6 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
CombinedData combinedData = new CombinedData(); CombinedData combinedData = new CombinedData();
combinedData.setData(barData); combinedData.setData(barData);
combinedData.setValueFormatter(weekDayValueFormatter);
return new DefaultChartsData(combinedData); return new DefaultChartsData(combinedData);
} }
@ -198,6 +191,8 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
x.setEnabled(true); x.setEnabled(true);
x.setTextColor(CHART_TEXT_COLOR); x.setTextColor(CHART_TEXT_COLOR);
x.setDrawLimitLinesBehindData(true); x.setDrawLimitLinesBehindData(true);
x.setValueFormatter(xIndexLabelFormatter);
x.setPosition(XAxis.XAxisPosition.BOTTOM);
YAxis y = mWeekStepsChart.getAxisLeft(); YAxis y = mWeekStepsChart.getAxisLeft();
y.setDrawGridLines(false); y.setDrawGridLines(false);