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

if screenHours is equal to 12 or higher then display only every second time label to avoid a busy time label view

polscm32 2 лет назад
Родитель
Сommit
26d454a07b
1 измененных файлов с 34 добавлено и 9 удалено
  1. 34 9
      FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

+ 34 - 9
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

@@ -340,20 +340,45 @@ struct MainChartView: View {
         }
     }
 
+    // MARK: TO DO: CHANGE TIME LABELS TO ONLY DISPLAY EVERY SECOND LABEL WHEN SCREENHOURS IS TOO BIG
+
+//    private func timeLabelsView(fullSize: CGSize) -> some View {
+//        let format = screenHours > 6 ? date24Formatter : dateFormatter
+//        return ZStack {
+//            // X time labels
+//            ForEach(0 ..< hours + hours) { hour in
+//                Text(format.string(from: firstHourDate().addingTimeInterval(hour.hours.timeInterval)))
+//                    .font(.caption)
+//                    .position(
+//                        x: firstHourPosition(viewWidth: fullSize.width) +
+//                            oneSecondStep(viewWidth: fullSize.width) *
+//                            CGFloat(hour) * CGFloat(1.hours.timeInterval),
+//                        y: 10.0
+//                    )
+//                    .foregroundColor(.secondary)
+//            }
+//        }.frame(maxHeight: 20)
+//    }
+
     private func timeLabelsView(fullSize: CGSize) -> some View {
         let format = screenHours > 6 ? date24Formatter : dateFormatter
         return ZStack {
             // X time labels
             ForEach(0 ..< hours + hours) { hour in
-                Text(format.string(from: firstHourDate().addingTimeInterval(hour.hours.timeInterval)))
-                    .font(.caption)
-                    .position(
-                        x: firstHourPosition(viewWidth: fullSize.width) +
-                            oneSecondStep(viewWidth: fullSize.width) *
-                            CGFloat(hour) * CGFloat(1.hours.timeInterval),
-                        y: 10.0
-                    )
-                    .foregroundColor(.secondary)
+                if screenHours >= 12 && hour % 2 == 1 {
+                    // only show every second time label if screenHours is too big
+                    EmptyView()
+                } else {
+                    Text(format.string(from: firstHourDate().addingTimeInterval(hour.hours.timeInterval)))
+                        .font(.caption)
+                        .position(
+                            x: firstHourPosition(viewWidth: fullSize.width) +
+                                oneSecondStep(viewWidth: fullSize.width) *
+                                CGFloat(hour) * CGFloat(1.hours.timeInterval),
+                            y: 10.0
+                        )
+                        .foregroundColor(.secondary)
+                }
             }
         }.frame(maxHeight: 20)
     }