use of com.github.mikephil.charting.data.PieData in project Gadgetbridge by Freeyourgadget.
the class SleepChartFragment method refreshSleepAmounts.
private MySleepChartsData refreshSleepAmounts(GBDevice mGBDevice, List<? extends ActivitySample> samples) {
SleepAnalysis sleepAnalysis = new SleepAnalysis();
List<SleepSession> sleepSessions = sleepAnalysis.calculateSleepSessions(samples);
PieData data = new PieData();
final long lightSleepDuration = calculateLightSleepDuration(sleepSessions);
final long deepSleepDuration = calculateDeepSleepDuration(sleepSessions);
final long totalSeconds = lightSleepDuration + deepSleepDuration;
final List<PieEntry> entries;
final List<Integer> colors;
if (sleepSessions.isEmpty()) {
entries = Collections.emptyList();
colors = Collections.emptyList();
} else {
entries = Arrays.asList(new PieEntry(lightSleepDuration, getActivity().getString(R.string.abstract_chart_fragment_kind_light_sleep)), new PieEntry(deepSleepDuration, getActivity().getString(R.string.abstract_chart_fragment_kind_deep_sleep)));
colors = Arrays.asList(getColorFor(ActivityKind.TYPE_LIGHT_SLEEP), getColorFor(ActivityKind.TYPE_DEEP_SLEEP));
}
String totalSleep = DateTimeUtils.formatDurationHoursMinutes(totalSeconds, TimeUnit.SECONDS);
PieDataSet set = new PieDataSet(entries, "");
set.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS);
}
});
set.setColors(colors);
set.setValueTextColor(DESCRIPTION_COLOR);
set.setValueTextSize(13f);
set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
data.setDataSet(set);
// setupLegend(pieChart);
return new MySleepChartsData(totalSleep, data, sleepSessions);
}
use of com.github.mikephil.charting.data.PieData in project Gadgetbridge by Freeyourgadget.
the class AbstractWeekChartFragment method refreshDayPie.
private DayData refreshDayPie(DBHandler db, Calendar day, GBDevice device) {
PieData data = new PieData();
List<PieEntry> entries = new ArrayList<>();
PieDataSet set = new PieDataSet(entries, "");
ActivityAmounts amounts = getActivityAmountsForDay(db, day, device);
float[] totalValues = getTotalsForActivityAmounts(amounts);
String[] pieLabels = getPieLabels();
float totalValue = 0;
for (int i = 0; i < totalValues.length; i++) {
float value = totalValues[i];
totalValue += value;
entries.add(new PieEntry(value, pieLabels[i]));
}
set.setColors(getColors());
if (totalValues.length < 2) {
if (totalValue < mTargetValue) {
entries.add(new PieEntry((mTargetValue - totalValue)));
set.addColor(Color.GRAY);
}
}
data.setDataSet(set);
if (totalValues.length < 2) {
data.setDrawValues(false);
} else {
set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
set.setValueTextColor(DESCRIPTION_COLOR);
set.setValueTextSize(13f);
set.setValueFormatter(getPieValueFormatter());
}
return new DayData(data, formatPieValue((long) totalValue));
}
use of com.github.mikephil.charting.data.PieData in project Gadgetbridge by Freeyourgadget.
the class GBDeviceAdapterv2 method setChartsData.
private void setChartsData(PieChart pieChart, float value, float target, String label, String stringValue, Context context) {
final String CHART_COLOR_START = "#e74c3c";
final String CHART_COLOR_END = "#2ecc71";
ArrayList<PieEntry> entries = new ArrayList<>();
entries.add(new PieEntry((float) value, context.getResources().getDrawable(R.drawable.ic_star_gold)));
if (value < target) {
entries.add(new PieEntry((float) (target - value)));
}
pieChart.setCenterText(String.format("%s\n%s", stringValue, label));
float colorValue = Math.max(0, Math.min(1, value / target));
int chartColor = interpolateColor(Color.parseColor(CHART_COLOR_START), Color.parseColor(CHART_COLOR_END), colorValue);
PieDataSet dataSet = new PieDataSet(entries, "");
dataSet.setDrawIcons(false);
dataSet.setIconsOffset(new MPPointF(0, -66));
if (colorValue == 1) {
dataSet.setDrawIcons(true);
}
dataSet.setSliceSpace(0f);
dataSet.setSelectionShift(5f);
dataSet.setColors(chartColor, Color.LTGRAY);
PieData data = new PieData(dataSet);
data.setValueTextSize(0f);
data.setValueTextColor(Color.WHITE);
pieChart.setData(data);
pieChart.invalidate();
}
Aggregations