ソースを参照

Update stats colors to match dynamic glucose color scheme

Mike Plante 1 週間 前
コミット
850afc4527

+ 11 - 0
Trio/Sources/Helpers/DynamicGlucoseColor.swift

@@ -64,3 +64,14 @@ public func calculateHueBasedGlucoseColor(
     let color = Color(hue: hue, saturation: 0.6, brightness: 0.9)
     return color
 }
+
+// Discrete band colors sampled from the dynamic gradient above
+public extension Color {
+    static let dynamicRed = Color(hue: 0.0 / 360.0, saturation: 0.6, brightness: 0.9)
+    static let dynamicOrange = Color(hue: 30.0 / 360.0, saturation: 0.6, brightness: 0.9)
+    static let dynamicGreen = Color(hue: 120.0 / 360.0, saturation: 0.6, brightness: 0.9)
+    static let dynamicTeal = Color(hue: 165.0 / 360.0, saturation: 0.6, brightness: 0.9)
+    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)
+}

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

@@ -146,12 +146,12 @@ struct GlucoseDailyDistributionChart: View {
             }
         }
         .chartForegroundStyleScale([
-            legend("veryLow"): .purple,
-            legend("low"): .red,
-            legend("inSmallRange"): .green,
-            legend("inRange"): .darkGreen,
-            legend("high"): .loopYellow,
-            legend("veryHigh"): .orange
+            legend("veryLow"): Color.dynamicRed,
+            legend("low"): Color.dynamicOrange,
+            legend("inSmallRange"): Color.dynamicGreen,
+            legend("inRange"): Color.dynamicTeal,
+            legend("high"): Color.dynamicBlue,
+            legend("veryHigh"): Color.dynamicPurple
         ])
         .chartXSelection(value: $selectedDate.animation(.easeInOut))
         .onChange(of: selectedDate) { _, newValue in

+ 14 - 14
Trio/Sources/Modules/Stat/View/ViewElements/Glucose/GlucoseDistributionChart.swift

@@ -25,38 +25,38 @@ struct GlucoseDistributionChart: View {
                 }
             }
             .chartForegroundStyleScale([
-                "<54": .purple.opacity(0.8),
-                "54-\(timeInRangeType.bottomThreshold)": .red.opacity(0.8),
-                "\(timeInRangeType.bottomThreshold)-\(timeInRangeType.topThreshold)": .green.opacity(0.8),
-                "\(timeInRangeType.topThreshold)-180": .darkGreen.opacity(0.8),
-                "180-200": .yellow.opacity(0.8),
-                "200-220": .orange.opacity(0.8),
-                ">220": .darkOrange.opacity(0.8)
+                "<54": Color.dynamicRed.opacity(0.8),
+                "54-\(timeInRangeType.bottomThreshold)": Color.dynamicOrange.opacity(0.8),
+                "\(timeInRangeType.bottomThreshold)-\(timeInRangeType.topThreshold)": Color.dynamicGreen.opacity(0.8),
+                "\(timeInRangeType.topThreshold)-180": Color.dynamicTeal.opacity(0.8),
+                "180-200": Color.dynamicBlue.opacity(0.8),
+                "200-220": Color.dynamicIndigo.opacity(0.8),
+                ">220": Color.dynamicPurple.opacity(0.8)
             ])
             .chartLegend(position: .bottom, alignment: .leading, spacing: 12) {
                 let legendItems: [(String, Color)] = [
-                    ("<\(units == .mgdL ? Decimal(54) : 54.asMmolL)", .purple.opacity(0.8)),
+                    ("<\(units == .mgdL ? Decimal(54) : 54.asMmolL)", .dynamicRed.opacity(0.8)),
                     (
                         "\(units == .mgdL ? Decimal(54) : 54.asMmolL)-\(units == .mgdL ? Decimal(timeInRangeType.bottomThreshold) : timeInRangeType.bottomThreshold.asMmolL)",
-                        .red.opacity(0.8)
+                        .dynamicOrange.opacity(0.8)
                     ),
                     (
                         "\(units == .mgdL ? Decimal(timeInRangeType.bottomThreshold) : timeInRangeType.bottomThreshold.asMmolL)-\(units == .mgdL ? Decimal(timeInRangeType.topThreshold) : timeInRangeType.topThreshold.asMmolL)",
-                        .green.opacity(0.8)
+                        .dynamicGreen.opacity(0.8)
                     ),
                     (
                         "\(units == .mgdL ? Decimal(timeInRangeType.topThreshold) : timeInRangeType.topThreshold.asMmolL)-\(units == .mgdL ? Decimal(180) : 180.asMmolL)",
-                        .darkGreen.opacity(0.8)
+                        .dynamicTeal.opacity(0.8)
                     ),
                     (
                         "\(units == .mgdL ? Decimal(180) : 180.asMmolL)-\(units == .mgdL ? Decimal(200) : 200.asMmolL)",
-                        .yellow.opacity(0.8)
+                        .dynamicBlue.opacity(0.8)
                     ),
                     (
                         "\(units == .mgdL ? Decimal(200) : 200.asMmolL)-\(units == .mgdL ? Decimal(220) : 220.asMmolL)",
-                        .orange.opacity(0.8)
+                        .dynamicIndigo.opacity(0.8)
                     ),
-                    (">\(units == .mgdL ? Decimal(220) : 220.asMmolL)", .darkOrange.opacity(0.8))
+                    (">\(units == .mgdL ? Decimal(220) : 220.asMmolL)", .dynamicPurple.opacity(0.8))
                 ]
 
                 let columns = [GridItem(.adaptive(minimum: 65), spacing: 4)]

+ 14 - 14
Trio/Sources/Modules/Stat/View/ViewElements/Glucose/GlucoseSectorChart.swift

@@ -72,7 +72,7 @@ struct GlucoseSectorChart: View {
                         .font(.subheadline)
                         .foregroundStyle(Color.secondary)
                         Text(formatPercentage(inRangePercentage, tight: true))
-                            .foregroundStyle(Color.loopGreen)
+                            .foregroundStyle(Color.dynamicTeal)
                     }
 
                     VStack(alignment: .leading, spacing: 5) {
@@ -82,7 +82,7 @@ struct GlucoseSectorChart: View {
                         .font(.subheadline)
                         .foregroundStyle(Color.secondary)
                         Text(formatPercentage(tightPercentage, tight: true))
-                            .foregroundStyle(Color.green)
+                            .foregroundStyle(Color.dynamicGreen)
                     }
                 }.padding(.leading, 5)
 
@@ -91,7 +91,7 @@ struct GlucoseSectorChart: View {
                         Text("> \(highLimit.formatted(for: units))").font(.subheadline)
                             .foregroundStyle(Color.secondary)
                         Text(formatPercentage(highPercentage, tight: true))
-                            .foregroundStyle(Color.loopYellow)
+                            .foregroundStyle(showChart ? Color.dynamicPurple : Color.dynamicBlue)
                     }
 
                     VStack(alignment: .leading, spacing: 5) {
@@ -101,7 +101,7 @@ struct GlucoseSectorChart: View {
                         .font(.subheadline)
                         .foregroundStyle(Color.secondary)
                         Text(formatPercentage(lowPercentage, tight: true))
-                            .foregroundStyle(Color.red)
+                            .foregroundStyle(showChart ? Color.dynamicRed : Color.dynamicOrange)
                     }
                 }
                 // If not showing chart, show extra stats
@@ -111,7 +111,7 @@ struct GlucoseSectorChart: View {
                             Text("> \(Decimal(220).formatted(for: units))").font(.subheadline)
                                 .foregroundStyle(Color.secondary)
                             Text(formatPercentage(moderatelyHighPercentage, tight: true))
-                                .foregroundStyle(Color.loopYellow)
+                                .foregroundStyle(Color.dynamicIndigo)
                         }
 
                         VStack(alignment: .leading, spacing: 5) {
@@ -121,7 +121,7 @@ struct GlucoseSectorChart: View {
                             .font(.subheadline)
                             .foregroundStyle(Color.secondary)
                             Text(formatPercentage(moderatelyLowPercentage, tight: true))
-                                .foregroundStyle(Color.red)
+                                .foregroundStyle(Color.dynamicOrange)
                         }
                     }
                     VStack(alignment: .leading, spacing: 10) {
@@ -129,7 +129,7 @@ struct GlucoseSectorChart: View {
                             Text("> \(Decimal(250).formatted(for: units))").font(.subheadline)
                                 .foregroundStyle(Color.secondary)
                             Text(formatPercentage(veryHighPercentage, tight: true))
-                                .foregroundStyle(Color.orange)
+                                .foregroundStyle(Color.dynamicPurple)
                         }
 
                         VStack(alignment: .leading, spacing: 5) {
@@ -139,7 +139,7 @@ struct GlucoseSectorChart: View {
                             .font(.subheadline)
                             .foregroundStyle(Color.secondary)
                             Text(formatPercentage(veryLowPercentage, tight: true))
-                                .foregroundStyle(Color.purple)
+                                .foregroundStyle(Color.dynamicRed)
                         }
                     }
                 }
@@ -230,9 +230,9 @@ struct GlucoseSectorChart: View {
 
         // Return array of tuples with range data
         return [
-            (.high, highCount, Decimal(highCount) / Decimal(total) * 100, .loopYellow),
-            (.inRange, inRangeCount, Decimal(inRangeCount) / Decimal(total) * 100, .green),
-            (.low, lowCount, Decimal(lowCount) / Decimal(total) * 100, .red)
+            (.high, highCount, Decimal(highCount) / Decimal(total) * 100, .dynamicPurple),
+            (.inRange, inRangeCount, Decimal(inRangeCount) / Decimal(total) * 100, .dynamicGreen),
+            (.low, lowCount, Decimal(lowCount) / Decimal(total) * 100, .dynamicRed)
         ]
     }
 
@@ -279,7 +279,7 @@ struct GlucoseSectorChart: View {
 
             return RangeDetail(
                 title: String(localized: "High Glucose"),
-                color: .loopYellow,
+                color: .dynamicPurple,
                 items: [
                     (
                         String(localized: "Very High (>\(Decimal(250).formatted(for: units)))"),
@@ -304,7 +304,7 @@ struct GlucoseSectorChart: View {
 
             return RangeDetail(
                 title: String(localized: "In Range"),
-                color: .green,
+                color: .dynamicGreen,
                 items: [
                     (
                         String(
@@ -334,7 +334,7 @@ struct GlucoseSectorChart: View {
 
             return RangeDetail(
                 title: String(localized: "Low Glucose"),
-                color: .red,
+                color: .dynamicRed,
                 items: [
                     (
                         String(