Просмотр исходного кода

Set default range if min and max range for cone is 0

Deniz Cengiz 1 год назад
Родитель
Сommit
6efd07f0df

+ 34 - 11
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

@@ -670,19 +670,42 @@ extension MainChartView {
         // Draw AreaMark for the forecast bounds
         ForEach(0 ..< max(state.minForecast.count, state.maxForecast.count), id: \.self) { index in
             if index < state.minForecast.count, index < state.maxForecast.count {
-                let yMinValue = units == .mgdL ? Decimal(state.minForecast[index]) : Decimal(state.minForecast[index]).asMmolL
-                let yMaxValue = units == .mgdL ? Decimal(state.maxForecast[index]) : Decimal(state.maxForecast[index]).asMmolL
+                let yMinMaxDelta = Decimal(state.minForecast[index] - state.maxForecast[index])
                 let xValue = timeForIndex(Int32(index))
 
-                if xValue <= Date(timeIntervalSinceNow: TimeInterval(hours: 2.5)) {
-                    AreaMark(
-                        x: .value("Time", xValue),
-                        // maxValue is already parsed to user units, no need to parse
-                        yStart: .value("Min Value", yMinValue <= maxValue ? yMinValue : maxValue),
-                        yEnd: .value("Max Value", yMaxValue <= maxValue ? yMaxValue : maxValue)
-                    )
-                    .foregroundStyle(Color.blue.opacity(0.5))
-                    .interpolationMethod(.catmullRom)
+                // if distance between respective min and max is 0, provide a default range
+                if yMinMaxDelta == 0 {
+                    let yMinValue = units == .mgdL ? Decimal(state.minForecast[index] - 1) :
+                        Decimal(state.minForecast[index] - 1)
+                        .asMmolL
+                    let yMaxValue = units == .mgdL ? Decimal(state.minForecast[index] + 1) :
+                        Decimal(state.minForecast[index] + 1)
+                        .asMmolL
+
+                    if xValue <= Date(timeIntervalSinceNow: TimeInterval(hours: 2.5)) {
+                        AreaMark(
+                            x: .value("Time", xValue),
+                            // maxValue is already parsed to user units, no need to parse
+                            yStart: .value("Min Value", yMinValue <= maxValue ? yMinValue : maxValue),
+                            yEnd: .value("Max Value", yMaxValue <= maxValue ? yMaxValue : maxValue)
+                        )
+                        .foregroundStyle(Color.blue.opacity(0.5))
+                        .interpolationMethod(.catmullRom)
+                    }
+                } else {
+                    let yMinValue = units == .mgdL ? Decimal(state.minForecast[index]) : Decimal(state.minForecast[index]).asMmolL
+                    let yMaxValue = units == .mgdL ? Decimal(state.maxForecast[index]) : Decimal(state.maxForecast[index]).asMmolL
+
+                    if xValue <= Date(timeIntervalSinceNow: TimeInterval(hours: 2.5)) {
+                        AreaMark(
+                            x: .value("Time", xValue),
+                            // maxValue is already parsed to user units, no need to parse
+                            yStart: .value("Min Value", yMinValue <= maxValue ? yMinValue : maxValue),
+                            yEnd: .value("Max Value", yMaxValue <= maxValue ? yMaxValue : maxValue)
+                        )
+                        .foregroundStyle(Color.blue.opacity(0.5))
+                        .interpolationMethod(.catmullRom)
+                    }
                 }
             }
         }

+ 6 - 2
FreeAPS/Sources/Modules/Home/View/Header/CurrentGlucoseView.swift

@@ -90,7 +90,7 @@ struct CurrentGlucoseView: View {
                                 glucoseValue == 400 ? "HIGH" : displayGlucose
                             )
                             .font(.system(size: 40, weight: .bold, design: .rounded))
-                            .foregroundColor(alarm == nil ? colourGlucoseText : .loopRed)
+                            .foregroundColor(alarm == nil ? glucoseDisplayColor : .loopRed)
                         } else {
                             Text("--")
                                 .font(.system(size: 40, weight: .bold, design: .rounded))
@@ -167,13 +167,17 @@ struct CurrentGlucoseView: View {
         return deltaFormatter.string(from: deltaAsDecimal as NSNumber) ?? "--"
     }
 
-    var colourGlucoseText: Color {
+    var glucoseDisplayColor: Color {
         // Fetch the first glucose reading and convert it to Int for comparison
         let whichGlucose = Int(combinedGlucoseValues.first?.glucose ?? 0)
 
         // Define default color based on the color scheme
         let defaultColor: Color = colorScheme == .dark ? .white : .black
 
+        // low and high glucose is parsed in state to mmol/L; parse it back to mg/dl here for comparison
+        let lowGlucose = units == .mgdL ? lowGlucose : lowGlucose.asMgdL
+        let highGlucose = units == .mgdL ? highGlucose : highGlucose.asMgdL
+
         // Ensure the thresholds are logical
         guard lowGlucose < highGlucose else { return .primary }
 

+ 1 - 1
Trio.xcworkspace/xcshareddata/swiftpm/Package.resolved

@@ -1,5 +1,5 @@
 {
-  "originHash" : "59ac7eba66375d6eb406e758cb0b9964f4b3b0ae45c5665596f00384c32262b9",
+  "originHash" : "f5c836c216c4ca7d356e3777e58d6d4f9502b03f3974891349eb775f4c4cf750",
   "pins" : [
     {
       "identity" : "cryptoswift",