Browse Source

UI fixes
* fix size of tap bar items
* explicitly define y axis label of main chart
* only run determine function for y axis labels every 60 min

polscm32 2 years ago
parent
commit
b15688e646

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

@@ -91,6 +91,9 @@ struct MainChartView: View {
     @State private var count: Decimal = 1
     @State private var count: Decimal = 1
     @State private var startMarker = Date(timeIntervalSince1970: TimeInterval(NSDate().timeIntervalSince1970 - 86400))
     @State private var startMarker = Date(timeIntervalSince1970: TimeInterval(NSDate().timeIntervalSince1970 - 86400))
     @State private var endMarker = Date(timeIntervalSince1970: TimeInterval(NSDate().timeIntervalSince1970 + 10800))
     @State private var endMarker = Date(timeIntervalSince1970: TimeInterval(NSDate().timeIntervalSince1970 + 10800))
+    @State private var glucoseUpdateCount = 0
+    @State private var maxUpdateCount = 12
+    @State private var maxYLabel: Int = 400
 
 
     private var bolusFormatter: NumberFormatter {
     private var bolusFormatter: NumberFormatter {
         let formatter = NumberFormatter()
         let formatter = NumberFormatter()
@@ -283,6 +286,7 @@ extension MainChartView {
                 .onChange(of: glucose) {
                 .onChange(of: glucose) {
                     calculatePredictions()
                     calculatePredictions()
                     calculateFpus()
                     calculateFpus()
+                    counter()
                 }
                 }
                 .onChange(of: carbs) {
                 .onChange(of: carbs) {
                     calculateCarbs()
                     calculateCarbs()
@@ -310,6 +314,7 @@ extension MainChartView {
                     width: max(0, screenSize.width - 20, fullWidth(viewWidth: screenSize.width)),
                     width: max(0, screenSize.width - 20, fullWidth(viewWidth: screenSize.width)),
                     height: UIScreen.main.bounds.height / 2.9
                     height: UIScreen.main.bounds.height / 2.9
                 )
                 )
+                .chartYScale(domain: 0 ... maxYLabel)
                 .chartXScale(domain: startMarker ... endMarker)
                 .chartXScale(domain: startMarker ... endMarker)
                 .chartXAxis {
                 .chartXAxis {
                     AxisMarks(values: .stride(by: .hour, count: screenHours == 24 ? 4 : 2)) { _ in
                     AxisMarks(values: .stride(by: .hour, count: screenHours == 24 ? 4 : 2)) { _ in
@@ -754,6 +759,30 @@ extension MainChartView {
         startMarker = Date(timeIntervalSince1970: TimeInterval(NSDate().timeIntervalSince1970 - 86400))
         startMarker = Date(timeIntervalSince1970: TimeInterval(NSDate().timeIntervalSince1970 - 86400))
         endMarker = Date(timeIntervalSince1970: TimeInterval(NSDate().timeIntervalSince1970 + 10800))
         endMarker = Date(timeIntervalSince1970: TimeInterval(NSDate().timeIntervalSince1970 + 10800))
     }
     }
+    
+    /// get y axis scale
+    /// but only call the function every 60min, i.e. every 12th glucose value
+    private func counter() {
+        glucoseUpdateCount += 1
+        if glucoseUpdateCount >= maxUpdateCount {
+            /// filter glucose entries within the last 24 hours
+            let last24Hours = glucose.suffix(288)
+
+            /// find the maximum glucose value
+            if let maxGlucose = last24Hours.max(by: { $0.unfiltered ?? 0 < $1.unfiltered ?? 0 }) {
+                /// round to next 50er
+                maxYLabel = Int(50 * round(Double(maxGlucose.unfiltered ?? 0) / 50))
+                print("dein wert issssssssssss")
+                print(maxYLabel)
+
+            } else {
+                /// return a default rounded value if no entries are found
+                maxYLabel = 400
+            }
+
+            glucoseUpdateCount = 0
+        }
+    }
 
 
     private func calculateBasals() {
     private func calculateBasals() {
         let dayAgoTime = Date().addingTimeInterval(-1.days.timeInterval).timeIntervalSince1970
         let dayAgoTime = Date().addingTimeInterval(-1.days.timeInterval).timeIntervalSince1970

+ 10 - 18
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -531,9 +531,7 @@ extension Home {
                     label: {
                     label: {
                         ZStack(alignment: Alignment(horizontal: .trailing, vertical: .bottom)) {
                         ZStack(alignment: Alignment(horizontal: .trailing, vertical: .bottom)) {
                             Image(systemName: "fork.knife")
                             Image(systemName: "fork.knife")
-                                .renderingMode(.template)
-                                .resizable()
-                                .frame(width: 24, height: 24)
+                                .font(.system(size: 24))
                                 .foregroundColor(colorIcon)
                                 .foregroundColor(colorIcon)
                                 .padding(8)
                                 .padding(8)
                             if let carbsReq = state.carbsRequired {
                             if let carbsReq = state.carbsRequired {
@@ -549,9 +547,7 @@ extension Home {
                     Button { state.showModal(for: .addTempTarget) }
                     Button { state.showModal(for: .addTempTarget) }
                     label: {
                     label: {
                         Image(systemName: "target")
                         Image(systemName: "target")
-                            .renderingMode(.template)
-                            .resizable()
-                            .frame(width: 24, height: 24)
+                            .font(.system(size: 24))
                             .padding(8)
                             .padding(8)
                     }
                     }
                     .foregroundColor(state.isTempTargetActive ? Color.purple : colorIcon)
                     .foregroundColor(state.isTempTargetActive ? Color.purple : colorIcon)
@@ -565,9 +561,8 @@ extension Home {
                     }
                     }
                     label: {
                     label: {
                         Image(systemName: "syringe")
                         Image(systemName: "syringe")
-                            .renderingMode(.template)
-                            .resizable()
-                            .frame(width: 24, height: 24)
+                            .font(.system(size: 24))
+                            .foregroundColor(colorIcon)
                             .padding(8)
                             .padding(8)
                     }
                     }
                     .foregroundColor(colorIcon)
                     .foregroundColor(colorIcon)
@@ -594,9 +589,8 @@ extension Home {
                         state.showModal(for: .overrideProfilesConfig)
                         state.showModal(for: .overrideProfilesConfig)
                     } label: {
                     } label: {
                         Image(systemName: "person")
                         Image(systemName: "person")
-                            .renderingMode(.template)
-                            .resizable()
-                            .frame(width: 24, height: 24)
+                            .font(.system(size: 24))
+                            .foregroundColor(colorIcon)
                             .padding(8)
                             .padding(8)
                     }
                     }
                     .foregroundColor(colorIcon)
                     .foregroundColor(colorIcon)
@@ -606,9 +600,8 @@ extension Home {
                     }
                     }
                     label: {
                     label: {
                         Image(systemName: "chart.bar")
                         Image(systemName: "chart.bar")
-                            .renderingMode(.template)
-                            .resizable()
-                            .frame(width: 24, height: 24)
+                            .font(.system(size: 24))
+                            .foregroundColor(colorIcon)
                             .padding(8)
                             .padding(8)
                     }
                     }
                     .foregroundColor(colorIcon)
                     .foregroundColor(colorIcon)
@@ -617,9 +610,8 @@ extension Home {
                     Button { state.showModal(for: .settings) }
                     Button { state.showModal(for: .settings) }
                     label: {
                     label: {
                         Image(systemName: "gear")
                         Image(systemName: "gear")
-                            .renderingMode(.template)
-                            .resizable()
-                            .frame(width: 24, height: 24)
+                            .font(.system(size: 24))
+                            .foregroundColor(colorIcon)
                             .padding(8)
                             .padding(8)
                     }
                     }
                     .foregroundColor(colorIcon)
                     .foregroundColor(colorIcon)