1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 04:16:49 +01:00

Add average line to HR chart

This commit is contained in:
José Rebelo 2024-10-12 19:00:26 +01:00
parent b4426c61be
commit c2668d2e6c

View File

@ -1,5 +1,6 @@
package nodomain.freeyourgadget.gadgetbridge.activities.charts; package nodomain.freeyourgadget.gadgetbridge.activities.charts;
import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -13,6 +14,7 @@ import androidx.core.content.ContextCompat;
import com.github.mikephil.charting.charts.Chart; import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.LegendEntry; import com.github.mikephil.charting.components.LegendEntry;
import com.github.mikephil.charting.components.LimitLine;
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;
@ -187,6 +189,21 @@ public class HeartRateDailyFragment extends AbstractChartFragment<HeartRateDaily
hrEntry.label = getTitle(); hrEntry.label = getTitle();
hrEntry.formColor = HEARTRATE_COLOR; hrEntry.formColor = HEARTRATE_COLOR;
legendEntries.add(hrEntry); legendEntries.add(hrEntry);
if (GBApplication.getPrefs().getBoolean("charts_show_average", true)) {
LegendEntry hrAverageEntry = new LegendEntry();
hrAverageEntry.label = getString(R.string.hr_average);
hrAverageEntry.formColor = Color.RED;
legendEntries.add(hrAverageEntry);
}
//if (supportsHeartRateRestingMeasurement()) {
// LegendEntry hrRestingEntry = new LegendEntry();
// hrRestingEntry.label = getString(R.string.hr_resting);
// hrRestingEntry.formColor = Color.GRAY;
// legendEntries.add(hrRestingEntry);
//}
chart.getLegend().setCustom(legendEntries); chart.getLegend().setCustom(legendEntries);
chart.getLegend().setTextColor(LEGEND_TEXT_COLOR); chart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
chart.getLegend().setWordWrapEnabled(true); chart.getLegend().setWordWrapEnabled(true);
@ -259,6 +276,24 @@ public class HeartRateDailyFragment extends AbstractChartFragment<HeartRateDaily
hrLineChart.getXAxis().setValueFormatter(new SampleXLabelFormatter(tsTranslation, "HH:mm")); hrLineChart.getXAxis().setValueFormatter(new SampleXLabelFormatter(tsTranslation, "HH:mm"));
hrLineChart.setData(new LineData(dataSet)); hrLineChart.setData(new LineData(dataSet));
hrLineChart.getAxisLeft().removeAllLimitLines();
if (GBApplication.getPrefs().getBoolean("charts_show_average", true)) {
final LimitLine averageLine = new LimitLine(average);
averageLine.setLineWidth(1.5f);
averageLine.enableDashedLine(15f, 10f, 0f);
averageLine.setLineColor(Color.RED);
hrLineChart.getAxisLeft().addLimitLine(averageLine);
}
//if (data.restingHeartRate > 0) {
// final LimitLine restingLine = new LimitLine(data.restingHeartRate);
// restingLine.setLineWidth(1.5f);
// restingLine.enableDashedLine(15f, 10f, 0f);
// restingLine.setLineColor(Color.GRAY);
// hrLineChart.getAxisLeft().addLimitLine(restingLine);
//}
} }
protected static class HeartRateData extends ChartsData { protected static class HeartRateData extends ChartsData {