mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-25 16:50:44 +02:00
Initial port to mpandroidchart 3.0
does not quite work yet
This commit is contained in:
parent
0a4eefcf11
commit
1b5bc23981
@ -68,7 +68,7 @@ dependencies {
|
|||||||
compile 'com.android.support:design:23.3.0'
|
compile 'com.android.support:design:23.3.0'
|
||||||
compile 'com.github.tony19:logback-android-classic:1.1.1-4'
|
compile 'com.github.tony19:logback-android-classic:1.1.1-4'
|
||||||
compile 'org.slf4j:slf4j-api:1.7.7'
|
compile 'org.slf4j:slf4j-api:1.7.7'
|
||||||
compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
|
compile 'com.github.PhilJay:MPAndroidChart:5b9bd6e633f2f084ea8064af64f8f72402964cd4'
|
||||||
compile 'com.github.pfichtner:durationformatter:0.1.1'
|
compile 'com.github.pfichtner:durationformatter:0.1.1'
|
||||||
compile 'de.cketti.library.changelog:ckchangelog:1.2.2'
|
compile 'de.cketti.library.changelog:ckchangelog:1.2.2'
|
||||||
compile 'net.e175.klaus:solarpositioning:0.0.9'
|
compile 'net.e175.klaus:solarpositioning:0.0.9'
|
||||||
|
@ -339,7 +339,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void configureChartDefaults(Chart<?> chart) {
|
protected void configureChartDefaults(Chart<?> chart) {
|
||||||
chart.setDescription("");
|
chart.getDescription().setText("");
|
||||||
|
|
||||||
// if enabled, the chart will always start at zero on the y-axis
|
// if enabled, the chart will always start at zero on the y-axis
|
||||||
chart.setNoDataText(getString(R.string.chart_no_data_synchronize));
|
chart.setNoDataText(getString(R.string.chart_no_data_synchronize));
|
||||||
@ -506,23 +506,25 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||||||
|
|
||||||
BarDataSet activitySet = createActivitySet(activityEntries, colors, "Activity");
|
BarDataSet activitySet = createActivitySet(activityEntries, colors, "Activity");
|
||||||
// create a data object with the datasets
|
// create a data object with the datasets
|
||||||
combinedData = new CombinedData(xLabels);
|
// combinedData = new CombinedData(xLabels);
|
||||||
|
combinedData = new CombinedData();
|
||||||
List<IBarDataSet> list = new ArrayList<>();
|
List<IBarDataSet> list = new ArrayList<>();
|
||||||
list.add(activitySet);
|
list.add(activitySet);
|
||||||
BarData barData = new BarData(xLabels, list);
|
BarData barData = new BarData(list);
|
||||||
barData.setGroupSpace(0);
|
// barData.setGroupSpace(0);
|
||||||
combinedData.setData(barData);
|
combinedData.setData(barData);
|
||||||
|
|
||||||
if (hr && heartrateEntries.size() > 0) {
|
if (hr && heartrateEntries.size() > 0) {
|
||||||
LineDataSet heartrateSet = createHeartrateSet(heartrateEntries, "Heart Rate");
|
LineDataSet heartrateSet = createHeartrateSet(heartrateEntries, "Heart Rate");
|
||||||
LineData lineData = new LineData(xLabels, heartrateSet);
|
LineData lineData = new LineData(heartrateSet);
|
||||||
combinedData.setData(lineData);
|
combinedData.setData(lineData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// chart.setDescription(getString(R.string.sleep_activity_date_range, dateStringFrom, dateStringTo));
|
// chart.setDescription(getString(R.string.sleep_activity_date_range, dateStringFrom, dateStringTo));
|
||||||
// chart.setDescriptionPosition(?, ?);
|
// chart.setDescriptionPosition(?, ?);
|
||||||
} else {
|
} else {
|
||||||
combinedData = new CombinedData(Collections.<String>emptyList());
|
// combinedData = new CombinedData(Collections.<String>emptyList());
|
||||||
|
combinedData = new CombinedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DefaultChartsData(combinedData);
|
return new DefaultChartsData(combinedData);
|
||||||
@ -575,7 +577,8 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||||||
LineDataSet set1 = new LineDataSet(values, label);
|
LineDataSet set1 = new LineDataSet(values, label);
|
||||||
set1.setLineWidth(0.8f);
|
set1.setLineWidth(0.8f);
|
||||||
set1.setColor(HEARTRATE_COLOR);
|
set1.setColor(HEARTRATE_COLOR);
|
||||||
set1.setDrawCubic(true);
|
// set1.setDrawCubic(true);
|
||||||
|
set1.setMode(LineDataSet.Mode.CUBIC_BEZIER);
|
||||||
set1.setCubicIntensity(0.1f);
|
set1.setCubicIntensity(0.1f);
|
||||||
set1.setDrawCircles(false);
|
set1.setDrawCircles(false);
|
||||||
// set1.setCircleRadius(2f);
|
// set1.setCircleRadius(2f);
|
||||||
|
@ -10,6 +10,7 @@ import android.view.ViewGroup;
|
|||||||
import com.github.mikephil.charting.animation.Easing;
|
import com.github.mikephil.charting.animation.Easing;
|
||||||
import com.github.mikephil.charting.charts.BarLineChartBase;
|
import com.github.mikephil.charting.charts.BarLineChartBase;
|
||||||
import com.github.mikephil.charting.charts.Chart;
|
import com.github.mikephil.charting.charts.Chart;
|
||||||
|
import com.github.mikephil.charting.components.LegendEntry;
|
||||||
import com.github.mikephil.charting.components.XAxis;
|
import com.github.mikephil.charting.components.XAxis;
|
||||||
import com.github.mikephil.charting.components.YAxis;
|
import com.github.mikephil.charting.components.YAxis;
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
|||||||
|
|
||||||
private void setupChart() {
|
private void setupChart() {
|
||||||
mChart.setBackgroundColor(BACKGROUND_COLOR);
|
mChart.setBackgroundColor(BACKGROUND_COLOR);
|
||||||
mChart.setDescriptionColor(DESCRIPTION_COLOR);
|
mChart.getDescription().setTextColor(DESCRIPTION_COLOR);
|
||||||
configureBarLineChartDefaults(mChart);
|
configureBarLineChartDefaults(mChart);
|
||||||
|
|
||||||
|
|
||||||
@ -119,26 +120,42 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
|||||||
mChart.setData(dcd.getCombinedData());
|
mChart.setData(dcd.getCombinedData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void renderCharts() {
|
protected void renderCharts() {
|
||||||
mChart.animateX(ANIM_TIME, Easing.EasingOption.EaseInOutQuart);
|
mChart.animateX(ANIM_TIME, Easing.EasingOption.EaseInOutQuart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setupLegend(Chart chart) {
|
protected void setupLegend(Chart chart) {
|
||||||
List<Integer> legendColors = new ArrayList<>(4);
|
List<LegendEntry> legendEntries = new ArrayList<>(5);
|
||||||
List<String> legendLabels = new ArrayList<>(4);
|
|
||||||
legendColors.add(akActivity.color);
|
LegendEntry activityEntry = new LegendEntry();
|
||||||
legendLabels.add(akActivity.label);
|
activityEntry.label = akActivity.label;
|
||||||
legendColors.add(akLightSleep.color);
|
activityEntry.formColor = akActivity.color;
|
||||||
legendLabels.add(akLightSleep.label);
|
legendEntries.add(activityEntry);
|
||||||
legendColors.add(akDeepSleep.color);
|
|
||||||
legendLabels.add(akDeepSleep.label);
|
LegendEntry lightSleepEntry = new LegendEntry();
|
||||||
legendColors.add(akNotWorn.color);
|
lightSleepEntry.label = akLightSleep.label;
|
||||||
legendLabels.add(akNotWorn.label);
|
lightSleepEntry.formColor = akLightSleep.color;
|
||||||
|
legendEntries.add(lightSleepEntry);
|
||||||
|
|
||||||
|
LegendEntry deepSleepEntry = new LegendEntry();
|
||||||
|
deepSleepEntry.label = akDeepSleep.label;
|
||||||
|
deepSleepEntry.formColor = akDeepSleep.color;
|
||||||
|
legendEntries.add(deepSleepEntry);
|
||||||
|
|
||||||
|
LegendEntry notWornEntry = new LegendEntry();
|
||||||
|
notWornEntry.label = akNotWorn.label;
|
||||||
|
notWornEntry.formColor = akNotWorn.color;
|
||||||
|
legendEntries.add(notWornEntry);
|
||||||
|
|
||||||
if (supportsHeartrate(getChartsHost().getDevice())) {
|
if (supportsHeartrate(getChartsHost().getDevice())) {
|
||||||
legendColors.add(HEARTRATE_COLOR);
|
LegendEntry hrEntry = new LegendEntry();
|
||||||
legendLabels.add(HEARTRATE_LABEL);
|
hrEntry.label = HEARTRATE_LABEL;
|
||||||
|
hrEntry.formColor = HEARTRATE_COLOR;
|
||||||
|
legendEntries.add(hrEntry);
|
||||||
}
|
}
|
||||||
chart.getLegend().setCustom(legendColors, legendLabels);
|
chart.getLegend().setCustom(legendEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -192,7 +192,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
// addEntries();
|
// addEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addEntries() {
|
private void addEntries(long timestamp) {
|
||||||
mTotalStepsChart.setSingleEntryYValue(mSteps.getTotalSteps());
|
mTotalStepsChart.setSingleEntryYValue(mSteps.getTotalSteps());
|
||||||
YAxis stepsPerMinuteCurrentYAxis = mStepsPerMinuteCurrentChart.getAxisLeft();
|
YAxis stepsPerMinuteCurrentYAxis = mStepsPerMinuteCurrentChart.getAxisLeft();
|
||||||
int maxStepsPerMinute = mSteps.getMaxStepsPerMinute();
|
int maxStepsPerMinute = mSteps.getMaxStepsPerMinute();
|
||||||
@ -211,16 +211,15 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ChartData data = mStepsPerMinuteHistoryChart.getData();
|
ChartData data = mStepsPerMinuteHistoryChart.getData();
|
||||||
data.addXValue("");
|
|
||||||
if (stepsPerMinute < 0) {
|
if (stepsPerMinute < 0) {
|
||||||
stepsPerMinute = 0;
|
stepsPerMinute = 0;
|
||||||
}
|
}
|
||||||
mHistorySet.addEntry(new Entry(stepsPerMinute, data.getXValCount() - 1));
|
mHistorySet.addEntry(new Entry(stepsPerMinute, timestamp));
|
||||||
int hr = getCurrentHeartRate();
|
int hr = getCurrentHeartRate();
|
||||||
if (hr < 0) {
|
if (hr < 0) {
|
||||||
hr = 0;
|
hr = 0;
|
||||||
}
|
}
|
||||||
mHeartRateSet.addEntry(new Entry(hr, data.getXValCount() - 1));
|
mHeartRateSet.addEntry(new Entry(hr, timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean addHistoryDataSet(boolean force) {
|
private boolean addHistoryDataSet(boolean force) {
|
||||||
@ -305,7 +304,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
* Called in the UI thread.
|
* Called in the UI thread.
|
||||||
*/
|
*/
|
||||||
private void pulse() {
|
private void pulse() {
|
||||||
addEntries();
|
addEntries(System.currentTimeMillis());
|
||||||
|
|
||||||
LineData historyData = (LineData) mStepsPerMinuteHistoryChart.getData();
|
LineData historyData = (LineData) mStepsPerMinuteHistoryChart.getData();
|
||||||
if (historyData == null) {
|
if (historyData == null) {
|
||||||
@ -368,14 +367,13 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
chart.getXAxis().setDrawLabels(false);
|
chart.getXAxis().setDrawLabels(false);
|
||||||
chart.getXAxis().setEnabled(false);
|
chart.getXAxis().setEnabled(false);
|
||||||
chart.setBackgroundColor(BACKGROUND_COLOR);
|
chart.setBackgroundColor(BACKGROUND_COLOR);
|
||||||
chart.setDescriptionColor(DESCRIPTION_COLOR);
|
chart.getDescription().setTextColor(DESCRIPTION_COLOR);
|
||||||
chart.setDescription(title);
|
chart.getDescription().setText(title);
|
||||||
chart.setNoDataTextDescription("");
|
// chart.setNoDataTextDescription("");
|
||||||
chart.setNoDataText("");
|
chart.setNoDataText("");
|
||||||
chart.getAxisRight().setEnabled(false);
|
chart.getAxisRight().setEnabled(false);
|
||||||
|
|
||||||
List<BarEntry> entries = new ArrayList<>();
|
List<BarEntry> entries = new ArrayList<>();
|
||||||
List<String> xLabels = new ArrayList<>();
|
|
||||||
List<Integer> colors = new ArrayList<>();
|
List<Integer> colors = new ArrayList<>();
|
||||||
|
|
||||||
entries.add(new BarEntry(0, 0));
|
entries.add(new BarEntry(0, 0));
|
||||||
@ -384,16 +382,16 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
colors.add(akActivity.color);
|
colors.add(akActivity.color);
|
||||||
colors.add(akActivity.color);
|
colors.add(akActivity.color);
|
||||||
colors.add(akActivity.color);
|
colors.add(akActivity.color);
|
||||||
//we don't want labels
|
// //we don't want labels
|
||||||
xLabels.add("");
|
// xLabels.add("");
|
||||||
xLabels.add("");
|
// xLabels.add("");
|
||||||
xLabels.add("");
|
// xLabels.add("");
|
||||||
|
|
||||||
BarDataSet set = new BarDataSet(entries, "");
|
BarDataSet set = new BarDataSet(entries, "");
|
||||||
set.setDrawValues(false);
|
set.setDrawValues(false);
|
||||||
set.setColors(colors);
|
set.setColors(colors);
|
||||||
BarData data = new BarData(xLabels, set);
|
BarData data = new BarData(set);
|
||||||
data.setGroupSpace(0);
|
// data.setGroupSpace(0);
|
||||||
chart.setData(data);
|
chart.setData(data);
|
||||||
|
|
||||||
chart.getLegend().setEnabled(false);
|
chart.getLegend().setEnabled(false);
|
||||||
@ -411,8 +409,8 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
|
|
||||||
chart.setTouchEnabled(false); // no zooming or anything, because it's updated all the time
|
chart.setTouchEnabled(false); // no zooming or anything, because it's updated all the time
|
||||||
chart.setBackgroundColor(BACKGROUND_COLOR);
|
chart.setBackgroundColor(BACKGROUND_COLOR);
|
||||||
chart.setDescriptionColor(DESCRIPTION_COLOR);
|
chart.getDescription().setTextColor(DESCRIPTION_COLOR);
|
||||||
chart.setDescription(getString(R.string.live_activity_steps_per_minute_history));
|
chart.getDescription().setText(getString(R.string.live_activity_steps_per_minute_history));
|
||||||
chart.setNoDataText(getString(R.string.live_activity_start_your_activity));
|
chart.setNoDataText(getString(R.string.live_activity_start_your_activity));
|
||||||
chart.getLegend().setEnabled(false);
|
chart.getLegend().setEnabled(false);
|
||||||
Paint infoPaint = chart.getPaint(Chart.PAINT_INFO);
|
Paint infoPaint = chart.getPaint(Chart.PAINT_INFO);
|
||||||
@ -447,7 +445,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
mHistorySet.setAxisDependency(YAxis.AxisDependency.LEFT);
|
mHistorySet.setAxisDependency(YAxis.AxisDependency.LEFT);
|
||||||
mHistorySet.setColor(akActivity.color);
|
mHistorySet.setColor(akActivity.color);
|
||||||
mHistorySet.setDrawCircles(false);
|
mHistorySet.setDrawCircles(false);
|
||||||
mHistorySet.setDrawCubic(true);
|
mHistorySet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
|
||||||
mHistorySet.setDrawFilled(true);
|
mHistorySet.setDrawFilled(true);
|
||||||
mHistorySet.setDrawValues(false);
|
mHistorySet.setDrawValues(false);
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ public class SingleEntryValueAnimator extends ChartAnimator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setEntryYValue(float value) {
|
public void setEntryYValue(float value) {
|
||||||
this.previousValue = entry.getVal();
|
this.previousValue = entry.getY();
|
||||||
entry.setVal(value);
|
entry.setY(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -38,10 +38,10 @@ public class SingleEntryValueAnimator extends ChartAnimator {
|
|||||||
|
|
||||||
float startAnim;
|
float startAnim;
|
||||||
float endAnim = 1f;
|
float endAnim = 1f;
|
||||||
if (entry.getVal() == 0f) {
|
if (entry.getY() == 0f) {
|
||||||
startAnim = 0f;
|
startAnim = 0f;
|
||||||
} else {
|
} else {
|
||||||
startAnim = previousValue / entry.getVal();
|
startAnim = previousValue / entry.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOG.debug("anim factors: " + startAnim + ", " + endAnim);
|
// LOG.debug("anim factors: " + startAnim + ", " + endAnim);
|
||||||
|
@ -11,12 +11,14 @@ import com.github.mikephil.charting.animation.Easing;
|
|||||||
import com.github.mikephil.charting.charts.Chart;
|
import com.github.mikephil.charting.charts.Chart;
|
||||||
import com.github.mikephil.charting.charts.CombinedChart;
|
import com.github.mikephil.charting.charts.CombinedChart;
|
||||||
import com.github.mikephil.charting.charts.PieChart;
|
import com.github.mikephil.charting.charts.PieChart;
|
||||||
|
import com.github.mikephil.charting.components.LegendEntry;
|
||||||
import com.github.mikephil.charting.components.XAxis;
|
import com.github.mikephil.charting.components.XAxis;
|
||||||
import com.github.mikephil.charting.components.YAxis;
|
import com.github.mikephil.charting.components.YAxis;
|
||||||
import com.github.mikephil.charting.data.Entry;
|
import com.github.mikephil.charting.data.Entry;
|
||||||
import com.github.mikephil.charting.data.PieData;
|
import com.github.mikephil.charting.data.PieData;
|
||||||
import com.github.mikephil.charting.data.PieDataSet;
|
import com.github.mikephil.charting.data.PieDataSet;
|
||||||
import com.github.mikephil.charting.formatter.ValueFormatter;
|
import com.github.mikephil.charting.data.PieEntry;
|
||||||
|
import com.github.mikephil.charting.formatter.IValueFormatter;
|
||||||
import com.github.mikephil.charting.utils.ViewPortHandler;
|
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -62,22 +64,23 @@ public class SleepChartFragment extends AbstractChartFragment {
|
|||||||
ActivityAnalysis analysis = new ActivityAnalysis();
|
ActivityAnalysis analysis = new ActivityAnalysis();
|
||||||
ActivityAmounts amounts = analysis.calculateActivityAmounts(samples);
|
ActivityAmounts amounts = analysis.calculateActivityAmounts(samples);
|
||||||
PieData data = new PieData();
|
PieData data = new PieData();
|
||||||
List<Entry> entries = new ArrayList<>();
|
List<PieEntry> entries = new ArrayList<>();
|
||||||
List<Integer> colors = new ArrayList<>();
|
List<Integer> colors = new ArrayList<>();
|
||||||
int index = 0;
|
// int index = 0;
|
||||||
long totalSeconds = 0;
|
long totalSeconds = 0;
|
||||||
for (ActivityAmount amount : amounts.getAmounts()) {
|
for (ActivityAmount amount : amounts.getAmounts()) {
|
||||||
if ((amount.getActivityKind() & ActivityKind.TYPE_SLEEP) != 0) {
|
if ((amount.getActivityKind() & ActivityKind.TYPE_SLEEP) != 0) {
|
||||||
long value = amount.getTotalSeconds();
|
long value = amount.getTotalSeconds();
|
||||||
totalSeconds += value;
|
totalSeconds += value;
|
||||||
entries.add(new Entry(value, index++));
|
// entries.add(new PieEntry(value, index++));
|
||||||
|
entries.add(new PieEntry(value, amount.getName(getActivity())));
|
||||||
colors.add(getColorFor(amount.getActivityKind()));
|
colors.add(getColorFor(amount.getActivityKind()));
|
||||||
data.addXValue(amount.getName(getActivity()));
|
// data.addXValue(amount.getName(getActivity()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String totalSleep = DateTimeUtils.formatDurationHoursMinutes(totalSeconds, TimeUnit.SECONDS);
|
String totalSleep = DateTimeUtils.formatDurationHoursMinutes(totalSeconds, TimeUnit.SECONDS);
|
||||||
PieDataSet set = new PieDataSet(entries, "");
|
PieDataSet set = new PieDataSet(entries, "");
|
||||||
set.setValueFormatter(new ValueFormatter() {
|
set.setValueFormatter(new IValueFormatter() {
|
||||||
@Override
|
@Override
|
||||||
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
|
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
|
||||||
return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS);
|
return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS);
|
||||||
@ -138,16 +141,16 @@ public class SleepChartFragment extends AbstractChartFragment {
|
|||||||
|
|
||||||
private void setupSleepAmountChart() {
|
private void setupSleepAmountChart() {
|
||||||
mSleepAmountChart.setBackgroundColor(BACKGROUND_COLOR);
|
mSleepAmountChart.setBackgroundColor(BACKGROUND_COLOR);
|
||||||
mSleepAmountChart.setDescriptionColor(DESCRIPTION_COLOR);
|
mSleepAmountChart.getDescription().setTextColor(DESCRIPTION_COLOR);
|
||||||
mSleepAmountChart.setDescription("");
|
mSleepAmountChart.getDescription().setText("");
|
||||||
mSleepAmountChart.setNoDataTextDescription("");
|
// mSleepAmountChart.getDescription().setNoDataTextDescription("");
|
||||||
mSleepAmountChart.setNoDataText("");
|
mSleepAmountChart.setNoDataText("");
|
||||||
mSleepAmountChart.getLegend().setEnabled(false);
|
mSleepAmountChart.getLegend().setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupActivityChart() {
|
private void setupActivityChart() {
|
||||||
mActivityChart.setBackgroundColor(BACKGROUND_COLOR);
|
mActivityChart.setBackgroundColor(BACKGROUND_COLOR);
|
||||||
mActivityChart.setDescriptionColor(DESCRIPTION_COLOR);
|
mActivityChart.getDescription().setTextColor(DESCRIPTION_COLOR);
|
||||||
configureBarLineChartDefaults(mActivityChart);
|
configureBarLineChartDefaults(mActivityChart);
|
||||||
|
|
||||||
XAxis x = mActivityChart.getXAxis();
|
XAxis x = mActivityChart.getXAxis();
|
||||||
@ -179,18 +182,26 @@ public class SleepChartFragment extends AbstractChartFragment {
|
|||||||
yAxisRight.setAxisMinValue(HeartRateUtils.MIN_HEART_RATE_VALUE);
|
yAxisRight.setAxisMinValue(HeartRateUtils.MIN_HEART_RATE_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setupLegend(Chart chart) {
|
protected void setupLegend(Chart chart) {
|
||||||
List<Integer> legendColors = new ArrayList<>(2);
|
List<LegendEntry> legendEntries = new ArrayList<>(3);
|
||||||
List<String> legendLabels = new ArrayList<>(2);
|
LegendEntry lightSleepEntry = new LegendEntry();
|
||||||
legendColors.add(akLightSleep.color);
|
lightSleepEntry.label = akLightSleep.label;
|
||||||
legendLabels.add(akLightSleep.label);
|
lightSleepEntry.formColor = akLightSleep.color;
|
||||||
legendColors.add(akDeepSleep.color);
|
legendEntries.add(lightSleepEntry);
|
||||||
legendLabels.add(akDeepSleep.label);
|
|
||||||
|
LegendEntry deepSleepEntry = new LegendEntry();
|
||||||
|
deepSleepEntry.label = akDeepSleep.label;
|
||||||
|
deepSleepEntry.formColor = akDeepSleep.color;
|
||||||
|
legendEntries.add(deepSleepEntry);
|
||||||
|
|
||||||
if (supportsHeartrate(getChartsHost().getDevice())) {
|
if (supportsHeartrate(getChartsHost().getDevice())) {
|
||||||
legendColors.add(HEARTRATE_COLOR);
|
LegendEntry hrEntry = new LegendEntry();
|
||||||
legendLabels.add(HEARTRATE_LABEL);
|
hrEntry.label = HEARTRATE_LABEL;
|
||||||
|
hrEntry.formColor = HEARTRATE_COLOR;
|
||||||
|
legendEntries.add(hrEntry);
|
||||||
}
|
}
|
||||||
chart.getLegend().setCustom(legendColors, legendLabels);
|
chart.getLegend().setCustom(legendEntries);
|
||||||
chart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
chart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,6 +212,7 @@ public class SleepChartFragment extends AbstractChartFragment {
|
|||||||
return super.getAllSamples(db, device, tsFrom, tsTo);
|
return super.getAllSamples(db, device, tsFrom, tsTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void renderCharts() {
|
protected void renderCharts() {
|
||||||
mActivityChart.animateX(ANIM_TIME, Easing.EasingOption.EaseInOutQuart);
|
mActivityChart.animateX(ANIM_TIME, Easing.EasingOption.EaseInOutQuart);
|
||||||
mSleepAmountChart.invalidate();
|
mSleepAmountChart.invalidate();
|
||||||
|
@ -19,6 +19,9 @@ import com.github.mikephil.charting.data.CombinedData;
|
|||||||
import com.github.mikephil.charting.data.Entry;
|
import com.github.mikephil.charting.data.Entry;
|
||||||
import com.github.mikephil.charting.data.PieData;
|
import com.github.mikephil.charting.data.PieData;
|
||||||
import com.github.mikephil.charting.data.PieDataSet;
|
import com.github.mikephil.charting.data.PieDataSet;
|
||||||
|
import com.github.mikephil.charting.data.PieEntry;
|
||||||
|
import com.github.mikephil.charting.formatter.IValueFormatter;
|
||||||
|
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -81,26 +84,35 @@ 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<>();
|
||||||
List<String> labels = new ArrayList<>();
|
final String[] labels = new String[7];
|
||||||
|
|
||||||
for (int counter = 0; counter < 7; counter++) {
|
for (int counter = 0; counter < 7; counter++) {
|
||||||
entries.add(new BarEntry(analysis.calculateTotalSteps(getSamplesOfDay(db, day, device)), counter));
|
entries.add(new BarEntry(counter, analysis.calculateTotalSteps(getSamplesOfDay(db, day, device))));
|
||||||
labels.add(day.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, mLocale));
|
labels[counter] = 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, set);
|
// BarData barData = new BarData(labels);
|
||||||
|
BarData barData = new BarData();
|
||||||
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();
|
||||||
combinedChart.getAxisLeft().addLimitLine(target);
|
combinedChart.getAxisLeft().addLimitLine(target);
|
||||||
|
|
||||||
CombinedData combinedData = new CombinedData(labels);
|
CombinedData combinedData = new CombinedData();
|
||||||
combinedData.setData(barData);
|
combinedData.setData(barData);
|
||||||
|
combinedData.setValueFormatter(weekDayValueFormatter);
|
||||||
return new DefaultChartsData(combinedData);
|
return new DefaultChartsData(combinedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,19 +124,15 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
|||||||
int totalSteps = analysis.calculateTotalSteps(getSamplesOfDay(db, day, device));
|
int totalSteps = analysis.calculateTotalSteps(getSamplesOfDay(db, day, device));
|
||||||
|
|
||||||
PieData data = new PieData();
|
PieData data = new PieData();
|
||||||
List<Entry> entries = new ArrayList<>();
|
List<PieEntry> entries = new ArrayList<>();
|
||||||
List<Integer> colors = new ArrayList<>();
|
List<Integer> colors = new ArrayList<>();
|
||||||
|
|
||||||
entries.add(new Entry(totalSteps, 0));
|
entries.add(new PieEntry(totalSteps, "")); //we don't want labels on the pie chart
|
||||||
colors.add(akActivity.color);
|
colors.add(akActivity.color);
|
||||||
//we don't want labels on the pie chart
|
|
||||||
data.addXValue("");
|
|
||||||
|
|
||||||
if (totalSteps < mTargetSteps) {
|
if (totalSteps < mTargetSteps) {
|
||||||
entries.add(new Entry((mTargetSteps - totalSteps), 1));
|
entries.add(new PieEntry((mTargetSteps - totalSteps))); //we don't want labels on the pie chart
|
||||||
colors.add(Color.GRAY);
|
colors.add(Color.GRAY);
|
||||||
//we don't want labels on the pie chart
|
|
||||||
data.addXValue("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PieDataSet set = new PieDataSet(entries, "");
|
PieDataSet set = new PieDataSet(entries, "");
|
||||||
@ -168,9 +176,9 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
|||||||
|
|
||||||
private void setupTodayStepsChart() {
|
private void setupTodayStepsChart() {
|
||||||
mTodayStepsChart.setBackgroundColor(BACKGROUND_COLOR);
|
mTodayStepsChart.setBackgroundColor(BACKGROUND_COLOR);
|
||||||
mTodayStepsChart.setDescriptionColor(DESCRIPTION_COLOR);
|
mTodayStepsChart.getDescription().setTextColor(DESCRIPTION_COLOR);
|
||||||
mTodayStepsChart.setDescription(getContext().getString(R.string.weeksteps_today_steps_description, mTargetSteps));
|
mTodayStepsChart.getDescription().setText(getContext().getString(R.string.weeksteps_today_steps_description, String.valueOf(mTargetSteps)));
|
||||||
mTodayStepsChart.setNoDataTextDescription("");
|
// mTodayStepsChart.setNoDataTextDescription("");
|
||||||
mTodayStepsChart.setNoDataText("");
|
mTodayStepsChart.setNoDataText("");
|
||||||
mTodayStepsChart.getLegend().setEnabled(false);
|
mTodayStepsChart.getLegend().setEnabled(false);
|
||||||
// setupLegend(mTodayStepsChart);
|
// setupLegend(mTodayStepsChart);
|
||||||
@ -178,8 +186,8 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
|||||||
|
|
||||||
private void setupWeekStepsChart() {
|
private void setupWeekStepsChart() {
|
||||||
mWeekStepsChart.setBackgroundColor(BACKGROUND_COLOR);
|
mWeekStepsChart.setBackgroundColor(BACKGROUND_COLOR);
|
||||||
mWeekStepsChart.setDescriptionColor(DESCRIPTION_COLOR);
|
mWeekStepsChart.getDescription().setTextColor(DESCRIPTION_COLOR);
|
||||||
mWeekStepsChart.setDescription("");
|
mWeekStepsChart.getDescription().setText("");
|
||||||
|
|
||||||
configureBarLineChartDefaults(mWeekStepsChart);
|
configureBarLineChartDefaults(mWeekStepsChart);
|
||||||
|
|
||||||
@ -205,6 +213,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
|||||||
yAxisRight.setTextColor(CHART_TEXT_COLOR);
|
yAxisRight.setTextColor(CHART_TEXT_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setupLegend(Chart chart) {
|
protected void setupLegend(Chart chart) {
|
||||||
// List<Integer> legendColors = new ArrayList<>(1);
|
// List<Integer> legendColors = new ArrayList<>(1);
|
||||||
// List<String> legendLabels = new ArrayList<>(1);
|
// List<String> legendLabels = new ArrayList<>(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user