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

Align high's static and dynamic colors; Apply DRY

Mike Plante 4 дней назад
Родитель
Сommit
311a09ad71

+ 9 - 4
LiveActivity/LiveActivity+Helper.swift

@@ -70,6 +70,11 @@ extension NumberFormatter {
 }
 
 extension Color {
+    // Static Glucose Color Scheme band colors — needs to be kept in sync with DynamicGlucoseColor.swift
+    static let staticLow = Color(hue: 0.0 / 360.0, saturation: 0.6, brightness: 0.9)
+    static let staticInRange = Color(hue: 120.0 / 360.0, saturation: 0.6, brightness: 0.9)
+    static let staticHigh = Color(hue: 270.0 / 360.0, saturation: 0.6, brightness: 0.9)
+
     // Helper function to decide how to pick the glucose color
     static func getDynamicGlucoseColor(
         glucoseValue: Decimal,
@@ -87,14 +92,14 @@ extension Color {
                 targetGlucose: targetGlucose
             )
         }
-        // Otheriwse, use static (orange = high, red = low, green = range)
+        // Otherwise, use static colors
         else {
             if glucoseValue >= highGlucoseColorValue {
-                return Color.orange
+                return Color.staticHigh
             } else if glucoseValue <= lowGlucoseColorValue {
-                return Color.red
+                return Color.staticLow
             } else {
-                return Color.green
+                return Color.staticInRange
             }
         }
     }

+ 9 - 4
Trio/Sources/Helpers/DynamicGlucoseColor.swift

@@ -18,14 +18,14 @@ public func getDynamicGlucoseColor(
             targetGlucose: targetGlucose
         )
     }
-    // Otheriwse, use static (orange = high, red = low, green = range)
+    // Otherwise, use the static colors
     else {
         if glucoseValue >= highGlucoseColorValue {
-            return Color.orange
+            return Color.staticHigh
         } else if glucoseValue <= lowGlucoseColorValue {
-            return Color.red
+            return Color.staticLow
         } else {
-            return Color.green
+            return Color.staticInRange
         }
     }
 }
@@ -74,4 +74,9 @@ public extension Color {
     static let dynamicBlue = Color(hue: 200.0 / 360.0, saturation: 0.6, brightness: 0.9)
     static let dynamicIndigo = Color(hue: 235.0 / 360.0, saturation: 0.6, brightness: 0.9)
     static let dynamicPurple = Color(hue: 270.0 / 360.0, saturation: 0.6, brightness: 0.9)
+
+    // Colors used when the Static Glucose Color Scheme is selected
+    static let staticLow = Color.dynamicRed
+    static let staticInRange = Color.dynamicGreen
+    static let staticHigh = Color.dynamicPurple
 }

+ 15 - 15
Trio/Sources/Modules/Stat/View/ChartsView.swift

@@ -64,17 +64,17 @@ struct ChartsView: View {
                     PointMark(
                         x: .value("Time", item.date ?? Date(), unit: .second),
                         y: .value("Value", Decimal(item.glucose) * conversionFactor)
-                    ).foregroundStyle(Color.orange.gradient).symbolSize(size).interpolationMethod(.cardinal)
+                    ).foregroundStyle(Color.staticHigh.gradient).symbolSize(size).interpolationMethod(.cardinal)
                 } else if item.glucose < Int(lowLimit) {
                     PointMark(
                         x: .value("Time", item.date ?? Date(), unit: .second),
                         y: .value("Value", Decimal(item.glucose) * conversionFactor)
-                    ).foregroundStyle(Color.red.gradient).symbolSize(size).interpolationMethod(.cardinal)
+                    ).foregroundStyle(Color.staticLow.gradient).symbolSize(size).interpolationMethod(.cardinal)
                 } else {
                     PointMark(
                         x: .value("Time", item.date ?? Date(), unit: .second),
                         y: .value("Value", Decimal(item.glucose) * conversionFactor)
-                    ).foregroundStyle(Color.green.gradient).symbolSize(size).interpolationMethod(.cardinal)
+                    ).foregroundStyle(Color.staticInRange.gradient).symbolSize(size).interpolationMethod(.cardinal)
                 }
             }
         }
@@ -133,13 +133,13 @@ struct ChartsView: View {
                     localized:
                     "Low",
                     comment: ""
-                ) + " (<\(low.formatted(.number.grouping(.never).rounded().precision(.fractionLength(fraction)))))": .red,
-                String(localized: "In Range", comment: ""): .green,
+                ) + " (<\(low.formatted(.number.grouping(.never).rounded().precision(.fractionLength(fraction)))))": .staticLow,
+                String(localized: "In Range", comment: ""): .staticInRange,
                 String(
                     localized:
                     "High",
                     comment: ""
-                ) + " (>\(high.formatted(.number.grouping(.never).rounded().precision(.fractionLength(fraction)))))": .orange
+                ) + " (>\(high.formatted(.number.grouping(.never).rounded().precision(.fractionLength(fraction)))))": .staticHigh
             ]).frame(maxHeight: 25)
         }
         .frame(maxWidth: .infinity, alignment: .center) // Align the entire VStack to center
@@ -194,13 +194,13 @@ struct ChartsView: View {
                 localized:
                 "Low",
                 comment: ""
-            ) + " (< \(low.formatted(.number.grouping(.never).rounded().precision(.fractionLength(fraction)))))": .red,
-            "\(low.formatted(.number.precision(.fractionLength(fraction)))) - \(high.formatted(.number.precision(.fractionLength(fraction))))": .green,
+            ) + " (< \(low.formatted(.number.grouping(.never).rounded().precision(.fractionLength(fraction)))))": .staticLow,
+            "\(low.formatted(.number.precision(.fractionLength(fraction)))) - \(high.formatted(.number.precision(.fractionLength(fraction))))": .staticInRange,
             String(
                 localized:
                 "High",
                 comment: ""
-            ) + " (> \(high.formatted(.number.grouping(.never).rounded().precision(.fractionLength(fraction)))))": .orange
+            ) + " (> \(high.formatted(.number.grouping(.never).rounded().precision(.fractionLength(fraction)))))": .staticHigh
         ])
     }
 
@@ -218,7 +218,7 @@ struct ChartsView: View {
                         .foregroundColor(.secondary)
                     Text("\(value.formatted(.number.precision(.fractionLength(0 ... 1)))) %")
                         .frame(width: 45, alignment: .trailing)
-                        .foregroundColor(.orange)
+                        .foregroundColor(.staticHigh)
                 }.font(.caption)
                 HStack {
                     let value = 100.0 * Double(mapGlucoseNormal.count) / Double(mapGlucose.count)
@@ -227,7 +227,7 @@ struct ChartsView: View {
                         .foregroundColor(.secondary)
                     Text("\(value.formatted(.number.precision(.fractionLength(0 ... 1)))) %")
                         .frame(width: 45, alignment: .trailing)
-                        .foregroundColor(.green)
+                        .foregroundColor(.staticInRange)
                 }.font(.caption)
                 HStack {
                     let value = 100.0 * Double(mapGlucoseAcuteLow.count) / Double(mapGlucose.count)
@@ -236,7 +236,7 @@ struct ChartsView: View {
                         .foregroundColor(.secondary)
                     Text("\(value.formatted(.number.precision(.fractionLength(0 ... 1)))) %")
                         .frame(width: 45, alignment: .trailing)
-                        .foregroundColor(.red)
+                        .foregroundColor(.staticLow)
                 }.font(.caption)
             }
         }
@@ -254,14 +254,14 @@ struct ChartsView: View {
                     let value = 100.0 * Double(mapGlucoseLow.count) / Double(mapGlucose.count)
                     Text(units == .mmolL ? "< 3.3" : "< 59").font(.caption2).foregroundColor(.secondary)
                     Text(value.formatted(.number.precision(.fractionLength(0 ... 1)))).font(.caption)
-                        .foregroundColor(value == 0 ? .green : .red)
+                        .foregroundColor(value == 0 ? .staticInRange : .staticLow)
                     Text("%").font(.caption)
                 }
                 Spacer()
                 HStack {
                     let value = 100.0 * Double(mapGlucoseNormal.count) / Double(mapGlucose.count)
                     Text(units == .mmolL ? "3.9-7.8" : "70-140").foregroundColor(.secondary)
-                    Text(value.formatted(.number.precision(.fractionLength(0 ... 1)))).foregroundColor(.green)
+                    Text(value.formatted(.number.precision(.fractionLength(0 ... 1)))).foregroundColor(.staticInRange)
                     Text("%").foregroundColor(.secondary)
                 }.font(.caption)
                 Spacer()
@@ -269,7 +269,7 @@ struct ChartsView: View {
                     let value = 100.0 * Double(mapGlucoseAcuteHigh.count) / Double(mapGlucose.count)
                     Text(units == .mmolL ? "> 11.0" : "> 198").font(.caption).foregroundColor(.secondary)
                     Text(value.formatted(.number.precision(.fractionLength(0 ... 1)))).font(.caption)
-                        .foregroundColor(value == 0 ? .green : .orange)
+                        .foregroundColor(value == 0 ? .staticInRange : .staticHigh)
                     Text("%").font(.caption)
                 }
                 Spacer()

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

@@ -329,9 +329,9 @@ struct GlucoseDailyPercentileChart: View {
             "10-90%": .blue.opacity(0.3),
             "25-75%": .blue.opacity(0.5),
             "Median": .blue,
-            "\(timeInRangeType.bottomThreshold.formatted(withUnits: units))": .red,
-            "\(timeInRangeType.topThreshold.formatted(withUnits: units))": .mint,
-            "\(highLimit.formatted(withUnits: units))": .orange
+            "\(timeInRangeType.bottomThreshold.formatted(withUnits: units))": .staticLow,
+            "\(timeInRangeType.topThreshold.formatted(withUnits: units))": .staticInRange,
+            "\(highLimit.formatted(withUnits: units))": .staticHigh
         ])
         .chartScrollableAxes(.horizontal)
         .chartScrollPosition(x: $scrollPosition)

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

@@ -123,18 +123,18 @@ struct GlucosePercentileChart: View {
                 "10-90%": Color.blue.opacity(0.3),
                 "25-75%": Color.blue.opacity(0.5),
                 "Median": Color.blue,
-                "\(timeInRangeType.bottomThreshold.formatted(withUnits: units))": Color.red,
-                "\(timeInRangeType.topThreshold.formatted(withUnits: units))": Color.mint,
-                "\(highLimit.formatted(withUnits: units))": Color.orange
+                "\(timeInRangeType.bottomThreshold.formatted(withUnits: units))": Color.staticLow,
+                "\(timeInRangeType.topThreshold.formatted(withUnits: units))": Color.staticInRange,
+                "\(highLimit.formatted(withUnits: units))": Color.staticHigh
             ])
             .chartLegend(position: .bottom, alignment: .leading, spacing: 12) {
                 let legendItems: [(String, Color)] = [
                     ("10-90%", Color.blue.opacity(0.3)),
                     ("25-75%", Color.blue.opacity(0.5)),
                     (String(localized: "Median"), Color.blue),
-                    (String(localized: "\(timeInRangeType.bottomThreshold.formatted(withUnits: units))"), Color.red),
-                    (String(localized: "\(timeInRangeType.topThreshold.formatted(withUnits: units))"), Color.mint),
-                    (String(localized: "\(highLimit.formatted(withUnits: units))"), Color.orange)
+                    (String(localized: "\(timeInRangeType.bottomThreshold.formatted(withUnits: units))"), Color.staticLow),
+                    (String(localized: "\(timeInRangeType.topThreshold.formatted(withUnits: units))"), Color.staticInRange),
+                    (String(localized: "\(highLimit.formatted(withUnits: units))"), Color.staticHigh)
                 ]
 
                 let columns = [GridItem(.adaptive(minimum: 100), spacing: 4)]

+ 3 - 3
Trio/Sources/Modules/Treatments/View/ForecastChart.swift

@@ -147,11 +147,11 @@ struct ForecastChart: View {
                 .zIndex(-1)
                 .symbolSize(CGSize(width: 15, height: 15))
                 .foregroundStyle(
-                    Decimal(selectedGlucose.glucose) > state.highGlucose ? Color.orange
+                    Decimal(selectedGlucose.glucose) > state.highGlucose ? Color.staticHigh
                         .opacity(0.8) :
                         (
-                            Decimal(selectedGlucose.glucose) < state.lowGlucose ? Color.red.opacity(0.8) : Color.green
-                                .opacity(0.8)
+                            Decimal(selectedGlucose.glucose) < state.lowGlucose ? Color.staticLow.opacity(0.8)
+                                : Color.staticInRange.opacity(0.8)
                         )
                 )