فهرست منبع

Merge pull request #891 from MikePlante1/stats-scale

Adjust Y-scale for Percentile Charts
Deniz Cengiz 5 ماه پیش
والد
کامیت
854b016baa

+ 8 - 9
Trio/Sources/Modules/Stat/View/ViewElements/Glucose/GlucoseDailyPercentileChart.swift

@@ -396,26 +396,25 @@ struct GlucoseDailyPercentileChart: View {
 
     // Calculate an appropriate Y axis domain for the chart
     private func glucoseYScaleDomain() -> ClosedRange<Double> {
-        // Find actual min/max from data
+        let padding = units == .mgdL ? 20.0 : 1.0
+        let bottomLimit = 40.0.asUnit(units)
+        let topLimit = 400.0.asUnit(units)
+
         if visibleDailyStats.isEmpty {
-            return 0 ... (units == .mgdL ? 250 : 14.0)
+            return bottomLimit ... topLimit
         }
 
         var allValues: [Double] = []
         for day in visibleDailyStats where day.minimum > 0 {
-            allValues.append(day.minimum.asUnit(units))
             allValues.append(day.maximum.asUnit(units))
         }
 
         guard !allValues.isEmpty else {
-            return 0 ... (units == .mgdL ? 250 : 14.0)
+            return bottomLimit ... topLimit
         }
 
-        let minValue = allValues.min() ?? 0
-        let maxValue = allValues.max() ?? (units == .mgdL ? 250 : 14.0)
+        let maxValue = allValues.max() ?? topLimit
 
-        // Add some padding
-        let padding = units == .mgdL ? 20.0 : 1.0
-        return max(0, minValue - padding) ... maxValue + padding
+        return bottomLimit ... max(Double(highLimit.asUnit(units)), maxValue + padding)
     }
 }

+ 1 - 1
Trio/Sources/Modules/Stat/View/ViewElements/Glucose/GlucosePercentileChart.swift

@@ -47,7 +47,7 @@ struct GlucosePercentileChart: View {
         let validStats = hourlyStats.filter { $0.median > 0 }
         guard !validStats.isEmpty else { return topLimit }
         let maxPercentile90 = validStats.map(\.percentile90).max() ?? topLimit
-        return maxPercentile90.asUnit(units)
+        return max(maxPercentile90.asUnit(units), Double(highLimit.asUnit(units)))
     }
 
     var body: some View {