Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions LoopFollow/Controllers/Graphs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -801,10 +801,14 @@ extension MainViewController {

topBG = Storage.shared.minBGScale.value
for i in 0 ..< entries.count {
if Double(entries[i].sgv) > topBG - maxBGOffset {
topBG = Double(entries[i].sgv) + maxBGOffset
// Clamp the plotted y-value to the same bounds the header text uses
// (HIGH/LOW), so the graph stays consistent with the main display.
// The pill tooltip still shows the raw reading.
let plottedSgv = Double(min(max(entries[i].sgv, globalVariables.minDisplayGlucose), globalVariables.maxDisplayGlucose))
if plottedSgv > topBG - maxBGOffset {
topBG = plottedSgv + maxBGOffset
}
let value = ChartDataEntry(x: Double(entries[i].date), y: Double(entries[i].sgv), data: formatPillText(line1: Localizer.toDisplayUnits(String(entries[i].sgv)), time: entries[i].date))
let value = ChartDataEntry(x: Double(entries[i].date), y: plottedSgv, data: formatPillText(line1: Localizer.toDisplayUnits(String(entries[i].sgv)), time: entries[i].date))
mainChart.append(value)
smallChart.append(value)

Expand Down
2 changes: 1 addition & 1 deletion LoopFollow/Helpers/Globals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum globalVariables {
// Glucose display range (mg/dL)
// Values at or below the min are shown as "LOW" on the main display;
// values at or above the max are shown as "HIGH". Also used to clamp
// prediction values on the graph.
// BG readings and prediction values on the graph.
static let minDisplayGlucose: Int = 39
static let maxDisplayGlucose: Int = 400
}