Forráskód Böngészése

glucose works but scaling is off

polscm32 2 éve
szülő
commit
d0c371c919

+ 12 - 4
FreeAPS/Sources/Modules/Home/View/Chart/DataModel.swift

@@ -1,10 +1,18 @@
-//import Foundation
-//
-//let ektasienView: [ViewMonth] = [
+import Foundation
+
+// let ektasienView: [ViewMonth] = [
 //    .init(date: Date.from(year: 2023, month: 1, day: 1), viewCount: 123),
 //    .init(date: Date.from(year: 2023, month: 2, day: 1), viewCount: 100),
 //    .init(date: Date.from(year: 2023, month: 3, day: 1), viewCount: 80),
 //    .init(date: Date.from(year: 2023, month: 4, day: 1), viewCount: 65),
 //    .init(date: Date.from(year: 2023, month: 5, day: 1), viewCount: 120),
 //    .init(date: Date.from(year: 2023, month: 6, day: 1), viewCount: 25)
-//]
+// ]
+
+// struct GlucoseInChart {
+//    let value: Decimal
+//    let id: UUID
+//    let timestamp: Date
+// }
+//
+// @Binding var bloodGlucoseDataModel: [BloodGlucose]

+ 30 - 17
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView2.swift

@@ -69,10 +69,10 @@ struct MainChartView2: View {
     @Binding var displayYgridLines: Bool
     @Binding var thresholdLines: Bool
 
-    // MARK: STATEs
-
-    @State private var glucoseDots: [CGRect] = []
-    @State private var glucoseYRange: Range<CGFloat> = 0 ..< 0
+//    // MARK: STATEs
+//
+//    @State private var glucoseDots: [CGRect] = []
+//    @State private var glucoseYRange: Range<CGFloat> = 0 ..< 0
     @State var didAppearTrigger = false
     @State private var glucoseDots: [CGRect] = []
     @State private var manualGlucoseDots: [CGRect] = []
@@ -95,34 +95,47 @@ struct MainChartView2: View {
     @State private var offset: CGFloat = 0
     @State private var cachedMaxBasalRate: Decimal?
 
+    private var date24Formatter: DateFormatter {
+        let formatter = DateFormatter()
+        formatter.locale = Locale(identifier: "en_US_POSIX")
+        formatter.setLocalizedDateFormatFromTemplate("HH")
+        return formatter
+    }
+
+    private var dateFormatter: DateFormatter {
+        let formatter = DateFormatter()
+        formatter.timeStyle = .short
+        return formatter
+    }
+
     var body: some View {
         NavigationStack {
             ScrollView {
                 VStack {
-                    Chart {
-                        ForEach(glucoseDots.indices, id: \.self) { index in
-                            PointMark(position: glucoseDots[index].origin)
-                                .frame(width: glucoseDots[index].width, height: glucoseDots[index].height)
-                                .foregroundStyle(Color.green.gradient)
-                        }
+                    Chart(glucose) {
+                        PointMark(
+                            x: .value("Time", $0.dateString),
+                            y: .value("Value", $0.value)
+                        )
+                        .foregroundStyle(Color.green.gradient)
+                        .cornerRadius(0)
                     }
+
                     .frame(height: 350)
                     .chartXAxis {
-                        // to do
+                        AxisMarks(values: glucose.map(\.dateString)) { _ in
+                            AxisValueLabel(format: .dateTime.hour())
+                        }
                     }
-
                     Legend()
                 }
                 .padding()
             }
         }
-        .onAppear {
-            calculateGlucoseDots(fullSize: UIScreen.main.bounds.size)
-        }
     }
 
-    // MARK: GLUCOSE FOR CHART
-
+//    // MARK: GLUCOSE FOR CHART
+//
     private func calculateGlucoseDots(fullSize: CGSize) {
         let dots = glucose.map { value -> CGRect in
             let position = glucoseToCoordinate(value, fullSize: fullSize)

+ 24 - 1
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -498,7 +498,30 @@ extension Home {
 
 //                MARK: SWIFT CHARTS
 
-                MainChartView2()
+                MainChartView2(
+                    glucose: $state.glucose,
+                    isManual: $state.isManual,
+                    suggestion: $state.suggestion,
+                    tempBasals: $state.tempBasals,
+                    boluses: $state.boluses,
+                    suspensions: $state.suspensions,
+                    announcement: $state.announcement,
+                    hours: .constant(state.filteredHours),
+                    maxBasal: $state.maxBasal,
+                    autotunedBasalProfile: $state.autotunedBasalProfile,
+                    basalProfile: $state.basalProfile,
+                    tempTargets: $state.tempTargets,
+                    carbs: $state.carbs,
+                    timerDate: $state.timerDate,
+                    units: $state.units,
+                    smooth: $state.smooth,
+                    highGlucose: $state.highGlucose,
+                    lowGlucose: $state.lowGlucose,
+                    screenHours: $state.hours,
+                    displayXgridLines: $state.displayXgridLines,
+                    displayYgridLines: $state.displayYgridLines,
+                    thresholdLines: $state.thresholdLines
+                )
             }
             .padding(.bottom)
             .modal(for: .dataTable, from: self)