77//
88
99import Foundation
10- import LoopKit
1110import SwiftCharts
1211
1312
1413extension ChartPoint {
15- static func pointsForGlucoseRangeSchedule( _ glucoseRangeSchedule: GlucoseRangeSchedule , xAxisValues: [ ChartAxisValue ] ) -> [ ChartPoint ] {
16- let targetRanges = glucoseRangeSchedule. between (
17- start: ChartAxisValueDate . dateFromScalar ( xAxisValues. first!. scalar) ,
18- end: ChartAxisValueDate . dateFromScalar ( xAxisValues. last!. scalar)
19- )
14+ static func pointsForDatedRanges( _ targetRanges: [ DatedRangeContext ] , xAxisValues: [ ChartAxisValue ] ) -> [ ChartPoint ] {
2015 let dateFormatter = DateFormatter ( )
2116
2217 var maxPoints : [ ChartPoint ] = [ ]
@@ -36,8 +31,8 @@ extension ChartPoint {
3631 endDate = ChartAxisValueDate ( date: targetRanges [ index + 1 ] . startDate, formatter: dateFormatter)
3732 }
3833
39- let minValue = ChartAxisValueDouble ( range. value . minValue)
40- let maxValue = ChartAxisValueDouble ( range. value . maxValue)
34+ let minValue = ChartAxisValueDouble ( range. minValue)
35+ let maxValue = ChartAxisValueDouble ( range. maxValue)
4136
4237 maxPoints += [
4338 ChartPoint ( x: startDate, y: maxValue) ,
@@ -53,7 +48,7 @@ extension ChartPoint {
5348 return maxPoints + minPoints. reversed ( )
5449 }
5550
56- static func pointsForGlucoseRangeScheduleOverrideDuration ( _ override: AbsoluteScheduleValue < DoubleRange > , xAxisValues: [ ChartAxisValue ] ) -> [ ChartPoint ] {
51+ static func pointsForDatedRangeOverrideDuration ( _ override: DatedRangeContext , xAxisValues: [ ChartAxisValue ] ) -> [ ChartPoint ] {
5752 let startDate = Date ( )
5853
5954 guard override. endDate. timeIntervalSince ( startDate) > 0 ,
@@ -65,8 +60,8 @@ extension ChartPoint {
6560 let dateFormatter = DateFormatter ( )
6661 let startDateAxisValue = ChartAxisValueDate ( date: startDate, formatter: dateFormatter)
6762 let endDateAxisValue = ChartAxisValueDate ( date: min ( lastXAxisValue. date, override. endDate) , formatter: dateFormatter)
68- let minValue = ChartAxisValueDouble ( override. value . minValue)
69- let maxValue = ChartAxisValueDouble ( override. value . maxValue)
63+ let minValue = ChartAxisValueDouble ( override. minValue)
64+ let maxValue = ChartAxisValueDouble ( override. maxValue)
7065
7166 return [
7267 ChartPoint ( x: startDateAxisValue, y: maxValue) ,
@@ -76,20 +71,20 @@ extension ChartPoint {
7671 ]
7772 }
7873
79- static func pointsForGlucoseRangeScheduleOverride ( _ override: AbsoluteScheduleValue < DoubleRange > , xAxisValues: [ ChartAxisValue ] ) -> [ ChartPoint ] {
74+ static func pointsForDatedRangeOverride ( _ override: DatedRangeContext , xAxisValues: [ ChartAxisValue ] ) -> [ ChartPoint ] {
8075 let startDate = Date ( )
8176
8277 guard override. endDate. timeIntervalSince ( startDate) > 0 ,
8378 let lastXAxisValue = xAxisValues. last as? ChartAxisValueDate
84- else {
85- return [ ]
79+ else {
80+ return [ ]
8681 }
8782
8883 let dateFormatter = DateFormatter ( )
8984 let startDateAxisValue = ChartAxisValueDate ( date: startDate, formatter: dateFormatter)
9085 let endDateAxisValue = ChartAxisValueDate ( date: lastXAxisValue. date, formatter: dateFormatter)
91- let minValue = ChartAxisValueDouble ( override. value . minValue)
92- let maxValue = ChartAxisValueDouble ( override. value . maxValue)
86+ let minValue = ChartAxisValueDouble ( override. minValue)
87+ let maxValue = ChartAxisValueDouble ( override. maxValue)
9388
9489 return [
9590 ChartPoint ( x: startDateAxisValue, y: maxValue) ,
@@ -98,16 +93,5 @@ extension ChartPoint {
9893 ChartPoint ( x: startDateAxisValue, y: minValue)
9994 ]
10095 }
101- }
102-
10396
104- extension ChartPoint : TimelineValue {
105- public var startDate : Date {
106- if let dateValue = x as? ChartAxisValueDate {
107- return dateValue. date
108- } else {
109- return Date . distantPast
110- }
111- }
11297}
113-
0 commit comments