@@ -73,23 +73,31 @@ class StatusChartsManager {
7373
7474 var glucoseValues : [ GlucoseValue ] = [ ] {
7575 didSet {
76- glucosePoints = glucoseValues. map ( {
76+ // TODO: Use the preferred unit
77+ let unit = HKUnit . milligramsPerDeciliterUnit ( )
78+ let unitString = unit. glucoseUnitDisplayString
79+
80+ glucosePoints = glucoseValues. map {
7781 return ChartPoint (
7882 x: ChartAxisValueDate ( date: $0. startDate, formatter: dateFormatter) ,
79- y: ChartAxisValueDouble ( $0. quantity. doubleValueForUnit ( HKUnit . milligramsPerDeciliterUnit ( ) ) )
83+ y: ChartAxisValueDoubleUnit ( $0. quantity. doubleValueForUnit ( unit ) , unitString : unitString )
8084 )
81- } )
85+ }
8286 }
8387 }
8488
8589 var predictedGlucoseValues : [ GlucoseValue ] = [ ] {
8690 didSet {
87- predictedGlucosePoints = predictedGlucoseValues. map ( {
91+ // TODO: Use the preferred unit
92+ let unit = HKUnit . milligramsPerDeciliterUnit ( )
93+ let unitString = unit. glucoseUnitDisplayString
94+
95+ predictedGlucosePoints = predictedGlucoseValues. map {
8896 return ChartPoint (
8997 x: ChartAxisValueDate ( date: $0. startDate, formatter: dateFormatter) ,
90- y: ChartAxisValueDouble ( $0. quantity. doubleValueForUnit ( HKUnit . milligramsPerDeciliterUnit ( ) ) , formatter: integerFormatter)
98+ y: ChartAxisValueDoubleUnit ( $0. quantity. doubleValueForUnit ( unit ) , unitString : unitString , formatter: integerFormatter)
9199 )
92- } )
100+ }
93101 }
94102 }
95103
@@ -98,18 +106,21 @@ class StatusChartsManager {
98106 IOBPoints = IOBValues . map {
99107 return ChartPoint (
100108 x: ChartAxisValueDate ( date: $0. startDate, formatter: dateFormatter) ,
101- y: ChartAxisValueDouble ( $0. value, formatter: decimalFormatter)
109+ y: ChartAxisValueDoubleUnit ( $0. value, unitString : " U " , formatter: decimalFormatter)
102110 )
103111 }
104112 }
105113 }
106114
107115 var COBValues : [ CarbValue ] = [ ] {
108116 didSet {
117+ let unit = HKUnit . gramUnit ( )
118+ let unitString = unit. unitString
119+
109120 COBPoints = COBValues . map {
110121 ChartPoint (
111122 x: ChartAxisValueDate ( date: $0. startDate, formatter: dateFormatter) ,
112- y: ChartAxisValueDouble ( $0. quantity. doubleValueForUnit ( HKUnit . gramUnit ( ) ) , formatter: integerFormatter)
123+ y: ChartAxisValueDoubleUnit ( $0. quantity. doubleValueForUnit ( unit ) , unitString : unitString , formatter: integerFormatter)
113124 )
114125 }
115126 }
@@ -122,7 +133,7 @@ class StatusChartsManager {
122133 let startX = ChartAxisValueDate ( date: entry. startDate, formatter: dateFormatter)
123134 let endX = ChartAxisValueDate ( date: entry. endDate, formatter: dateFormatter)
124135 let zero = ChartAxisValueInt ( 0 )
125- let value = ChartAxisValueDoubleLog ( actualDouble: entry. value, formatter: decimalFormatter)
136+ let value = ChartAxisValueDoubleLog ( actualDouble: entry. value, unitString : " U/hour " , formatter: decimalFormatter)
126137
127138 let newPoints = [
128139 ChartPoint ( x: startX, y: zero) ,
@@ -214,6 +225,14 @@ class StatusChartsManager {
214225
215226 private var doseChart : Chart ?
216227
228+ private var glucoseChartCache : ChartPointsTouchHighlightLayerViewCache ?
229+
230+ private var IOBChartCache : ChartPointsTouchHighlightLayerViewCache ?
231+
232+ private var COBChartCache : ChartPointsTouchHighlightLayerViewCache ?
233+
234+ private var doseChartCache : ChartPointsTouchHighlightLayerViewCache ?
235+
217236 // MARK: - Generators
218237
219238 func glucoseChartWithFrame( frame: CGRect ) -> Chart ? {
@@ -275,7 +294,7 @@ class StatusChartsManager {
275294 prediction = ChartPointsScatterCirclesLayer ( xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: predictedGlucosePoints, displayDelay: 0 , itemSize: CGSize ( width: 2 , height: 2 ) , itemFillColor: UIColor . glucoseTintColor. colorWithAlphaComponent ( 0.75 ) )
276295 }
277296
278- let highlightLayer = StatusChartHighlightLayer (
297+ glucoseChartCache = ChartPointsTouchHighlightLayerViewCache (
279298 xAxis: xAxis,
280299 yAxis: yAxis,
281300 innerFrame: innerFrame,
@@ -292,7 +311,7 @@ class StatusChartsManager {
292311 targetOverrideDurationLayer,
293312 xAxis,
294313 yAxis,
295- highlightLayer,
314+ glucoseChartCache ? . highlightLayer,
296315 prediction,
297316 circles
298317 ]
@@ -356,7 +375,7 @@ class StatusChartsManager {
356375 return v
357376 } )
358377
359- let highlightLayer = StatusChartHighlightLayer (
378+ IOBChartCache = ChartPointsTouchHighlightLayerViewCache (
360379 xAxis: xAxis,
361380 yAxis: yAxis,
362381 innerFrame: innerFrame,
@@ -371,7 +390,7 @@ class StatusChartsManager {
371390 xAxis,
372391 yAxis,
373392 zeroGuidelineLayer,
374- highlightLayer,
393+ IOBChartCache ? . highlightLayer,
375394 IOBArea,
376395 IOBLine,
377396 ]
@@ -425,7 +444,7 @@ class StatusChartsManager {
425444 let gridLayer = ChartGuideLinesLayer ( xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, axis: . XAndY, settings: guideLinesLayerSettings, onlyVisibleX: true , onlyVisibleY: false )
426445
427446
428- let highlightLayer = StatusChartHighlightLayer (
447+ COBChartCache = ChartPointsTouchHighlightLayerViewCache (
429448 xAxis: xAxis,
430449 yAxis: yAxis,
431450 innerFrame: innerFrame,
@@ -439,7 +458,7 @@ class StatusChartsManager {
439458 gridLayer,
440459 xAxis,
441460 yAxis,
442- highlightLayer,
461+ COBChartCache ? . highlightLayer,
443462 COBArea,
444463 COBLine
445464 ]
@@ -492,7 +511,7 @@ class StatusChartsManager {
492511 return v
493512 } )
494513
495- let highlightLayer = StatusChartHighlightLayer (
514+ doseChartCache = ChartPointsTouchHighlightLayerViewCache (
496515 xAxis: xAxis,
497516 yAxis: yAxis,
498517 innerFrame: innerFrame,
@@ -507,7 +526,7 @@ class StatusChartsManager {
507526 xAxis,
508527 yAxis,
509528 zeroGuidelineLayer,
510- highlightLayer,
529+ doseChartCache ? . highlightLayer,
511530 doseArea,
512531 doseLine
513532 ]
0 commit comments