Browse Source

fix graph updating with picker on new swift chart

polscm32 2 years ago
parent
commit
d44145601a

+ 2 - 2
FreeAPS/Sources/Modules/Home/HomeStateModel.swift

@@ -290,8 +290,8 @@ extension Home {
             offsetComponents.hour = -Int(offset)
 
             let startTime = calendar.date(byAdding: offsetComponents, to: date)!
-            print("******************")
-            print("die voll krasse start time ist: \(startTime)")
+//            print("******************")
+//            print("die voll krasse start time ist: \(startTime)")
 
             let bolusesForCurrentDay = boluses.filter { $0.timestamp >= startTime && $0.type == .bolus }
 

+ 6 - 3
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView2.swift

@@ -112,7 +112,7 @@ struct MainChartView2: View {
         NavigationStack {
             ScrollView {
                 VStack {
-                    let filteredGlucose: [BloodGlucose] = filterGlucoseData(for: 6)
+                    let filteredGlucose: [BloodGlucose] = filterGlucoseData(for: screenHours)
 
                     Chart(filteredGlucose) {
                         PointMark(
@@ -136,13 +136,16 @@ struct MainChartView2: View {
         }
     }
 
-    private func filterGlucoseData(for hours: Int) -> [BloodGlucose] {
+    private func filterGlucoseData(for hours: Int16) -> [BloodGlucose] {
         guard hours > 0 else {
             return glucose
         }
 
         let currentDate = Date()
-        let startDate = Calendar.current.date(byAdding: .hour, value: -hours, to: currentDate) ?? currentDate
+        let startDate = Calendar.current.date(byAdding: .hour, value: -Int(hours), to: currentDate) ?? currentDate
+
+//        print("die hours sind ++++++++++++++++++++")
+//        print(hours)
 
         return glucose.filter { $0.dateString >= startDate }
     }