Skip to content

Commit 7e3af2d

Browse files
committed
charts: continue implementing charts
1 parent a68d368 commit 7e3af2d

7 files changed

Lines changed: 25 additions & 6 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

InfiniLink/.DS_Store

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

InfiniLink/Core/Components/Charts/HeartChartView.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,22 @@ struct HeartChartView: View {
4141
var latestDate: Date {
4242
data().compactMap({ $0.date }).max() ?? Date()
4343
}
44+
var unit: Calendar.Component {
45+
switch chartManager.heartRateChartDataSelection {
46+
case 1:
47+
return .day
48+
case 2:
49+
return .weekOfMonth
50+
case 3:
51+
return .month
52+
default:
53+
return .hour
54+
}
55+
}
4456

4557
var header: some View {
4658
VStack(alignment: .leading) {
47-
Text(data().count > 1 ? "Range" : " ")
59+
Text(data().count > 1 ? "Range" : "No Data")
4860
Text({
4961
let max = Int(data().compactMap({ $0.max }).max() ?? 0)
5062
let min = Int(data().compactMap({ $0.min }).min() ?? 0)
@@ -58,7 +70,7 @@ struct HeartChartView: View {
5870
.font(.system(.title, design: .rounded))
5971
.foregroundColor(.primary)
6072
+ Text("BPM")
61-
Text("\(earliestDate.formatted())-\(latestDate.formatted())")
73+
Text("\(earliestDate.formatted(.dateTime.month(.abbreviated).day()))-\(latestDate.formatted(.dateTime.day()))")
6274
}
6375
.fontWeight(.semibold)
6476
}
@@ -72,7 +84,7 @@ struct HeartChartView: View {
7284
Chart(data(), id: \.id) { point in
7385
Plot {
7486
BarMark(
75-
x: .value("Day", point.date, unit: .day),
87+
x: .value("Day", point.date, unit: unit),
7688
yStart: .value("BPM Min", point.min),
7789
yEnd: .value("BPM Max", point.max),
7890
width: .fixed(8)

InfiniLink/Core/HeartView.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct HeartView: View {
3939
return NSLocalizedString("Now", comment: "")
4040
}
4141
func timestamp(for heartPoint: HeartDataPoint?) -> String? {
42-
guard let timeInterval = heartPoint?.timestamp?.timeIntervalSinceNow else { return "No data" }
42+
guard let timeInterval = heartPoint?.timestamp?.timeIntervalSinceNow else { return " " }
4343

4444
return units(for: Int(abs(timeInterval)))
4545
}
@@ -57,7 +57,11 @@ struct HeartView: View {
5757
)
5858
DetailHeaderSubItemView(
5959
title: "Avg",
60-
value: heartRate(for: Double(heartPointValues.compactMap({ Int($0) }).reduce(0, +) / heartPointValues.count)))
60+
value: heartRate(for: {
61+
guard heartPointValues.count > 0 else { return Double(0) }
62+
63+
return Double(heartPointValues.compactMap({ Int($0) }).reduce(0, +) / heartPointValues.count)
64+
}()))
6165
DetailHeaderSubItemView(
6266
title: "Max",
6367
value: heartRate(for: heartPointValues.max() ?? 0)

InfiniLink/Localizable.xcstrings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,9 @@
546546
},
547547
"Next" : {
548548

549+
},
550+
"No Data" : {
551+
549552
},
550553
"No Exercises" : {
551554

InfiniLink/Utils/ChartManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ChartManager: ObservableObject {
1313
let viewContext = PersistenceController.shared.container.viewContext
1414
let bleManager = BLEManager.shared
1515

16-
@AppStorage("heartRateChartDataSelection") private var heartRateChartDataSelection = 0
16+
@AppStorage("heartRateChartDataSelection") var heartRateChartDataSelection = 0
1717

1818
static let shared = ChartManager()
1919

0 commit comments

Comments
 (0)