Explorar o código

Use Short date format when over 6 hours for x-axis

Jon Mårtensson %!s(int64=3) %!d(string=hai) anos
pai
achega
0c017da3d5
Modificáronse 1 ficheiros con 10 adicións e 2 borrados
  1. 10 2
      FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

+ 10 - 2
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

@@ -79,6 +79,13 @@ struct MainChartView: View {
         return formatter
     }
 
+    private var date24Formatter: DateFormatter {
+        let formatter = DateFormatter()
+        formatter.locale = Locale(identifier: "en_US_POSIX")
+        formatter.setLocalizedDateFormatFromTemplate("HH")
+        return formatter
+    }
+
     private var glucoseFormatter: NumberFormatter {
         let formatter = NumberFormatter()
         formatter.numberStyle = .decimal
@@ -295,10 +302,11 @@ struct MainChartView: View {
     }
 
     private func timeLabelsView(fullSize: CGSize) -> some View {
-        ZStack {
+        let format = screenHours > 6 ? date24Formatter : dateFormatter
+        return ZStack {
             // X time labels
             ForEach(0 ..< hours + hours) { hour in
-                Text(dateFormatter.string(from: firstHourDate().addingTimeInterval(hour.hours.timeInterval)))
+                Text(format.string(from: firstHourDate().addingTimeInterval(hour.hours.timeInterval)))
                     .font(.caption)
                     .position(
                         x: firstHourPosition(viewWidth: fullSize.width) +