Minor improvements to the WIP week sleep chart

This commit is contained in:
Andreas Shimokawa 2017-02-23 08:49:55 +01:00
parent 6834f36ec7
commit 437ec6c9b7
3 changed files with 43 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.IValueFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -90,7 +91,8 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
}
BarDataSet set = new BarDataSet(entries, "");
set.setColor(akActivity.color);
set.setColor(getMainColor());
set.setValueFormatter(getFormatter());
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);
@ -112,7 +114,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
List<Integer> colors = new ArrayList<>();
entries.add(new PieEntry(totalValue, "")); //we don't want labels on the pie chart
colors.add(akActivity.color);
colors.add(getMainColor());
if (totalValue < mTargetValue) {
entries.add(new PieEntry((mTargetValue - totalValue))); //we don't want labels on the pie chart
@ -120,6 +122,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
}
PieDataSet set = new PieDataSet(entries, "");
set.setValueFormatter(getFormatter());
set.setColors(colors);
data.setDataSet(set);
//this hides the values (numeric) added to the set. These would be shown aside the strings set with addXValue above
@ -260,4 +263,9 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
abstract int getGoal();
abstract int getTotalForSamples(List<? extends ActivitySample> activitySamples);
abstract IValueFormatter getFormatter();
abstract Integer getMainColor();
}

View File

@ -1,12 +1,18 @@
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.List;
import java.util.concurrent.TimeUnit;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmount;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityAmounts;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
public class WeekSleepChartFragment extends AbstractWeekChartFragment {
@Override
@ -31,4 +37,19 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
}
return (int) (totalSeconds / 60);
}
@Override
IValueFormatter getFormatter() {
return new IValueFormatter() {
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.MINUTES);
}
};
}
@Override
Integer getMainColor() {
return akLightSleep.color;
}
}

View File

@ -1,5 +1,7 @@
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
import com.github.mikephil.charting.formatter.IValueFormatter;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.R;
@ -27,4 +29,14 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
ActivityAnalysis analysis = new ActivityAnalysis();
return analysis.calculateTotalSteps(activitySamples);
}
@Override
IValueFormatter getFormatter() {
return null;
}
@Override
Integer getMainColor() {
return akActivity.color;
}
}