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

Add custom legend for distribution; localized strings

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

+ 12 - 1
Trio/Sources/Localizations/Main/Localizable.xcstrings

@@ -80930,6 +80930,9 @@
         }
       }
     },
+    "Glucose Count" : {
+
+    },
     "Glucose Data used for statistics" : {
       "comment" : "Debug option view Glucose Data used for statistics",
       "extractionState" : "manual",
@@ -100121,6 +100124,9 @@
         }
       }
     },
+    "Loops per day" : {
+
+    },
     "Low" : {
       "comment" : "Low Glucose Threshold in Statistics settings",
       "localizations" : {
@@ -127509,7 +127515,6 @@
     },
     "Readings" : {
       "comment" : "CGM readings in statView",
-      "extractionState" : "stale",
       "localizations" : {
         "ar" : {
           "stringUnit" : {
@@ -127836,6 +127841,9 @@
         }
       }
     },
+    "Readings per Day" : {
+
+    },
     "Received unexpected error in %@ from %@: %@" : {
       "localizations" : {
         "en" : {
@@ -147126,6 +147134,9 @@
         }
       }
     },
+    "Successful Loops" : {
+
+    },
     "Suggested at" : {
       "comment" : "Headline in suggested pop up (at: at what time)",
       "extractionState" : "manual",

+ 4 - 4
Trio/Sources/Modules/Stat/StatStateModel+Setup/LoopChartSetup.swift

@@ -164,8 +164,8 @@ extension Stat.StateModel {
                 let glucosePercentage = (Double(totalGlucose) / maxLoopsPerDay) * 100
 
                 return [
-                    ("Successful Loops", successfulLoops, loopPercentage),
-                    ("Glucose Count", totalGlucose, glucosePercentage)
+                    (String(localized: "Successful Loops"), successfulLoops, loopPercentage),
+                    (String(localized: "Glucose Count"), totalGlucose, glucosePercentage)
                 ]
 
             case .Month,
@@ -182,8 +182,8 @@ extension Stat.StateModel {
                 let glucosePercentage = (averageGlucosePerDay / maxLoopsPerDay) * 100
 
                 return [
-                    ("Successful Loops", Int(round(averageLoopsPerDay)), loopPercentage),
-                    ("Glucose Count", Int(round(averageGlucosePerDay)), glucosePercentage)
+                    (String(localized: "Successful Loops"), Int(round(averageLoopsPerDay)), loopPercentage),
+                    (String(localized: "Glucose Count"), Int(round(averageGlucosePerDay)), glucosePercentage)
                 ]
             }
         }

+ 0 - 2
Trio/Sources/Modules/Stat/View/StatRootView.swift

@@ -197,12 +197,10 @@ extension Stat {
                     }
 
                 case .bolusDistribution:
-                    // TODO: -
                     var hasBolusData: Bool {
                         state.dailyBolusStats.contains { $0.manualBolus > 0 || $0.smb > 0 || $0.external > 0 }
                     }
 
-                    // TODO: -
                     if state.dailyBolusStats.isEmpty || !hasBolusData {
                         ContentUnavailableView(
                             String(localized: "No Bolus Data"),

+ 39 - 0
Trio/Sources/Modules/Stat/View/ViewElements/GlucoseDistributionChart.swift

@@ -32,6 +32,38 @@ struct GlucoseDistributionChart: View {
                 "200-220": .orange.opacity(0.7),
                 ">220": .orange.opacity(0.8)
             ])
+            .chartLegend(position: .bottom) {
+                let legendItems: [(String, Color)] = [
+                    ("<\(units == .mgdL ? Decimal(54) : 54.asMmolL)", .purple.opacity(0.7)),
+                    (
+                        "\(units == .mgdL ? Decimal(54) : 54.asMmolL)-\(units == .mgdL ? Decimal(70) : 70.asMmolL)",
+                        .red.opacity(0.7)
+                    ),
+                    ("\(units == .mgdL ? Decimal(70) : 70.asMmolL)-\(units == .mgdL ? Decimal(140) : 140.asMmolL)", .green),
+                    (
+                        "\(units == .mgdL ? Decimal(140) : 140.asMmolL)-\(units == .mgdL ? Decimal(180) : 180.asMmolL)",
+                        .green.opacity(0.7)
+                    ),
+                    (
+                        "\(units == .mgdL ? Decimal(180) : 180.asMmolL)-\(units == .mgdL ? Decimal(200) : 200.asMmolL)",
+                        .yellow.opacity(0.7)
+                    ),
+                    (
+                        "\(units == .mgdL ? Decimal(200) : 200.asMmolL)-\(units == .mgdL ? Decimal(220) : 220.asMmolL)",
+                        .orange.opacity(0.7)
+                    ),
+                    (">\(units == .mgdL ? Decimal(220) : 220.asMmolL)", .orange.opacity(0.8))
+                ]
+
+                let columns = [GridItem(.adaptive(minimum: 65), spacing: 4)]
+
+                LazyVGrid(columns: columns, alignment: .leading, spacing: 4) {
+                    ForEach(legendItems, id: \.0) { item in
+                        legendItem(label: item.0, color: item.1)
+                    }
+                }
+            }
+
             .chartYAxis {
                 AxisMarks(position: .trailing) { value in
                     if let percentage = value.as(Double.self) {
@@ -59,4 +91,11 @@ struct GlucoseDistributionChart: View {
             .frame(height: 200)
         }
     }
+
+    @ViewBuilder func legendItem(label: String, color: Color) -> some View {
+        HStack(spacing: 4) {
+            Image(systemName: "circle.fill").foregroundStyle(color)
+            Text(label).foregroundStyle(Color.secondary)
+        }.font(.caption2)
+    }
 }

+ 4 - 4
Trio/Sources/Modules/Stat/View/ViewElements/LoopBarChartView.swift

@@ -55,24 +55,24 @@ struct LoopBarChartView: View {
             switch selectedDuration {
             case .Day,
                  .Today:
-                return "\(data.count) Loops"
+                return "\(data.count) " + String(localized: "Loops")
             case .Month,
                  .Total,
                  .Week:
                 let maxLoopsPerDay = 288.0
                 let averageLoopsPerDay = Double(data.count) / maxLoopsPerDay * 100
-                return "\(Int(round(averageLoopsPerDay))) Loops per day"
+                return "\(Int(round(averageLoopsPerDay))) " + String(localized: "Loops per day")
             }
         } else {
             // For Glucose Count, show different text based on duration
             switch selectedDuration {
             case .Day,
                  .Today:
-                return "\(data.count) Readings"
+                return "\(data.count) " + String(localized: "Readings")
             case .Month,
                  .Total,
                  .Week:
-                return "\(data.count) Readings per day"
+                return "\(data.count) " + String(localized: "Readings per Day")
             }
         }
     }