From 1e0b7d331af2eefcb198fd10fec8a5272ee232b7 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 5 May 2018 19:09:22 +0200 Subject: [PATCH] Fix finding BG in graph for treatments before the first displayed BG. (cherry picked from commit 8bdafe3) --- .../androidaps/plugins/Overview/graphData/GraphData.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java index 8023e86ac0..1c8b27c113 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java @@ -320,14 +320,13 @@ public class GraphData { } private double getNearestBg(long date) { - double bg = 0; for (int r = bgReadingsArray.size() - 1; r >= 0; r--) { BgReading reading = bgReadingsArray.get(r); if (reading.date > date) continue; - bg = Profile.fromMgdlToUnits(reading.value, units); - break; + return Profile.fromMgdlToUnits(reading.value, units); } - return bg; + return bgReadingsArray.size() > 0 + ? Profile.fromMgdlToUnits(bgReadingsArray.get(0).value, units) : 0; } // scale in % of vertical size (like 0.3)