|
@@ -10,6 +10,7 @@ extension BasalProfileEditor {
|
|
|
|
|
|
|
|
let chartScale = Calendar.current
|
|
let chartScale = Calendar.current
|
|
|
.date(from: DateComponents(year: 2001, month: 01, day: 01, hour: 0, minute: 0, second: 0))
|
|
.date(from: DateComponents(year: 2001, month: 01, day: 01, hour: 0, minute: 0, second: 0))
|
|
|
|
|
+ let tzOffset = TimeZone.current.secondsFromGMT()
|
|
|
|
|
|
|
|
@Environment(\.colorScheme) var colorScheme
|
|
@Environment(\.colorScheme) var colorScheme
|
|
|
@Environment(AppState.self) var appState
|
|
@Environment(AppState.self) var appState
|
|
@@ -28,12 +29,17 @@ extension BasalProfileEditor {
|
|
|
return formatter
|
|
return formatter
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ var now = Date()
|
|
|
var basalScheduleChart: some View {
|
|
var basalScheduleChart: some View {
|
|
|
Chart {
|
|
Chart {
|
|
|
ForEach(state.chartData!, id: \.self) { profile in
|
|
ForEach(state.chartData!, id: \.self) { profile in
|
|
|
|
|
+ let startDate = Calendar.current.startOfDay(for: now)
|
|
|
|
|
+ .addingTimeInterval(profile.startDate.timeIntervalSinceReferenceDate + Double(tzOffset))
|
|
|
|
|
+ let endDate = Calendar.current.startOfDay(for: now)
|
|
|
|
|
+ .addingTimeInterval(profile.endDate!.timeIntervalSinceReferenceDate + Double(tzOffset))
|
|
|
RectangleMark(
|
|
RectangleMark(
|
|
|
- xStart: .value("start", profile.startDate),
|
|
|
|
|
- xEnd: .value("end", profile.endDate!),
|
|
|
|
|
|
|
+ xStart: .value("start", startDate),
|
|
|
|
|
+ xEnd: .value("end", endDate),
|
|
|
yStart: .value("rate-start", profile.amount),
|
|
yStart: .value("rate-start", profile.amount),
|
|
|
yEnd: .value("rate-end", 0)
|
|
yEnd: .value("rate-end", 0)
|
|
|
).foregroundStyle(
|
|
).foregroundStyle(
|
|
@@ -47,10 +53,10 @@ extension BasalProfileEditor {
|
|
|
)
|
|
)
|
|
|
).alignsMarkStylesWithPlotArea()
|
|
).alignsMarkStylesWithPlotArea()
|
|
|
|
|
|
|
|
- LineMark(x: .value("End Date", profile.endDate!), y: .value("Amount", profile.amount))
|
|
|
|
|
|
|
+ LineMark(x: .value("End Date", endDate), y: .value("Amount", profile.amount))
|
|
|
.lineStyle(.init(lineWidth: 1)).foregroundStyle(Color.insulin)
|
|
.lineStyle(.init(lineWidth: 1)).foregroundStyle(Color.insulin)
|
|
|
|
|
|
|
|
- LineMark(x: .value("Start Date", profile.startDate), y: .value("Amount", profile.amount))
|
|
|
|
|
|
|
+ LineMark(x: .value("Start Date", startDate), y: .value("Amount", profile.amount))
|
|
|
.lineStyle(.init(lineWidth: 1)).foregroundStyle(Color.insulin)
|
|
.lineStyle(.init(lineWidth: 1)).foregroundStyle(Color.insulin)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -67,7 +73,8 @@ extension BasalProfileEditor {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
.chartXScale(
|
|
.chartXScale(
|
|
|
- domain: Calendar.current.startOfDay(for: chartScale!) ... Calendar.current.startOfDay(for: chartScale!)
|
|
|
|
|
|
|
+ domain: Calendar.current.startOfDay(for: now) ... Calendar
|
|
|
|
|
+ .current.startOfDay(for: now)
|
|
|
.addingTimeInterval(60 * 60 * 24)
|
|
.addingTimeInterval(60 * 60 * 24)
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|