Przeglądaj źródła

fix temp basal bar marks displaying only the start of every temp basal

polscm32 2 lat temu
rodzic
commit
3edd9df9e8

+ 15 - 4
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

@@ -405,12 +405,23 @@ extension MainChartView {
                         unit: .second
                     )
                 ).foregroundStyle(Color.clear)
-                ForEach(TempBasals) {
-                    BarMark(
-                        x: .value("Time", $0.timestamp),
-                        y: .value("Rate", $0.rate ?? 0)
+                ///temp basal rects
+                ForEach(TempBasals) { temp in
+                    ///calculate end time of temp basal adding duration to start time
+                    let end = temp.timestamp + (temp.durationMin ?? 0).minutes.timeInterval
+                    let now = Date()
+                    ///ensure that temp basals that are set cannot exceed current date -> i.e. scheduled temp basals are not shown
+                    ///we could display scheduled temp basals with opacity etc... in the future
+                    let maxEndTime = min(end, now)
+                    
+                    RectangleMark(
+                        xStart: .value("start", temp.timestamp),
+                        xEnd: .value("end", maxEndTime),
+                        yStart: .value("rate-start", 0),
+                        yEnd: .value("rate-end", temp.rate ?? 0)
                     ).foregroundStyle(Color.insulin)
                 }
+                ///dashed profile line
                 ForEach(BasalProfiles, id: \.self) { profile in
                     LineMark(
                         x: .value("Start Date", profile.startDate),