Pārlūkot izejas kodu

Ensure glucose charts display 0 for midnight (start and end)

Deniz Cengiz 1 gadu atpakaļ
vecāks
revīzija
2d7a8eb6e4

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

@@ -81,10 +81,19 @@ struct GlucoseDistributionChart: View {
                     .padding(.vertical, 3)
                     .padding(.vertical, 3)
             }
             }
             .chartXAxis {
             .chartXAxis {
-                AxisMarks(values: .stride(by: .hour, count: 3)) { _ in
-                    AxisValueLabel(format: .dateTime.hour(.defaultDigits(amPM: .narrow)), anchor: .top)
-                        .font(.footnote)
-                    AxisGridLine()
+                AxisMarks(values: .stride(by: .hour, count: 3)) { value in
+                    if let date = value.as(Date.self) {
+                        let hour = Calendar.current.component(.hour, from: date)
+                        switch hour {
+                        case 0,
+                             12:
+                            AxisValueLabel(format: .dateTime.hour())
+                        default:
+                            AxisValueLabel(format: .dateTime.hour(.defaultDigits(amPM: .omitted)))
+                        }
+
+                        AxisGridLine()
+                    }
                 }
                 }
             }
             }
             .frame(height: 200)
             .frame(height: 200)

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

@@ -146,10 +146,19 @@ struct GlucosePercentileChart: View {
                     .padding(.vertical, 3)
                     .padding(.vertical, 3)
             }
             }
             .chartXAxis {
             .chartXAxis {
-                AxisMarks(values: .stride(by: .hour, count: 3)) { _ in
-                    AxisValueLabel(format: .dateTime.hour(.defaultDigits(amPM: .narrow)), anchor: .top)
-                        .font(.footnote)
-                    AxisGridLine()
+                AxisMarks(values: .stride(by: .hour, count: 3)) { value in
+                    if let date = value.as(Date.self) {
+                        let hour = Calendar.current.component(.hour, from: date)
+                        switch hour {
+                        case 0,
+                             12:
+                            AxisValueLabel(format: .dateTime.hour())
+                        default:
+                            AxisValueLabel(format: .dateTime.hour(.defaultDigits(amPM: .omitted)))
+                        }
+
+                        AxisGridLine()
+                    }
                 }
                 }
             }
             }
             .chartXSelection(value: $selection.animation(.easeInOut))
             .chartXSelection(value: $selection.animation(.easeInOut))