Selaa lähdekoodia

Allow lower than 6 hours for X-axis in main chart, Home View.
Make low /high lines configurable.

Jon Mårtensson 3 vuotta sitten
vanhempi
commit
5f61f8344b

+ 39 - 33
FreeAPS/Resources/json/defaults/freeaps/freeaps_settings.json

@@ -1,35 +1,41 @@
 {
-    "units": "mmol/L",
-    "closedLoop": false,
-    "allowAnnouncements": false,
-    "useAutotune": false,
-    "isUploadEnabled": false,
-    "useLocalGlucoseSource": false,
-    "localGlucosePort": 8080,
-    "debugOptions": false,
-    "insulinReqPercentage": 70,
-    "skipBolusScreenAfterCarbs": false,
-    "displayHR": false,
-    "cgm": "nightscout",
-    "uploadGlucose": false,
-    "glucoseBadge": false,
-    "glucoseNotificationsAlways": false,
-    "useAlarmSound": false,
-    "addSourceInfoToGlucoseNotifications": false,
-    "lowGlucose": 72,
-    "highGlucose": 145,
-    "carbsRequiredThreshold": 10,
-    "useAppleHealth": false,
-    "animatedBackground": false,
-    "uploadStats": false,
-    "useFPUconversion": true
-    "individualAdjustmentFactor": 0.5,
-    "timeCap": 8,
-    "minuteInterval": 30,
-    "delay": 60,
-    "displayOnWatch": "BGTarget",
-    "hours": 6,
-    "xGridLines": false,
-    "yGridLines": true,
-    "oneDimensionalGraph": false
+    "useAlarmSound" : false,
+      "uploadStats" : false,
+      "useCalendar" : false,
+      "rulerMarks" : false,
+      "individualAdjustmentFactor" : 0.5,
+      "low" : 70,
+      "displayHR" : true,
+      "localGlucosePort" : 8080,
+      "uploadGlucose" : true,
+      "allowAnnouncements" : false,
+      "debugOptions" : false,
+      "useAppleHealth" : false,
+      "high" : 170,
+      "yGridLines" : true,
+      "useLocalGlucoseSource" : false,
+      "closedLoop" : false,
+      "units" : "mmol/L",
+      "xGridLines" : true,
+      "lowGlucose" : 70,
+      "oneDimensionalGraph" : false,
+      "glucoseNotificationsAlways" : false,
+      "addSourceInfoToGlucoseNotifications" : false,
+      "cgm" : "nightscout",
+      "glucoseBadge" : true,
+      "overrideHbA1cUnit" : false,
+      "delay" : 80,
+      "smoothGlucose" : false,
+      "skipBolusScreenAfterCarbs" : false,
+      "highGlucose" : 220,
+      "timeCap" : 8,
+      "minuteInterval" : 20,
+      "isUploadEnabled" : true,
+      "useAutotune" : false,
+      "hours" : 6,
+      "carbsRequiredThreshold" : 50,
+      "insulinReqPercentage" : 80,
+      "useFPUconversion" : false,
+      "displayOnWatch" : "HR",
+      "animatedBackground" : false
 }

+ 5 - 0
FreeAPS/Sources/Models/FreeAPSSettings.swift

@@ -39,6 +39,7 @@ struct FreeAPSSettings: JSON, Equatable {
     var xGridLines: Bool = true
     var yGridLines: Bool = true
     var oneDimensionalGraph: Bool = false
+    var rulerMarks: Bool = false
 }
 
 extension FreeAPSSettings: Decodable {
@@ -200,6 +201,10 @@ extension FreeAPSSettings: Decodable {
             settings.oneDimensionalGraph = oneDimensionalGraph
         }
 
+        if let rulerMarks = try? container.decode(Bool.self, forKey: .rulerMarks) {
+            settings.rulerMarks = rulerMarks
+        }
+
         self = settings
     }
 }

+ 3 - 0
FreeAPS/Sources/Modules/Home/HomeStateModel.swift

@@ -57,6 +57,7 @@ extension Home {
         @Published var screenHours: Int = 6
         @Published var displayXgridLines: Bool = false
         @Published var displayYgridLines: Bool = false
+        @Published var thresholdLines: Bool = false
 
         override func subscribe() {
             setupGlucose()
@@ -90,6 +91,7 @@ extension Home {
             screenHours = settingsManager.settings.hours
             displayXgridLines = settingsManager.settings.xGridLines
             displayYgridLines = settingsManager.settings.yGridLines
+            thresholdLines = settingsManager.settings.rulerMarks
 
             broadcaster.register(GlucoseObserver.self, observer: self)
             broadcaster.register(SuggestionObserver.self, observer: self)
@@ -398,6 +400,7 @@ extension Home.StateModel:
         screenHours = settingsManager.settings.hours
         displayXgridLines = settingsManager.settings.xGridLines
         displayYgridLines = settingsManager.settings.yGridLines
+        thresholdLines = settingsManager.settings.rulerMarks
 
         setupGlucose()
     }

+ 29 - 23
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

@@ -52,6 +52,7 @@ struct MainChartView: View {
     @Binding var screenHours: Int
     @Binding var displayXgridLines: Bool
     @Binding var displayYgridLines: Bool
+    @Binding var thresholdLines: Bool
 
     @State var didAppearTrigger = false
     @State private var glucoseDots: [CGRect] = []
@@ -136,6 +137,10 @@ struct MainChartView: View {
             .onChange(of: vSizeClass) { _ in
                 update(fullSize: geo.size)
             }
+            .onChange(of: screenHours) { _ in
+                update(fullSize: geo.size)
+                // scroll.scrollTo(Config.endID, anchor: .trailing)
+            }
             .onReceive(
                 Foundation.NotificationCenter.default
                     .publisher(for: UIDevice.orientationDidChangeNotification)
@@ -188,23 +193,25 @@ struct MainChartView: View {
             }.stroke(useColour, lineWidth: 0.15)
 
             // horizontal limits
-            let range = glucoseYRange
-            let topstep = (range.maxY - range.minY) / CGFloat(range.maxValue - range.minValue) *
-                (CGFloat(range.maxValue) - CGFloat(highGlucose))
-            if CGFloat(range.maxValue) > CGFloat(highGlucose) {
-                Path { path in
-                    path.move(to: CGPoint(x: 0, y: range.minY + topstep))
-                    path.addLine(to: CGPoint(x: fullSize.width, y: range.minY + topstep))
-                }.stroke(Color.loopYellow, lineWidth: 0.5) // .StrokeStyle(lineWidth: 0.5, dash: [5])
-            }
-            let yrange = glucoseYRange
-            let bottomstep = (yrange.maxY - yrange.minY) / CGFloat(yrange.maxValue - yrange.minValue) *
-                (CGFloat(yrange.maxValue) - CGFloat(lowGlucose))
-            if CGFloat(yrange.minValue) < CGFloat(lowGlucose) {
-                Path { path in
-                    path.move(to: CGPoint(x: 0, y: yrange.minY + bottomstep))
-                    path.addLine(to: CGPoint(x: fullSize.width, y: yrange.minY + bottomstep))
-                }.stroke(Color.loopRed, lineWidth: 0.5)
+            if thresholdLines {
+                let range = glucoseYRange
+                let topstep = (range.maxY - range.minY) / CGFloat(range.maxValue - range.minValue) *
+                    (CGFloat(range.maxValue) - CGFloat(highGlucose))
+                if CGFloat(range.maxValue) > CGFloat(highGlucose) {
+                    Path { path in
+                        path.move(to: CGPoint(x: 0, y: range.minY + topstep))
+                        path.addLine(to: CGPoint(x: fullSize.width, y: range.minY + topstep))
+                    }.stroke(Color.loopYellow, lineWidth: 0.5) // .StrokeStyle(lineWidth: 0.5, dash: [5])
+                }
+                let yrange = glucoseYRange
+                let bottomstep = (yrange.maxY - yrange.minY) / CGFloat(yrange.maxValue - yrange.minValue) *
+                    (CGFloat(yrange.maxValue) - CGFloat(lowGlucose))
+                if CGFloat(yrange.minValue) < CGFloat(lowGlucose) {
+                    Path { path in
+                        path.move(to: CGPoint(x: 0, y: yrange.minY + bottomstep))
+                        path.addLine(to: CGPoint(x: fullSize.width, y: yrange.minY + bottomstep))
+                    }.stroke(Color.loopRed, lineWidth: 0.5)
+                }
             }
         }
     }
@@ -287,8 +294,6 @@ struct MainChartView: View {
             }
             .stroke(useColour, lineWidth: 0.15)
 
-            // .stroke(Color.secondary, lineWidth: 0.2)
-
             Path { path in // vertical timeline
                 let x = timeToXCoordinate(timerDate.timeIntervalSince1970, fullSize: fullSize)
                 path.move(to: CGPoint(x: x, y: 0))
@@ -663,7 +668,8 @@ extension MainChartView {
                 path.addLine(to: CGPoint(x: 0, y: Config.basalHeight))
             }
 
-            let endDateTime = dayAgoTime + 1.days.timeInterval + 6.hours.timeInterval
+            let endDateTime = dayAgoTime + min(max(screenHours, 2), 24).hours.timeInterval + min(max(screenHours, 2), 24).hours
+                .timeInterval
             let autotunedBasalPoints = findRegularBasalPoints(
                 timeBegin: dayAgoTime,
                 timeEnd: endDateTime,
@@ -869,7 +875,7 @@ extension MainChartView {
     }
 
     private func fullGlucoseWidth(viewWidth: CGFloat) -> CGFloat {
-        viewWidth * CGFloat(hours) / CGFloat(min(max(screenHours, 6), 24))
+        viewWidth * CGFloat(hours) / CGFloat(min(max(screenHours, 2), 24))
     }
 
     private func additionalWidth(viewWidth: CGFloat) -> CGFloat {
@@ -890,11 +896,11 @@ extension MainChartView {
         let additionalTime = CGFloat(TimeInterval(max) * 5.minutes.timeInterval - lastDeltaTime)
         let oneSecondWidth = oneSecondStep(viewWidth: viewWidth)
 
-        return Swift.max(additionalTime * oneSecondWidth, Config.minAdditionalWidth)
+        return Swift.min(Swift.max(additionalTime * oneSecondWidth, Config.minAdditionalWidth), 275)
     }
 
     private func oneSecondStep(viewWidth: CGFloat) -> CGFloat {
-        viewWidth / (CGFloat(max(screenHours, 6)) * CGFloat(1.hours.timeInterval))
+        viewWidth / (CGFloat(min(max(screenHours, 2), 24)) * CGFloat(1.hours.timeInterval))
     }
 
     private func maxPredValue() -> Int? {

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

@@ -338,7 +338,8 @@ extension Home {
                     lowGlucose: $state.lowGlucose,
                     screenHours: $state.screenHours,
                     displayXgridLines: $state.displayXgridLines,
-                    displayYgridLines: $state.displayYgridLines
+                    displayYgridLines: $state.displayYgridLines,
+                    thresholdLines: $state.thresholdLines
                 )
             }
             .padding(.bottom)

+ 3 - 1
FreeAPS/Sources/Modules/StatConfig/StatConfigStateModel.swift

@@ -10,6 +10,7 @@ extension StatConfig {
         @Published var xGridLines = false
         @Published var yGridLines: Bool = false
         @Published var oneDimensionalGraph = false
+        @Published var rulerMarks: Bool = false
 
         var units: GlucoseUnits = .mmolL
 
@@ -21,6 +22,7 @@ extension StatConfig {
             subscribeSetting(\.uploadStats, on: $uploadStats) { uploadStats = $0 }
             subscribeSetting(\.xGridLines, on: $xGridLines) { xGridLines = $0 }
             subscribeSetting(\.yGridLines, on: $yGridLines) { yGridLines = $0 }
+            subscribeSetting(\.rulerMarks, on: $rulerMarks) { rulerMarks = $0 }
             subscribeSetting(\.oneDimensionalGraph, on: $oneDimensionalGraph) { oneDimensionalGraph = $0 }
 
             subscribeSetting(\.low, on: $low, initial: {
@@ -40,7 +42,7 @@ extension StatConfig {
             })
 
             subscribeSetting(\.hours, on: $hours.map(Int.init), initial: {
-                let value = max(min($0, 24), 6)
+                let value = max(min($0, 24), 2)
                 hours = Decimal(value)
             }, map: {
                 $0

+ 4 - 3
FreeAPS/Sources/Modules/StatConfig/View/StatConfigRootView.swift

@@ -29,12 +29,13 @@ extension StatConfig {
                 Section(header: Text("Settings")) {
                     Toggle("Change HbA1c Unit", isOn: $state.overrideHbA1cUnit)
                     Toggle("Allow Upload of Statistics to NS", isOn: $state.uploadStats)
-                    Toggle("Display X - Grid lines", isOn: $state.xGridLines)
-                    Toggle("Display Y - Grid lines", isOn: $state.yGridLines)
+                    Toggle("Display Chart X - Grid lines", isOn: $state.xGridLines)
+                    Toggle("Display Chart Y - Grid lines", isOn: $state.yGridLines)
+                    Toggle("Display Chart Threshold lines for Low and High)", isOn: $state.rulerMarks)
                     Toggle("Standing / Laying TIR Chart", isOn: $state.oneDimensionalGraph)
 
                     HStack {
-                        Text("Hours (X-Axis)")
+                        Text("Hours X-Axis (6 default)")
                         Spacer()
                         DecimalTextField("6", value: $state.hours, formatter: carbsFormatter)
                         Text("hours").foregroundColor(.secondary)