|
@@ -43,6 +43,7 @@ enum GraphDataIndex: Int {
|
|
|
case smb = 16
|
|
case smb = 16
|
|
|
case tempTarget = 17
|
|
case tempTarget = 17
|
|
|
case predictionCone = 18
|
|
case predictionCone = 18
|
|
|
|
|
+ case yesterday = 19
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
extension GraphDataIndex {
|
|
extension GraphDataIndex {
|
|
@@ -67,6 +68,7 @@ extension GraphDataIndex {
|
|
|
case .smb: return "SMB"
|
|
case .smb: return "SMB"
|
|
|
case .tempTarget: return "Temp Target"
|
|
case .tempTarget: return "Temp Target"
|
|
|
case .predictionCone: return "Prediction Cone"
|
|
case .predictionCone: return "Prediction Cone"
|
|
|
|
|
+ case .yesterday: return "Yesterday"
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -638,6 +640,16 @@ extension MainViewController {
|
|
|
lineCone.axisDependency = YAxis.AxisDependency.right
|
|
lineCone.axisDependency = YAxis.AxisDependency.right
|
|
|
data.append(lineCone)
|
|
data.append(lineCone)
|
|
|
|
|
|
|
|
|
|
+ // Dataset 19: Yesterday's BG comparison overlay (thin dimmed gray line, no dots)
|
|
|
|
|
+ let lineYesterday = LineChartDataSet(entries: [ChartDataEntry](), label: "")
|
|
|
|
|
+ lineYesterday.lineWidth = 1.5
|
|
|
|
|
+ lineYesterday.setColor(NSUIColor.systemGray, alpha: 0.4)
|
|
|
|
|
+ lineYesterday.drawCirclesEnabled = false
|
|
|
|
|
+ lineYesterday.drawValuesEnabled = false
|
|
|
|
|
+ lineYesterday.highlightEnabled = false
|
|
|
|
|
+ lineYesterday.axisDependency = YAxis.AxisDependency.right
|
|
|
|
|
+ data.append(lineYesterday)
|
|
|
|
|
+
|
|
|
data.setValueFont(UIFont.systemFont(ofSize: 12))
|
|
data.setValueFont(UIFont.systemFont(ofSize: 12))
|
|
|
|
|
|
|
|
// Add marker popups for bolus and carbs
|
|
// Add marker popups for bolus and carbs
|
|
@@ -829,6 +841,11 @@ extension MainViewController {
|
|
|
BGChart.data?.notifyDataChanged()
|
|
BGChart.data?.notifyDataChanged()
|
|
|
BGChart.notifyDataSetChanged()
|
|
BGChart.notifyDataSetChanged()
|
|
|
|
|
|
|
|
|
|
+ // Reflect the yesterday overlay toggle immediately, and reload the BG window
|
|
|
|
|
+ // so the extra day of history is fetched (or dropped) when the toggle changed.
|
|
|
|
|
+ updateYesterdayBGGraph()
|
|
|
|
|
+ TaskScheduler.shared.rescheduleTask(id: .fetchBG, to: Date())
|
|
|
|
|
+
|
|
|
// Re-render prediction display in case display type changed
|
|
// Re-render prediction display in case display type changed
|
|
|
updateOpenAPSPredictionDisplay()
|
|
updateOpenAPSPredictionDisplay()
|
|
|
}
|
|
}
|
|
@@ -898,6 +915,8 @@ extension MainViewController {
|
|
|
BGChartFull.data?.notifyDataChanged()
|
|
BGChartFull.data?.notifyDataChanged()
|
|
|
BGChartFull.notifyDataSetChanged()
|
|
BGChartFull.notifyDataSetChanged()
|
|
|
|
|
|
|
|
|
|
+ updateYesterdayBGGraph()
|
|
|
|
|
+
|
|
|
// The initial zoom is a one-shot, relative to the chart's current
|
|
// The initial zoom is a one-shot, relative to the chart's current
|
|
|
// viewport. Skip it until the chart actually has a width — otherwise a
|
|
// viewport. Skip it until the chart actually has a width — otherwise a
|
|
|
// refresh that lands while the view is loaded but off-screen (e.g. Home
|
|
// refresh that lands while the view is loaded but off-screen (e.g. Home
|
|
@@ -922,6 +941,32 @@ extension MainViewController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Populates (or clears) the dimmed "yesterday" comparison overlay on the main graph.
|
|
|
|
|
+ // Points in yesterdayBGData are already shifted +24h so they align with today's clock time.
|
|
|
|
|
+ func updateYesterdayBGGraph() {
|
|
|
|
|
+ let dataIndex = GraphDataIndex.yesterday.rawValue
|
|
|
|
|
+ guard let lineData = BGChart.lineData,
|
|
|
|
|
+ dataIndex < lineData.dataSets.count,
|
|
|
|
|
+ let dataSet = lineData.dataSets[dataIndex] as? LineChartDataSet
|
|
|
|
|
+ else {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ dataSet.removeAll(keepingCapacity: false)
|
|
|
|
|
+
|
|
|
|
|
+ if Storage.shared.showYesterdayLine.value {
|
|
|
|
|
+ for entry in yesterdayBGData {
|
|
|
|
|
+ // Clamp the plotted y-value to the same bounds the main BG line uses.
|
|
|
|
|
+ let plottedSgv = Double(min(max(entry.sgv, globalVariables.minDisplayGlucose), globalVariables.maxDisplayGlucose))
|
|
|
|
|
+ dataSet.append(ChartDataEntry(x: entry.date, y: plottedSgv))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BGChart.data?.dataSets[dataIndex].notifyDataSetChanged()
|
|
|
|
|
+ BGChart.data?.notifyDataChanged()
|
|
|
|
|
+ BGChart.notifyDataSetChanged()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
func updatePredictionGraph(color: UIColor? = nil) {
|
|
func updatePredictionGraph(color: UIColor? = nil) {
|
|
|
let dataIndex = 1
|
|
let dataIndex = 1
|
|
|
var mainChart = BGChart.lineData!.dataSets[dataIndex] as! LineChartDataSet
|
|
var mainChart = BGChart.lineData!.dataSets[dataIndex] as! LineChartDataSet
|