Sfoglia il codice sorgente

fix x axis for glucose graph in dynamic island

polscm32 2 anni fa
parent
commit
5be9d74963

+ 1 - 0
FreeAPS/Sources/Services/LiveActivity/LiveActitiyShared.swift

@@ -8,6 +8,7 @@ struct LiveActivityAttributes: ActivityAttributes {
         let change: String
         let change: String
         let date: Date
         let date: Date
         let chart: [Int?]
         let chart: [Int?]
+        let chartDate: [Date?]
     }
     }
 
 
     let startDate: Date
     let startDate: Date

+ 13 - 4
FreeAPS/Sources/Services/LiveActivity/LiveActivityBridge.swift

@@ -63,8 +63,16 @@ extension LiveActivityAttributes.ContentState {
         }) ?? ""
         }) ?? ""
 
 
         let chartBG = chart.map(\.glucose)
         let chartBG = chart.map(\.glucose)
-
-        self.init(bg: formattedBG, trendSystemImage: trendString, change: change, date: bg.dateString, chart: chartBG)
+        let chartDate = chart.map(\.dateString)
+
+        self.init(
+            bg: formattedBG,
+            trendSystemImage: trendString,
+            change: change,
+            date: bg.dateString,
+            chart: chartBG,
+            chartDate: chartDate
+        )
     }
     }
 }
 }
 
 
@@ -196,12 +204,13 @@ extension LiveActivityBridge: GlucoseObserver {
             self.latestGlucose = glucose.last
             self.latestGlucose = glucose.last
         }
         }
 
 
-        let last200Glucose = Array(glucose.suffix(200))
+        let last72Glucose = Array(glucose.dropLast().suffix(72))
 
 
         guard let bg = glucose.last, let content = LiveActivityAttributes.ContentState(
         guard let bg = glucose.last, let content = LiveActivityAttributes.ContentState(
             new: bg,
             new: bg,
             prev: latestGlucose,
             prev: latestGlucose,
-            mmol: settings.units == .mmolL, chart: last200Glucose
+            mmol: settings.units == .mmolL,
+            chart: last72Glucose
         ) else {
         ) else {
             // no bg or value stale. Don't update the activity if there already is one, just let it turn stale so that it can still be used once current bg is available again
             // no bg or value stale. Don't update the activity if there already is one, just let it turn stale so that it can still be used once current bg is available again
             return
             return

+ 3 - 17
LiveActivity/LiveActivity.swift

@@ -42,30 +42,16 @@ struct LiveActivity: Widget {
         }
         }
     }
     }
 
 
-//
-//    @ViewBuilder func chart(context: ActivityViewContext<LiveActivityAttributes>) -> some View {
-//        if context.isStale {
-//            Text("--")
-//        } else {
-//            Chart {
-//                PointMark(
-//                    x: .value("Time", context.state.chart.count),
-//                    y: .value("Value", context.state.chart.count)
-//                )
-//            }
-//        }
-//    }
-
     @ViewBuilder func chart(context: ActivityViewContext<LiveActivityAttributes>) -> some View {
     @ViewBuilder func chart(context: ActivityViewContext<LiveActivityAttributes>) -> some View {
         if context.isStale {
         if context.isStale {
             Text("--")
             Text("--")
         } else {
         } else {
             Chart {
             Chart {
                 ForEach(context.state.chart.indices, id: \.self) { index in
                 ForEach(context.state.chart.indices, id: \.self) { index in
-                    PointMark(
-                        x: .value("Time", index),
+                    LineMark(
+                        x: .value("Time", context.state.chartDate[index] ?? Date()),
                         y: .value("Value", context.state.chart[index] ?? 0)
                         y: .value("Value", context.state.chart[index] ?? 0)
-                    )
+                    ).foregroundStyle(Color.blue.gradient).symbolSize(12)
                 }
                 }
             }
             }
         }
         }