|
@@ -396,26 +396,25 @@ struct GlucoseDailyPercentileChart: View {
|
|
|
|
|
|
|
|
// Calculate an appropriate Y axis domain for the chart
|
|
// Calculate an appropriate Y axis domain for the chart
|
|
|
private func glucoseYScaleDomain() -> ClosedRange<Double> {
|
|
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 {
|
|
if visibleDailyStats.isEmpty {
|
|
|
- return 0 ... (units == .mgdL ? 250 : 14.0)
|
|
|
|
|
|
|
+ return bottomLimit ... topLimit
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var allValues: [Double] = []
|
|
var allValues: [Double] = []
|
|
|
for day in visibleDailyStats where day.minimum > 0 {
|
|
for day in visibleDailyStats where day.minimum > 0 {
|
|
|
- allValues.append(day.minimum.asUnit(units))
|
|
|
|
|
allValues.append(day.maximum.asUnit(units))
|
|
allValues.append(day.maximum.asUnit(units))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
guard !allValues.isEmpty else {
|
|
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)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|