polscm32 1 anno fa
parent
commit
8ee49cb5d2

+ 4 - 0
FreeAPS.xcodeproj/project.pbxproj

@@ -264,6 +264,7 @@
 		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 */; };
+		58D08B362C8DFAC600AA37D3 /* IobChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D08B352C8DFAC600AA37D3 /* IobChart.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 */; };
@@ -915,6 +916,7 @@
 		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>"; };
+		58D08B352C8DFAC600AA37D3 /* IobChart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IobChart.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>"; };
@@ -1783,6 +1785,7 @@
 				58D08B2F2C8DEA7500AA37D3 /* ForecastView.swift */,
 				58D08B312C8DF88900AA37D3 /* DummyCharts.swift */,
 				58D08B332C8DF9A700AA37D3 /* CobChart.swift */,
+				58D08B352C8DFAC600AA37D3 /* IobChart.swift */,
 			);
 			path = Chart;
 			sourceTree = "<group>";
@@ -3376,6 +3379,7 @@
 				BDCD47AF2C1F3F1700F8BCD5 /* OverrideStored+helper.swift in Sources */,
 				3811DE3F25C9D4A100A708ED /* SettingsStateModel.swift in Sources */,
 				CE7CA3582A064E2F004BE681 /* ListStateView.swift in Sources */,
+				58D08B362C8DFAC600AA37D3 /* IobChart.swift in Sources */,
 				193F6CDD2A512C8F001240FD /* Loops.swift in Sources */,
 				38B4F3CB25E502E200E76A18 /* WeakObjectSet.swift in Sources */,
 				38E989DD25F5021400C0CED0 /* PumpStatus.swift in Sources */,

+ 39 - 0
FreeAPS/Sources/Modules/Home/View/Chart/IobChart.swift

@@ -0,0 +1,39 @@
+import Charts
+import Foundation
+import SwiftUI
+
+extension MainChartView {
+    var iobChart: some View {
+        VStack {
+            Chart {
+                drawIOB()
+
+                if #available(iOS 17, *) {
+                    if let selectedIOBValue {
+                        PointMark(
+                            x: .value("Time", selectedIOBValue.deliverAt ?? now, unit: .minute),
+                            y: .value("Value", Int(truncating: selectedIOBValue.iob ?? 0))
+                        )
+                        .symbolSize(CGSize(width: 15, height: 15))
+                        .foregroundStyle(Color.darkerBlue.opacity(0.8))
+
+                        PointMark(
+                            x: .value("Time", selectedIOBValue.deliverAt ?? now, unit: .minute),
+                            y: .value("Value", Int(truncating: selectedIOBValue.iob ?? 0))
+                        )
+                        .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: minValueIobChart ... maxValueIobChart)
+            .chartYAxis(.hidden)
+        }
+    }
+}

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

@@ -92,7 +92,7 @@ struct MainChartView: View {
         }
     }
 
-    private var selectedIOBValue: OrefDetermination? {
+    var selectedIOBValue: OrefDetermination? {
         if let selection = selection {
             let lowerBound = selection.addingTimeInterval(-120)
             let upperBound = selection.addingTimeInterval(120)
@@ -359,40 +359,6 @@ extension MainChartView {
             .chartPlotStyle { basalChartPlotStyle($0) }
         }
     }
-
-    private var iobChart: some View {
-        VStack {
-            Chart {
-                drawIOB()
-
-                if #available(iOS 17, *) {
-                    if let selectedIOBValue {
-                        PointMark(
-                            x: .value("Time", selectedIOBValue.deliverAt ?? now, unit: .minute),
-                            y: .value("Value", Int(truncating: selectedIOBValue.iob ?? 0))
-                        )
-                        .symbolSize(CGSize(width: 15, height: 15))
-                        .foregroundStyle(Color.darkerBlue.opacity(0.8))
-
-                        PointMark(
-                            x: .value("Time", selectedIOBValue.deliverAt ?? now, unit: .minute),
-                            y: .value("Value", Int(truncating: selectedIOBValue.iob ?? 0))
-                        )
-                        .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: minValueIobChart ... maxValueIobChart)
-            .chartYAxis(.hidden)
-        }
-    }
 }
 
 // MARK: - Calculations
@@ -472,7 +438,7 @@ extension MainChartView {
         }
     }
 
-    private func drawIOB() -> some ChartContent {
+    func drawIOB() -> some ChartContent {
         ForEach(state.enactedAndNonEnactedDeterminations) { iob in
             let rawAmount = iob.iob?.doubleValue ?? 0
             let amount: Double = rawAmount > 0 ? rawAmount : rawAmount * 2 // weigh negative iob with factor 2