Kaynağa Gözat

small fixes

polscm32 aka Marvout 1 yıl önce
ebeveyn
işleme
fe33ad00bd

+ 45 - 12
FreeAPS/Sources/Modules/Stat/View/ViewElements/BolusStatsView.swift

@@ -81,12 +81,11 @@ struct BolusStatsView: View {
         let calendar = Calendar.current
         let today = Date()
 
-        let timeFormat = start.formatted(.dateTime.hour().minute())
-
         // Special handling for Day view with relative dates
         if selectedDuration == .Day {
             let startDateText: String
             let endDateText: String
+            let timeFormat = start.formatted(.dateTime.hour().minute())
 
             // Format start date
             if calendar.isDate(start, inSameDayAs: today) {
@@ -118,8 +117,32 @@ struct BolusStatsView: View {
             return "\(startDateText), \(timeFormat) - \(endDateText), \(end.formatted(.dateTime.hour().minute()))"
         }
 
-        // Standard format for other views
-        return "\(start.formatted()) - \(end.formatted())"
+        // Standard format for other views - only show dates without time
+        let startText: String
+        let endText: String
+
+        // Check for relative dates
+        if calendar.isDate(start, inSameDayAs: today) {
+            startText = "Today"
+        } else if calendar.isDate(start, inSameDayAs: calendar.date(byAdding: .day, value: -1, to: today)!) {
+            startText = "Yesterday"
+        } else if calendar.isDate(start, inSameDayAs: calendar.date(byAdding: .day, value: 1, to: today)!) {
+            startText = "Tomorrow"
+        } else {
+            startText = start.formatted(.dateTime.day().month())
+        }
+
+        if calendar.isDate(end, inSameDayAs: today) {
+            endText = "Today"
+        } else if calendar.isDate(end, inSameDayAs: calendar.date(byAdding: .day, value: -1, to: today)!) {
+            endText = "Yesterday"
+        } else if calendar.isDate(end, inSameDayAs: calendar.date(byAdding: .day, value: 1, to: today)!) {
+            endText = "Tomorrow"
+        } else {
+            endText = end.formatted(.dateTime.day().month())
+        }
+
+        return "\(startText) - \(endText)"
     }
 
     private func isSameTimeUnit(_ date1: Date, _ date2: Date) -> Bool {
@@ -214,7 +237,7 @@ struct BolusStatsView: View {
             Spacer()
 
             Text(formatVisibleDateRange())
-                .font(.subheadline)
+                .font(.footnote)
                 .foregroundStyle(.secondary)
         }
     }
@@ -288,7 +311,7 @@ struct BolusStatsView: View {
                 if let amount = value.as(Double.self) {
                     AxisValueLabel {
                         Text(amount.formatted(.number.precision(.fractionLength(0))) + " U")
-                            .font(.subheadline)
+                            .font(.footnote)
                     }
                     AxisGridLine()
                 }
@@ -304,25 +327,25 @@ struct BolusStatsView: View {
                     case .Day:
                         if hour % 6 == 0 { // Show only every 6 hours
                             AxisValueLabel(format: dateFormat, centered: true)
-                                .font(.subheadline)
+                                .font(.footnote)
                             AxisGridLine()
                         }
                     case .Month:
                         if day % 5 == 0 { // Only show every 5th day
                             AxisValueLabel(format: dateFormat, centered: true)
-                                .font(.subheadline)
+                                .font(.footnote)
                             AxisGridLine()
                         }
                     case .Total:
                         // Only show January, April, July, October
                         if day == 1 && Calendar.current.component(.month, from: date) % 3 == 1 {
                             AxisValueLabel(format: dateFormat, centered: true)
-                                .font(.subheadline)
+                                .font(.footnote)
                             AxisGridLine()
                         }
                     default:
                         AxisValueLabel(format: dateFormat, centered: true)
-                            .font(.subheadline)
+                            .font(.footnote)
                         AxisGridLine()
                     }
                 }
@@ -350,10 +373,20 @@ private struct BolusSelectionPopover: View {
     let date: Date
     let bolus: BolusStats
     let selectedDuration: Stat.StateModel.StatsTimeInterval
+
+    private var timeText: String {
+        if selectedDuration == .Day {
+            let hour = Calendar.current.component(.hour, from: date)
+            return "\(hour):00-\(hour + 1):00"
+        } else {
+            return date.formatted(.dateTime.month().day())
+        }
+    }
+
     var body: some View {
         VStack(alignment: .leading, spacing: 4) {
-            Text(selectedDuration == .Day ? date.formatted(.dateTime.hour().minute()) : date.formatted(.dateTime.month().day()))
-                .font(.subheadline)
+            Text(timeText)
+                .font(.footnote)
                 .fontWeight(.bold)
 
             Grid(alignment: .leading) {

+ 12 - 3
FreeAPS/Sources/Modules/Stat/View/ViewElements/GlucoseDistributionChart.swift

@@ -33,17 +33,26 @@ struct GlucoseDistributionChart: View {
                 ">220": .orange.opacity(0.8)
             ])
             .chartYAxis {
-                AxisMarks(position: .leading)
+                AxisMarks(position: .trailing) { value in
+                    if let percentage = value.as(Double.self) {
+                        AxisValueLabel {
+                            Text((percentage / 100).formatted(.percent.precision(.fractionLength(0))))
+                                .font(.footnote)
+                        }
+                        AxisGridLine()
+                    }
+                }
             }
-            .chartYAxisLabel(alignment: .leading) {
+            .chartYAxisLabel(alignment: .trailing) {
                 Text("Percentage")
                     .foregroundStyle(.primary)
-                    .font(.caption)
+                    .font(.footnote)
                     .padding(.vertical, 3)
             }
             .chartXAxis {
                 AxisMarks(values: .stride(by: .hour, count: 3)) { _ in
                     AxisValueLabel(format: .dateTime.hour(.defaultDigits(amPM: .narrow)), anchor: .top)
+                        .font(.footnote)
                     AxisGridLine()
                 }
             }

+ 22 - 9
FreeAPS/Sources/Modules/Stat/View/ViewElements/GlucosePercentileChart.swift

@@ -80,11 +80,7 @@ struct GlucosePercentileChart: View {
                         .annotation(
                             position: .top,
                             spacing: 0,
-//                            overflowResolution: .init(x: .fit, y: .disabled)
-                            overflowResolution: .init(
-                                x: .fit(to: .chart),
-                                y: .fit(to: .chart)
-                            ) // for coherence with the other charts
+                            overflowResolution: .init(x: .fit, y: .disabled)
                         ) {
                             AGPSelectionPopover(
                                 stats: selectedStats,
@@ -95,17 +91,26 @@ struct GlucosePercentileChart: View {
                 }
             }
             .chartYAxis {
-                AxisMarks(position: .leading)
+                AxisMarks(position: .trailing) { value in
+                    if let glucose = value.as(Double.self) {
+                        AxisValueLabel {
+                            Text(glucose.formatted(.number.precision(.fractionLength(0))))
+                                .font(.footnote)
+                        }
+                        AxisGridLine()
+                    }
+                }
             }
-            .chartYAxisLabel(alignment: .leading) {
+            .chartYAxisLabel(alignment: .trailing) {
                 Text("\(units.rawValue)")
                     .foregroundStyle(.primary)
-                    .font(.caption)
+                    .font(.footnote)
                     .padding(.vertical, 3)
             }
             .chartXAxis {
                 AxisMarks(values: .stride(by: .hour, count: 3)) { _ in
                     AxisValueLabel(format: .dateTime.hour(.defaultDigits(amPM: .narrow)), anchor: .top)
+                        .font(.footnote)
                     AxisGridLine()
                 }
             }
@@ -181,11 +186,19 @@ struct AGPSelectionPopover: View {
     let time: Date
     let units: GlucoseUnits
 
+    private var timeText: String {
+        if let hour = Calendar.current.dateComponents([.hour], from: time).hour {
+            return "\(hour):00-\(hour + 1):00"
+        } else {
+            return time.formatted(.dateTime.hour().minute())
+        }
+    }
+
     var body: some View {
         VStack(alignment: .leading, spacing: 4) {
             HStack {
                 Image(systemName: "clock")
-                Text(time.formatted(.dateTime.hour().minute(.twoDigits)))
+                Text(timeText)
                     .fontWeight(.bold)
             }
             .font(.subheadline)

+ 44 - 12
FreeAPS/Sources/Modules/Stat/View/ViewElements/MealStatsView.swift

@@ -124,12 +124,11 @@ struct MealStatsView: View {
         let calendar = Calendar.current
         let today = Date()
 
-        let timeFormat = start.formatted(.dateTime.hour().minute())
-
         // Special handling for Day view with relative dates
         if selectedDuration == .Day {
             let startDateText: String
             let endDateText: String
+            let timeFormat = start.formatted(.dateTime.hour().minute())
 
             // Format start date
             if calendar.isDate(start, inSameDayAs: today) {
@@ -161,8 +160,32 @@ struct MealStatsView: View {
             return "\(startDateText), \(timeFormat) - \(endDateText), \(end.formatted(.dateTime.hour().minute()))"
         }
 
-        // Standard format for other views
-        return "\(start.formatted()) - \(end.formatted())"
+        // Standard format for other views - only show dates without time
+        let startText: String
+        let endText: String
+
+        // Check for relative dates
+        if calendar.isDate(start, inSameDayAs: today) {
+            startText = "Today"
+        } else if calendar.isDate(start, inSameDayAs: calendar.date(byAdding: .day, value: -1, to: today)!) {
+            startText = "Yesterday"
+        } else if calendar.isDate(start, inSameDayAs: calendar.date(byAdding: .day, value: 1, to: today)!) {
+            startText = "Tomorrow"
+        } else {
+            startText = start.formatted(.dateTime.day().month())
+        }
+
+        if calendar.isDate(end, inSameDayAs: today) {
+            endText = "Today"
+        } else if calendar.isDate(end, inSameDayAs: calendar.date(byAdding: .day, value: -1, to: today)!) {
+            endText = "Yesterday"
+        } else if calendar.isDate(end, inSameDayAs: calendar.date(byAdding: .day, value: 1, to: today)!) {
+            endText = "Tomorrow"
+        } else {
+            endText = end.formatted(.dateTime.day().month())
+        }
+
+        return "\(startText) - \(endText)"
     }
 
     /// Returns the initial scroll position date based on the selected duration
@@ -267,7 +290,7 @@ struct MealStatsView: View {
             Spacer()
 
             Text(formatVisibleDateRange())
-                .font(.subheadline)
+                .font(.footnote)
                 .foregroundStyle(.secondary)
         }
     }
@@ -341,7 +364,7 @@ struct MealStatsView: View {
                 if let amount = value.as(Double.self) {
                     AxisValueLabel {
                         Text(amount.formatted(.number.precision(.fractionLength(0))) + " g")
-                            .font(.subheadline)
+                            .font(.footnote)
                     }
                     AxisGridLine()
                 }
@@ -357,24 +380,24 @@ struct MealStatsView: View {
                     case .Day:
                         if hour % 6 == 0 {
                             AxisValueLabel(format: dateFormat, centered: true)
-                                .font(.subheadline)
+                                .font(.footnote)
                             AxisGridLine()
                         }
                     case .Month:
                         if day % 5 == 0 {
                             AxisValueLabel(format: dateFormat, centered: true)
-                                .font(.subheadline)
+                                .font(.footnote)
                             AxisGridLine()
                         }
                     case .Total:
                         if day == 1 && Calendar.current.component(.month, from: date) % 3 == 1 {
                             AxisValueLabel(format: dateFormat, centered: true)
-                                .font(.subheadline)
+                                .font(.footnote)
                             AxisGridLine()
                         }
                     default:
                         AxisValueLabel(format: dateFormat, centered: true)
-                            .font(.subheadline)
+                            .font(.footnote)
                         AxisGridLine()
                     }
                 }
@@ -411,11 +434,20 @@ private struct MealSelectionPopover: View {
     // The selected duration in the time picker
     let selectedDuration: Stat.StateModel.StatsTimeInterval
 
+    private var timeText: String {
+        if selectedDuration == .Day {
+            let hour = Calendar.current.component(.hour, from: date)
+            return "\(hour):00-\(hour + 1):00"
+        } else {
+            return date.formatted(.dateTime.month().day())
+        }
+    }
+
     var body: some View {
         VStack(alignment: .leading, spacing: 4) {
             // Display formatted date header
-            Text(selectedDuration == .Day ? date.formatted(.dateTime.hour().minute()) : date.formatted(.dateTime.month().day()))
-                .font(.subheadline)
+            Text(timeText)
+                .font(.footnote)
                 .fontWeight(.bold)
 
             // Grid layout for macronutrient values

+ 44 - 11
FreeAPS/Sources/Modules/Stat/View/ViewElements/TDDChart.swift

@@ -75,12 +75,11 @@ struct TDDChartView: View {
         let calendar = Calendar.current
         let today = Date()
 
-        let timeFormat = start.formatted(.dateTime.hour().minute())
-
         // Special handling for Day view with relative dates
         if selectedDuration == .Day {
             let startDateText: String
             let endDateText: String
+            let timeFormat = start.formatted(.dateTime.hour().minute())
 
             // Format start date
             if calendar.isDate(start, inSameDayAs: today) {
@@ -112,8 +111,32 @@ struct TDDChartView: View {
             return "\(startDateText), \(timeFormat) - \(endDateText), \(end.formatted(.dateTime.hour().minute()))"
         }
 
-        // Standard format for other views
-        return "\(start.formatted()) - \(end.formatted())"
+        // Standard format for other views - only show dates without time
+        let startText: String
+        let endText: String
+
+        // Check for relative dates
+        if calendar.isDate(start, inSameDayAs: today) {
+            startText = "Today"
+        } else if calendar.isDate(start, inSameDayAs: calendar.date(byAdding: .day, value: -1, to: today)!) {
+            startText = "Yesterday"
+        } else if calendar.isDate(start, inSameDayAs: calendar.date(byAdding: .day, value: 1, to: today)!) {
+            startText = "Tomorrow"
+        } else {
+            startText = start.formatted(.dateTime.day().month())
+        }
+
+        if calendar.isDate(end, inSameDayAs: today) {
+            endText = "Today"
+        } else if calendar.isDate(end, inSameDayAs: calendar.date(byAdding: .day, value: -1, to: today)!) {
+            endText = "Yesterday"
+        } else if calendar.isDate(end, inSameDayAs: calendar.date(byAdding: .day, value: 1, to: today)!) {
+            endText = "Tomorrow"
+        } else {
+            endText = end.formatted(.dateTime.day().month())
+        }
+
+        return "\(startText) - \(endText)"
     }
 
     private func getInitialScrollPosition() -> Date {
@@ -178,7 +201,7 @@ struct TDDChartView: View {
             Spacer()
 
             Text(formatVisibleDateRange())
-                .font(.subheadline)
+                .font(.footnote)
                 .foregroundStyle(.secondary)
         }
     }
@@ -220,7 +243,7 @@ struct TDDChartView: View {
                 if let amount = value.as(Double.self) {
                     AxisValueLabel {
                         Text(amount.formatted(.number.precision(.fractionLength(0))) + " U")
-                            .font(.subheadline)
+                            .font(.footnote)
                     }
                     AxisGridLine()
                 }
@@ -236,24 +259,24 @@ struct TDDChartView: View {
                     case .Day:
                         if hour % 6 == 0 {
                             AxisValueLabel(format: dateFormat, centered: true)
-                                .font(.subheadline)
+                                .font(.footnote)
                             AxisGridLine()
                         }
                     case .Month:
                         if day % 5 == 0 {
                             AxisValueLabel(format: dateFormat, centered: true)
-                                .font(.subheadline)
+                                .font(.footnote)
                             AxisGridLine()
                         }
                     case .Total:
                         if day == 1 && Calendar.current.component(.month, from: date) % 3 == 1 {
                             AxisValueLabel(format: dateFormat, centered: true)
-                                .font(.subheadline)
+                                .font(.footnote)
                             AxisGridLine()
                         }
                     default:
                         AxisValueLabel(format: dateFormat, centered: true)
-                            .font(.subheadline)
+                            .font(.footnote)
                         AxisGridLine()
                     }
                 }
@@ -279,9 +302,19 @@ private struct TDDSelectionPopover: View {
     let date: Date
     let tdd: TDDStats
     let selectedDuration: Stat.StateModel.StatsTimeInterval
+
+    private var timeText: String {
+        if selectedDuration == .Day {
+            let hour = Calendar.current.component(.hour, from: date)
+            return "\(hour):00-\(hour + 1):00"
+        } else {
+            return date.formatted(.dateTime.month().day())
+        }
+    }
+
     var body: some View {
         VStack(alignment: .leading, spacing: 4) {
-            Text(selectedDuration == .Day ? date.formatted(.dateTime.hour().minute()) : date.formatted(.dateTime.month().day()))
+            Text(timeText)
                 .font(.subheadline)
                 .fontWeight(.bold)