Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions LoopFollow/Charts/BGChartModel.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -157,6 +157,7 @@ final class BGChartModel: ObservableObject {
@Published var now: Date = .init()
@Published var diaMarkers: [Date] = []
@Published var midnightMarkers: [Date] = []
@Published var priorDayTimeMarkers: [Date] = []
@Published var thirtyMinMark: Date? = nil
@Published var ninetyMinMark: Date? = nil

Expand DownExpand Up@@ -596,6 +597,17 @@ final class BGChartModel: ObservableObject {
}
return cal
}()

// Mark the current local time on each prior day. Calendar arithmetic
// preserves the displayed time of day across daylight-saving changes.
var priorDayTimes: [Date] = []
var priorDayTime = calendar.date(byAdding: .day, value: -1, to: currentNow)
while let marker = priorDayTime, marker > domainStart {
priorDayTimes.append(marker)
priorDayTime = calendar.date(byAdding: .day, value: -1, to: marker)
}
priorDayTimeMarkers = priorDayTimes

var cursor = calendar.startOfDay(for: domainStart)
while cursor <= domainEnd {
if cursor >= domainStart {
Expand Down
10 changes: 10 additions & 0 deletions LoopFollow/Charts/BGChartView.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -1095,6 +1095,7 @@ private struct BGChartCanvas: View, Equatable {
if showTreatments {
treatmentMarks
}
priorDayTimeRuleMarks
if !isSmall {
ruleMarks
} else if model.showMidnight {
Expand DownExpand Up@@ -1462,6 +1463,15 @@ private struct BGChartCanvas: View, Equatable {
}
}

@ChartContentBuilder
private var priorDayTimeRuleMarks: some ChartContent {
ForEach(model.priorDayTimeMarkers.filter { $0 >= windowStart && $0 <= windowEnd }, id: \.self) { d in
RuleMark(x: .value("same time on prior day", d))
.lineStyle(StrokeStyle(lineWidth: 1, dash: isSmall ? [2, 2] : [2, 5]))
.foregroundStyle(Color.orange.opacity(isSmall ? 1 : 0.5))
}
}

@ChartContentBuilder
private var ruleMarks: some ChartContent {
RuleMark(y: .value("low", model.lowLine))
Expand Down
Loading