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
32 changes: 20 additions & 12 deletions LoopFollow/Charts/BGChartModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ final class BGChartModel: ObservableObject {
showMidnight = Storage.shared.showMidnightLines.value
smallGraphTreatments = Storage.shared.smallGraphTreatments.value

// Advanced-settings visibility toggles. The Nightscout controllers
// collect the data regardless (it also feeds the info rows), so hidden
// kinds are dropped here at render time.
let showBasal = Storage.shared.graphBasal.value
let showBolus = Storage.shared.graphBolus.value
let showCarbs = Storage.shared.graphCarbs.value
let showOtherTreatments = Storage.shared.graphOtherTreatments.value

let isLoop = Storage.shared.device.value == "Loop"
overrideColor = isLoop ? .green : .purple
tempTargetColor = isLoop ? .purple : .green
Expand Down Expand Up @@ -436,7 +444,7 @@ final class BGChartModel: ObservableObject {
cobPrediction = vc.cobPredictionData.map { BGPoint(date: Date(timeIntervalSince1970: $0.date), value: Double($0.sgv), color: .purple) }
uamPrediction = vc.uamPredictionData.map { BGPoint(date: Date(timeIntervalSince1970: $0.date), value: Double($0.sgv), color: .purple) }

let bolusPoints = vc.bolusData.map {
let bolusPoints = (showBolus ? vc.bolusData : []).map {
let dose = self.formatDose($0.value)
return TreatmentPoint(
date: Date(timeIntervalSince1970: $0.date),
Expand All @@ -446,7 +454,7 @@ final class BGChartModel: ObservableObject {
pillText: "Bolus\n\(dose)U\n\(pillTimeString(for: Date(timeIntervalSince1970: $0.date)))"
)
}
carbs = Self.spread(vc.carbData.map {
carbs = Self.spread((showCarbs ? vc.carbData : []).map {
let grams = Int($0.value)
var label = "\(grams)"
if $0.absorptionTime > 0, Storage.shared.showAbsorption.value {
Expand All @@ -460,7 +468,7 @@ final class BGChartModel: ObservableObject {
pillText: "Carbs\n\(grams)g\n\(pillTimeString(for: Date(timeIntervalSince1970: $0.date)))"
)
}, minGap: Spread.carbGap, maxShift: Spread.carbShift)
let smbPoints = vc.smbData.map {
let smbPoints = (showBolus ? vc.smbData : []).map {
let dose = self.formatDose($0.value)
return TreatmentPoint(
date: Date(timeIntervalSince1970: $0.date),
Expand All @@ -471,7 +479,7 @@ final class BGChartModel: ObservableObject {
)
}
(boluses, smbs) = Self.spreadTogether(bolusPoints, smbPoints, minGap: Spread.bolusGap, maxShift: Spread.bolusShift)
bgChecks = vc.bgCheckData.map {
bgChecks = (showOtherTreatments ? vc.bgCheckData : []).map {
TreatmentPoint(
date: Date(timeIntervalSince1970: $0.date),
value: Double($0.sgv),
Expand All @@ -480,16 +488,16 @@ final class BGChartModel: ObservableObject {
pillText: "BG Check\n\(Localizer.toDisplayUnits(String($0.sgv)))\n\(pillTimeString(for: Date(timeIntervalSince1970: $0.date)))"
)
}
suspends = vc.suspendGraphData.map {
suspends = (showOtherTreatments ? vc.suspendGraphData : []).map {
TreatmentPoint(date: Date(timeIntervalSince1970: $0.date), value: Double($0.sgv), sgv: Double($0.sgv), label: "", pillText: "Suspend\n\(pillTimeString(for: Date(timeIntervalSince1970: $0.date)))")
}
resumes = vc.resumeGraphData.map {
resumes = (showOtherTreatments ? vc.resumeGraphData : []).map {
TreatmentPoint(date: Date(timeIntervalSince1970: $0.date), value: Double($0.sgv), sgv: Double($0.sgv), label: "", pillText: "Resume\n\(pillTimeString(for: Date(timeIntervalSince1970: $0.date)))")
}
sensorStarts = vc.sensorStartGraphData.map {
sensorStarts = (showOtherTreatments ? vc.sensorStartGraphData : []).map {
TreatmentPoint(date: Date(timeIntervalSince1970: $0.date), value: Double($0.sgv), sgv: Double($0.sgv), label: "", pillText: "Sensor Start\n\(pillTimeString(for: Date(timeIntervalSince1970: $0.date)))")
}
notes = vc.noteGraphData.map {
notes = (showOtherTreatments ? vc.noteGraphData : []).map {
TreatmentPoint(
date: Date(timeIntervalSince1970: $0.date),
value: Double($0.sgv),
Expand All @@ -499,12 +507,12 @@ final class BGChartModel: ObservableObject {
)
}

basalScheduled = vc.basalScheduleData.map {
basalScheduled = (showBasal ? vc.basalScheduleData : []).map {
ScheduledBasalPoint(date: Date(timeIntervalSince1970: $0.date), rate: $0.basalRate)
}

var steps: [BasalStep] = []
let sortedBasal = vc.basalData.sorted { $0.date < $1.date }
let sortedBasal = (showBasal ? vc.basalData : []).sorted { $0.date < $1.date }
for i in 0 ..< sortedBasal.count {
let start = sortedBasal[i].date
let end = i + 1 < sortedBasal.count
Expand All @@ -523,7 +531,7 @@ final class BGChartModel: ObservableObject {

let yTop = maxBG - 5
let yBottom = maxBG - 25
overrides = vc.overrideGraphData.map {
overrides = (showOtherTreatments ? vc.overrideGraphData : []).map {
let overrideName = $0.reason.trimmingCharacters(in: .whitespacesAndNewlines)
let displayName = overrideName.isEmpty ? "Override" : overrideName
return BandRect(
Expand All @@ -535,7 +543,7 @@ final class BGChartModel: ObservableObject {
pillText: "Override\n\(displayName)\n\(pillTimeString(for: Date(timeIntervalSince1970: $0.date)))"
)
}
tempTargets = vc.tempTargetGraphData.map {
tempTargets = (showOtherTreatments ? vc.tempTargetGraphData : []).map {
let target = $0.correctionRange.first.map { String($0) } ?? ""
// Temp targets render at the BG level they target (±5 mg/dL);
// only overrides live in the top strip.
Expand Down
9 changes: 9 additions & 0 deletions LoopFollow/Charts/BGChartStubs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ extension MainViewController {

func updateBGGraphSettings() {
chartModel.rebuild()

// Re-route the stored predBGs in case the prediction style
// (cone/lines) changed; rebuild() alone only redraws what was
// already routed.
updateOpenAPSPredictionDisplay()

// The yesterday overlay is built during the BG fetch and needs an
// extra day of history, so reload the BG window when it's toggled.
TaskScheduler.shared.rescheduleTask(id: .fetchBG, to: Date())
}

private func recomputeTopBG() {
Expand Down
4 changes: 4 additions & 0 deletions LoopFollow/Settings/AdvancedSettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,28 @@ class AdvancedSettingsViewModel: ObservableObject {
@Published var graphBasal: Bool {
didSet {
Storage.shared.graphBasal.value = graphBasal
Observable.shared.chartSettingsChanged.value = true
}
}

@Published var graphBolus: Bool {
didSet {
Storage.shared.graphBolus.value = graphBolus
Observable.shared.chartSettingsChanged.value = true
}
}

@Published var graphCarbs: Bool {
didSet {
Storage.shared.graphCarbs.value = graphCarbs
Observable.shared.chartSettingsChanged.value = true
}
}

@Published var graphOtherTreatments: Bool {
didSet {
Storage.shared.graphOtherTreatments.value = graphOtherTreatments
Observable.shared.chartSettingsChanged.value = true
}
}

Expand Down
Loading