Yakov Karpov 5 лет назад
Родитель
Сommit
e9113c2553

+ 7 - 7
FreeAPS/Sources/Charts/Views/Charts/MainChartView.swift

@@ -2,9 +2,9 @@ import SwiftUI
 
 struct MainChartView: View {
     let maxWidth: CGFloat
-    let showHours: Int
-    let glucoseData: [BloodGlucose]
-    var predictionsData: [PredictionLineData]?
+    @Binding var showHours: Int
+    @Binding var glucoseData: [BloodGlucose]
+    @Binding var predictionsData: [PredictionLineData]?
     var body: some View {
         let allValues = getAllValues()
         let minValue = allValues.min() ?? 40
@@ -15,8 +15,8 @@ struct MainChartView: View {
                 minValue: minValue,
                 maxValue: maxValue,
                 maxWidth: maxWidth,
-                showHours: showHours,
-                glucoseData: glucoseData
+                showHours: $showHours,
+                glucoseData: $glucoseData
             ) { value in
                 GlucosePointView(value: value)
             }
@@ -24,8 +24,8 @@ struct MainChartView: View {
                 minValue: minValue,
                 maxValue: maxValue,
                 maxWidth: maxWidth,
-                data: predictionsData,
-                showHours: showHours
+                data: $predictionsData,
+                showHours: $showHours
             )
         }
     }

+ 4 - 34
FreeAPS/Sources/Charts/Views/Charts/PointChartView.swift

@@ -4,8 +4,10 @@ struct PointChartView<PointEntry: View>: View {
     let minValue: Int
     let maxValue: Int
     let maxWidth: CGFloat
-    let showHours: Int
-    let glucoseData: [BloodGlucose]
+
+    @Binding var showHours: Int
+    @Binding var glucoseData: [BloodGlucose]
+
     let pointEntry: (_: Int?) -> PointEntry
 
     let hoursMultiplier: Double = 14
@@ -69,35 +71,3 @@ extension PointChartView {
         }
     }
 }
-
-struct PointChartView_Previews: PreviewProvider {
-    static let sampleData = Array(SampleData.sampleData)
-
-    static let testingData = [
-        BloodGlucose(sgv: 3, direction: nil, date: 1_615_179_600, dateString: Date(), filtered: nil, noise: nil, glucose: nil),
-        BloodGlucose(sgv: 4, direction: nil, date: 1_615_179_900, dateString: Date(), filtered: nil, noise: nil, glucose: nil),
-        BloodGlucose(sgv: 5, direction: nil, date: 1_615_180_200, dateString: Date(), filtered: nil, noise: nil, glucose: nil),
-        BloodGlucose(sgv: 6, direction: nil, date: 1_615_180_200, dateString: Date(), filtered: nil, noise: nil, glucose: nil),
-        BloodGlucose(sgv: 7, direction: nil, date: 1_615_180_800, dateString: Date(), filtered: nil, noise: nil, glucose: nil),
-        BloodGlucose(sgv: 8, direction: nil, date: 1_615_181_300, dateString: Date(), filtered: nil, noise: nil, glucose: nil)
-    ]
-
-    static var previews: some View {
-        Group {
-            ScrollView(.horizontal) {
-                PointChartView(
-                    minValue: 3,
-                    maxValue: 8,
-                    maxWidth: 500,
-                    showHours: 1,
-                    glucoseData: testingData
-                ) { value in
-                    GlucosePointView(value: value)
-                }
-            }
-            .padding(.vertical)
-
-            .preferredColorScheme(/*@START_MENU_TOKEN@*/ .dark/*@END_MENU_TOKEN@*/)
-        }
-    }
-}

+ 10 - 29
FreeAPS/Sources/Charts/Views/Charts/PredictionsChartView.swift

@@ -4,22 +4,25 @@ public struct PredictionsChartView: View {
     let minValue: Int
     let maxValue: Int
     let maxWidth: CGFloat
-    var data: [PredictionLineData]?
-    let showHours: Int
+    @Binding var data: [PredictionLineData]?
+    @Binding var showHours: Int
 
     public var body: some View {
         ZStack {
-            if let data = data {
-                ForEach(data, id: \.self) { predictionLine in
+            if data != nil {
+                ForEach(0 ..< data!.count, id: \.self) { index in
                     HStack {
                         PointChartView(
                             minValue: minValue,
                             maxValue: maxValue,
                             maxWidth: maxWidth,
-                            showHours: showHours,
-                            glucoseData: predictionLine.values
+                            showHours: $showHours,
+                            glucoseData: $data[index].values
                         ) { value in
-                            PredictionPointView(predictionType: predictionLine.type, value: value)
+                            PredictionPointView(
+                                predictionType: data?[index].type ?? .cob,
+                                value: value
+                            )
                         }
                         Spacer()
                     }
@@ -28,25 +31,3 @@ public struct PredictionsChartView: View {
         }
     }
 }
-
-struct PredictionsChartView_Previews: PreviewProvider {
-    static let data = [
-        PredictionLineData(
-            type: .iob,
-            values: Array(SampleData.sampleData[0 ... 10])
-        ),
-        PredictionLineData(type: .cob, values: Array(SampleData.sampleData[1 ... 21])),
-        PredictionLineData(
-            type: .uam,
-            values: Array(SampleData.sampleData[21 ... 30])
-        ),
-        PredictionLineData(type: .zt, values: Array(SampleData.sampleData[31 ... 40]))
-    ]
-
-    static var previews: some View {
-        ScrollView(.horizontal) {
-            PredictionsChartView(minValue: 30, maxValue: 180, maxWidth: 400, data: data, showHours: 1)
-        }
-        .preferredColorScheme(/*@START_MENU_TOKEN@*/ .dark/*@END_MENU_TOKEN@*/)
-    }
-}