@@ -43,6 +43,7 @@ enum GraphDataIndex: Int {
4343 case smb = 16
4444 case tempTarget = 17
4545 case predictionCone = 18
46+ case yesterday = 19
4647}
4748
4849extension GraphDataIndex {
@@ -67,6 +68,7 @@ extension GraphDataIndex {
6768 case . smb: return " SMB "
6869 case . tempTarget: return " Temp Target "
6970 case . predictionCone: return " Prediction Cone "
71+ case . yesterday: return " Yesterday "
7072 }
7173 }
7274}
@@ -638,6 +640,16 @@ extension MainViewController {
638640 lineCone. axisDependency = YAxis . AxisDependency. right
639641 data. append ( lineCone)
640642
643+ // Dataset 19: Yesterday's BG comparison overlay (thin dimmed gray line, no dots)
644+ let lineYesterday = LineChartDataSet ( entries: [ ChartDataEntry] ( ) , label: " " )
645+ lineYesterday. lineWidth = 1.5
646+ lineYesterday. setColor ( NSUIColor . systemGray, alpha: 0.4 )
647+ lineYesterday. drawCirclesEnabled = false
648+ lineYesterday. drawValuesEnabled = false
649+ lineYesterday. highlightEnabled = false
650+ lineYesterday. axisDependency = YAxis . AxisDependency. right
651+ data. append ( lineYesterday)
652+
641653 data. setValueFont ( UIFont . systemFont ( ofSize: 12 ) )
642654
643655 // Add marker popups for bolus and carbs
@@ -829,6 +841,11 @@ extension MainViewController {
829841 BGChart . data? . notifyDataChanged ( )
830842 BGChart . notifyDataSetChanged ( )
831843
844+ // Reflect the yesterday overlay toggle immediately, and reload the BG window
845+ // so the extra day of history is fetched (or dropped) when the toggle changed.
846+ updateYesterdayBGGraph ( )
847+ TaskScheduler . shared. rescheduleTask ( id: . fetchBG, to: Date ( ) )
848+
832849 // Re-render prediction display in case display type changed
833850 updateOpenAPSPredictionDisplay ( )
834851 }
@@ -898,6 +915,8 @@ extension MainViewController {
898915 BGChartFull . data? . notifyDataChanged ( )
899916 BGChartFull . notifyDataSetChanged ( )
900917
918+ updateYesterdayBGGraph ( )
919+
901920 // The initial zoom is a one-shot, relative to the chart's current
902921 // viewport. Skip it until the chart actually has a width — otherwise a
903922 // refresh that lands while the view is loaded but off-screen (e.g. Home
@@ -922,6 +941,32 @@ extension MainViewController {
922941 }
923942 }
924943
944+ // Populates (or clears) the dimmed "yesterday" comparison overlay on the main graph.
945+ // Points in yesterdayBGData are already shifted +24h so they align with today's clock time.
946+ func updateYesterdayBGGraph( ) {
947+ let dataIndex = GraphDataIndex . yesterday. rawValue
948+ guard let lineData = BGChart . lineData,
949+ dataIndex < lineData. dataSets. count,
950+ let dataSet = lineData. dataSets [ dataIndex] as? LineChartDataSet
951+ else {
952+ return
953+ }
954+
955+ dataSet. removeAll ( keepingCapacity: false )
956+
957+ if Storage . shared. showYesterdayLine. value {
958+ for entry in yesterdayBGData {
959+ // Clamp the plotted y-value to the same bounds the main BG line uses.
960+ let plottedSgv = Double ( min ( max ( entry. sgv, globalVariables. minDisplayGlucose) , globalVariables. maxDisplayGlucose) )
961+ dataSet. append ( ChartDataEntry ( x: entry. date, y: plottedSgv) )
962+ }
963+ }
964+
965+ BGChart . data? . dataSets [ dataIndex] . notifyDataSetChanged ( )
966+ BGChart . data? . notifyDataChanged ( )
967+ BGChart . notifyDataSetChanged ( )
968+ }
969+
925970 func updatePredictionGraph( color: UIColor ? = nil ) {
926971 let dataIndex = 1
927972 var mainChart = BGChart . lineData!. dataSets [ dataIndex] as! LineChartDataSet
0 commit comments