polscm32 hace 1 año
padre
commit
1a59f22e8c

+ 4 - 0
FreeAPS.xcodeproj/project.pbxproj

@@ -263,6 +263,7 @@
 		58D08B222C8DAA8E00AA37D3 /* OverrideView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D08B212C8DAA8E00AA37D3 /* OverrideView.swift */; };
 		58D08B302C8DEA7500AA37D3 /* ForecastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D08B2F2C8DEA7500AA37D3 /* ForecastView.swift */; };
 		58D08B322C8DF88900AA37D3 /* DummyCharts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D08B312C8DF88900AA37D3 /* DummyCharts.swift */; };
+		58D08B342C8DF9A700AA37D3 /* CobChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D08B332C8DF9A700AA37D3 /* CobChart.swift */; };
 		58F107742BD1A4D000B1A680 /* Determination+helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58F107732BD1A4D000B1A680 /* Determination+helper.swift */; };
 		5A2325522BFCBF55003518CA /* NightscoutUploadView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A2325512BFCBF55003518CA /* NightscoutUploadView.swift */; };
 		5A2325542BFCBF66003518CA /* NightscoutFetchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A2325532BFCBF65003518CA /* NightscoutFetchView.swift */; };
@@ -913,6 +914,7 @@
 		58D08B212C8DAA8E00AA37D3 /* OverrideView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverrideView.swift; sourceTree = "<group>"; };
 		58D08B2F2C8DEA7500AA37D3 /* ForecastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastView.swift; sourceTree = "<group>"; };
 		58D08B312C8DF88900AA37D3 /* DummyCharts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DummyCharts.swift; sourceTree = "<group>"; };
+		58D08B332C8DF9A700AA37D3 /* CobChart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CobChart.swift; sourceTree = "<group>"; };
 		58F107732BD1A4D000B1A680 /* Determination+helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Determination+helper.swift"; sourceTree = "<group>"; };
 		5A2325512BFCBF55003518CA /* NightscoutUploadView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NightscoutUploadView.swift; sourceTree = "<group>"; };
 		5A2325532BFCBF65003518CA /* NightscoutFetchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NightscoutFetchView.swift; sourceTree = "<group>"; };
@@ -1780,6 +1782,7 @@
 				58D08B212C8DAA8E00AA37D3 /* OverrideView.swift */,
 				58D08B2F2C8DEA7500AA37D3 /* ForecastView.swift */,
 				58D08B312C8DF88900AA37D3 /* DummyCharts.swift */,
+				58D08B332C8DF9A700AA37D3 /* CobChart.swift */,
 			);
 			path = Chart;
 			sourceTree = "<group>";
@@ -3411,6 +3414,7 @@
 				38A43598262E0E4900E80935 /* FetchAnnouncementsManager.swift in Sources */,
 				DD1745442C55C60E00211FAC /* AutosensSettingsDataFlow.swift in Sources */,
 				BDCAF2382C639F35002DC907 /* SettingItems.swift in Sources */,
+				58D08B342C8DF9A700AA37D3 /* CobChart.swift in Sources */,
 				642F76A05A4FF530463A9FD0 /* NightscoutConfigRootView.swift in Sources */,
 				BD7DA9AC2AE06EB900601B20 /* BolusCalculatorConfigRootView.swift in Sources */,
 				AD3D2CD42CD01B9EB8F26522 /* PumpConfigDataFlow.swift in Sources */,

+ 37 - 0
FreeAPS/Sources/Modules/Home/View/Chart/CobChart.swift

@@ -0,0 +1,37 @@
+import Charts
+import Foundation
+import SwiftUI
+
+extension MainChartView {
+    var cobChart: some View {
+        Chart {
+            drawCurrentTimeMarker()
+            drawCOB(dummy: false)
+
+            if #available(iOS 17, *) {
+                if let selectedCOBValue {
+                    PointMark(
+                        x: .value("Time", selectedCOBValue.deliverAt ?? now, unit: .minute),
+                        y: .value("Value", selectedCOBValue.cob)
+                    )
+                    .symbolSize(CGSize(width: 15, height: 15))
+                    .foregroundStyle(Color.orange.opacity(0.8))
+
+                    PointMark(
+                        x: .value("Time", selectedCOBValue.deliverAt ?? now, unit: .minute),
+                        y: .value("Value", selectedCOBValue.cob)
+                    )
+                    .symbolSize(CGSize(width: 6, height: 6))
+                    .foregroundStyle(Color.primary)
+                }
+            }
+        }
+        .frame(minHeight: geo.size.height * 0.12)
+        .frame(width: fullWidth(viewWidth: screenSize.width))
+        .chartXScale(domain: startMarker ... endMarker)
+        .backport.chartXSelection(value: $selection)
+        .chartXAxis { basalChartXAxis }
+        .chartYAxis { cobChartYAxis }
+        .chartYScale(domain: minValueCobChart ... maxValueCobChart)
+    }
+}

+ 4 - 36
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

@@ -59,7 +59,7 @@ struct MainChartView: View {
     @State var maxValueIobChart: Decimal = 5
     @State var mainChartHasInitialized = false
 
-    private let now = Date.now
+    let now = Date.now
 
     private let context = CoreDataStack.shared.persistentContainer.viewContext
 
@@ -80,7 +80,7 @@ struct MainChartView: View {
         }
     }
 
-    private var selectedCOBValue: OrefDetermination? {
+    var selectedCOBValue: OrefDetermination? {
         if let selection = selection {
             let lowerBound = selection.addingTimeInterval(-120)
             let upperBound = selection.addingTimeInterval(120)
@@ -393,44 +393,12 @@ extension MainChartView {
             .chartYAxis(.hidden)
         }
     }
-
-    private var cobChart: some View {
-        Chart {
-            drawCurrentTimeMarker()
-            drawCOB(dummy: false)
-
-            if #available(iOS 17, *) {
-                if let selectedCOBValue {
-                    PointMark(
-                        x: .value("Time", selectedCOBValue.deliverAt ?? now, unit: .minute),
-                        y: .value("Value", selectedCOBValue.cob)
-                    )
-                    .symbolSize(CGSize(width: 15, height: 15))
-                    .foregroundStyle(Color.orange.opacity(0.8))
-
-                    PointMark(
-                        x: .value("Time", selectedCOBValue.deliverAt ?? now, unit: .minute),
-                        y: .value("Value", selectedCOBValue.cob)
-                    )
-                    .symbolSize(CGSize(width: 6, height: 6))
-                    .foregroundStyle(Color.primary)
-                }
-            }
-        }
-        .frame(minHeight: geo.size.height * 0.12)
-        .frame(width: fullWidth(viewWidth: screenSize.width))
-        .chartXScale(domain: startMarker ... endMarker)
-        .backport.chartXSelection(value: $selection)
-        .chartXAxis { basalChartXAxis }
-        .chartYAxis { cobChartYAxis }
-        .chartYScale(domain: minValueCobChart ... maxValueCobChart)
-    }
 }
 
 // MARK: - Calculations
 
 extension MainChartView {
-    private func drawCurrentTimeMarker() -> some ChartContent {
+    func drawCurrentTimeMarker() -> some ChartContent {
         RuleMark(
             x: .value(
                 "",
@@ -637,7 +605,7 @@ extension MainChartView {
         }
     }
 
-    private func fullWidth(viewWidth: CGFloat) -> CGFloat {
+    func fullWidth(viewWidth: CGFloat) -> CGFloat {
         viewWidth * CGFloat(hours) / CGFloat(min(max(screenHours, 2), 24))
     }