@@ -254,6 +254,102 @@ extension MainViewController {
254254 lineNote. axisDependency = YAxis . AxisDependency. right
255255 lineNote. valueFormatter = ChartYDataValueFormatter ( )
256256 lineNote. drawValuesEnabled = false
257+
258+ // Setup COB Prediction line details
259+ let COBpredictionChartEntry = [ ChartDataEntry] ( )
260+ let COBlinePrediction = LineChartDataSet ( entries: COBpredictionChartEntry, label: " " )
261+ COBlinePrediction . circleRadius = CGFloat ( globalVariables. dotBG)
262+ COBlinePrediction . circleColors = [ NSUIColor . systemPurple]
263+ COBlinePrediction . colors = [ NSUIColor . systemPurple]
264+ COBlinePrediction . drawCircleHoleEnabled = false
265+ COBlinePrediction . axisDependency = YAxis . AxisDependency. right
266+ COBlinePrediction . highlightEnabled = true
267+ COBlinePrediction . drawValuesEnabled = false
268+
269+ if UserDefaultsRepository . showLines. value {
270+ COBlinePrediction . lineWidth = 2
271+ } else {
272+ COBlinePrediction . lineWidth = 0
273+ }
274+ if UserDefaultsRepository . showDots. value {
275+ COBlinePrediction . drawCirclesEnabled = true
276+ } else {
277+ COBlinePrediction . drawCirclesEnabled = false
278+ }
279+ COBlinePrediction . setDrawHighlightIndicators ( false )
280+ COBlinePrediction . valueFont. withSize ( 50 )
281+
282+ // Setup IOB Prediction line details
283+ let IOBpredictionChartEntry = [ ChartDataEntry] ( )
284+ let IOBlinePrediction = LineChartDataSet ( entries: IOBpredictionChartEntry, label: " " )
285+ IOBlinePrediction . circleRadius = CGFloat ( globalVariables. dotBG)
286+ IOBlinePrediction . circleColors = [ NSUIColor . systemPurple]
287+ IOBlinePrediction . colors = [ NSUIColor . systemPurple]
288+ IOBlinePrediction . drawCircleHoleEnabled = false
289+ IOBlinePrediction . axisDependency = YAxis . AxisDependency. right
290+ IOBlinePrediction . highlightEnabled = true
291+ IOBlinePrediction . drawValuesEnabled = false
292+
293+ if UserDefaultsRepository . showLines. value {
294+ IOBlinePrediction . lineWidth = 2
295+ } else {
296+ IOBlinePrediction . lineWidth = 0
297+ }
298+ if UserDefaultsRepository . showDots. value {
299+ IOBlinePrediction . drawCirclesEnabled = true
300+ } else {
301+ IOBlinePrediction . drawCirclesEnabled = false
302+ }
303+ IOBlinePrediction . setDrawHighlightIndicators ( false )
304+ IOBlinePrediction . valueFont. withSize ( 50 )
305+
306+ // Setup UAM Prediction line details
307+ let UAMpredictionChartEntry = [ ChartDataEntry] ( )
308+ let UAMlinePrediction = LineChartDataSet ( entries: UAMpredictionChartEntry, label: " " )
309+ UAMlinePrediction . circleRadius = CGFloat ( globalVariables. dotBG)
310+ UAMlinePrediction . circleColors = [ NSUIColor . systemPurple]
311+ UAMlinePrediction . colors = [ NSUIColor . systemPurple]
312+ UAMlinePrediction . drawCircleHoleEnabled = false
313+ UAMlinePrediction . axisDependency = YAxis . AxisDependency. right
314+ UAMlinePrediction . highlightEnabled = true
315+ UAMlinePrediction . drawValuesEnabled = false
316+
317+ if UserDefaultsRepository . showLines. value {
318+ UAMlinePrediction . lineWidth = 2
319+ } else {
320+ UAMlinePrediction . lineWidth = 0
321+ }
322+ if UserDefaultsRepository . showDots. value {
323+ UAMlinePrediction . drawCirclesEnabled = true
324+ } else {
325+ UAMlinePrediction . drawCirclesEnabled = false
326+ }
327+ linePrediction. setDrawHighlightIndicators ( false )
328+ linePrediction. valueFont. withSize ( 50 )
329+
330+ // Setup ZT Prediction line details
331+ let ZTpredictionChartEntry = [ ChartDataEntry] ( )
332+ let ZTlinePrediction = LineChartDataSet ( entries: ZTpredictionChartEntry, label: " " )
333+ ZTlinePrediction . circleRadius = CGFloat ( globalVariables. dotBG)
334+ ZTlinePrediction . circleColors = [ NSUIColor . systemPurple]
335+ ZTlinePrediction . colors = [ NSUIColor . systemPurple]
336+ ZTlinePrediction . drawCircleHoleEnabled = false
337+ ZTlinePrediction . axisDependency = YAxis . AxisDependency. right
338+ ZTlinePrediction . highlightEnabled = true
339+ ZTlinePrediction . drawValuesEnabled = false
340+
341+ if UserDefaultsRepository . showLines. value {
342+ ZTlinePrediction . lineWidth = 2
343+ } else {
344+ ZTlinePrediction . lineWidth = 0
345+ }
346+ if UserDefaultsRepository . showDots. value {
347+ ZTlinePrediction . drawCirclesEnabled = true
348+ } else {
349+ ZTlinePrediction . drawCirclesEnabled = false
350+ }
351+ ZTlinePrediction . setDrawHighlightIndicators ( false )
352+ ZTlinePrediction . valueFont. withSize ( 50 )
257353
258354 // Setup the chart data of all lines
259355 let data = LineChartData ( )
@@ -270,7 +366,11 @@ extension MainViewController {
270366 data. append ( lineResume) // Dataset 9
271367 data. append ( lineSensor) // Dataset 10
272368 data. append ( lineNote) // Dataset 11
273-
369+ data. append ( ZTlinePrediction) // Dataset 12
370+ data. append ( IOBlinePrediction) // Dataset 13
371+ data. append ( COBlinePrediction) // Dataset 14
372+ data. append ( UAMlinePrediction) // Dataset 15
373+
274374 data. setValueFont ( UIFont . systemFont ( ofSize: 12 ) )
275375
276376 // Add marker popups for bolus and carbs
@@ -1137,6 +1237,58 @@ extension MainViewController {
11371237 lineNote. axisDependency = YAxis . AxisDependency. right
11381238 lineNote. valueFormatter = ChartYDataValueFormatter ( )
11391239 lineNote. drawValuesEnabled = false
1240+
1241+ // Setup COB Prediction line details
1242+ var COBpredictionChartEntry = [ ChartDataEntry] ( )
1243+ let COBlinePrediction = LineChartDataSet ( entries: COBpredictionChartEntry, label: " " )
1244+ COBlinePrediction . drawCirclesEnabled = false
1245+ COBlinePrediction . setColor ( NSUIColor . systemPurple)
1246+ COBlinePrediction . highlightEnabled = true
1247+ COBlinePrediction . drawHorizontalHighlightIndicatorEnabled = false
1248+ COBlinePrediction . drawVerticalHighlightIndicatorEnabled = false
1249+ COBlinePrediction . highlightColor = NSUIColor . label
1250+ COBlinePrediction . drawValuesEnabled = false
1251+ COBlinePrediction . lineWidth = 1.5
1252+ COBlinePrediction . axisDependency = YAxis . AxisDependency. right
1253+
1254+ // Setup IOB Prediction line details
1255+ var IOBpredictionChartEntry = [ ChartDataEntry] ( )
1256+ let IOBlinePrediction = LineChartDataSet ( entries: IOBpredictionChartEntry, label: " " )
1257+ IOBlinePrediction . drawCirclesEnabled = false
1258+ IOBlinePrediction . setColor ( NSUIColor . systemPurple)
1259+ IOBlinePrediction . highlightEnabled = true
1260+ IOBlinePrediction . drawHorizontalHighlightIndicatorEnabled = false
1261+ IOBlinePrediction . drawVerticalHighlightIndicatorEnabled = false
1262+ IOBlinePrediction . highlightColor = NSUIColor . label
1263+ IOBlinePrediction . drawValuesEnabled = false
1264+ IOBlinePrediction . lineWidth = 1.5
1265+ IOBlinePrediction . axisDependency = YAxis . AxisDependency. right
1266+
1267+ // Setup UAM Prediction line details
1268+ var UAMpredictionChartEntry = [ ChartDataEntry] ( )
1269+ let UAMlinePrediction = LineChartDataSet ( entries: UAMpredictionChartEntry, label: " " )
1270+ UAMlinePrediction . drawCirclesEnabled = false
1271+ UAMlinePrediction . setColor ( NSUIColor . systemPurple)
1272+ UAMlinePrediction . highlightEnabled = true
1273+ UAMlinePrediction . drawHorizontalHighlightIndicatorEnabled = false
1274+ UAMlinePrediction . drawVerticalHighlightIndicatorEnabled = false
1275+ UAMlinePrediction . highlightColor = NSUIColor . label
1276+ UAMlinePrediction . drawValuesEnabled = false
1277+ UAMlinePrediction . lineWidth = 1.5
1278+ UAMlinePrediction . axisDependency = YAxis . AxisDependency. right
1279+
1280+ // Setup ZT Prediction line details
1281+ var ZTpredictionChartEntry = [ ChartDataEntry] ( )
1282+ let ZTlinePrediction = LineChartDataSet ( entries: ZTpredictionChartEntry, label: " " )
1283+ ZTlinePrediction . drawCirclesEnabled = false
1284+ ZTlinePrediction . setColor ( NSUIColor . systemPurple)
1285+ ZTlinePrediction . highlightEnabled = true
1286+ ZTlinePrediction . drawHorizontalHighlightIndicatorEnabled = false
1287+ ZTlinePrediction . drawVerticalHighlightIndicatorEnabled = false
1288+ ZTlinePrediction . highlightColor = NSUIColor . label
1289+ ZTlinePrediction . drawValuesEnabled = false
1290+ ZTlinePrediction . lineWidth = 1.5
1291+ ZTlinePrediction . axisDependency = YAxis . AxisDependency. right
11401292
11411293 // Setup the chart data of all lines
11421294 let data = LineChartData ( )
@@ -1152,7 +1304,11 @@ extension MainViewController {
11521304 data. append ( lineResume) // Dataset 9
11531305 data. append ( lineSensor) // Dataset 10
11541306 data. append ( lineNote) // Dataset 11
1155-
1307+ data. append ( ZTlinePrediction) // Dataset 12
1308+ data. append ( IOBlinePrediction) // Dataset 13
1309+ data. append ( COBlinePrediction) // Dataset 14
1310+ data. append ( UAMlinePrediction) // Dataset 15
1311+
11561312 BGChartFull . highlightPerDragEnabled = true
11571313 BGChartFull . leftAxis. enabled = false
11581314 BGChartFull . leftAxis. axisMaximum = maxBasal
@@ -1237,21 +1393,86 @@ extension MainViewController {
12371393 }
12381394 }
12391395
1240- func formatPillText( line1: String , time: TimeInterval ) -> String {
1396+ func formatPillText( line1: String , time: TimeInterval , line2 : String ? = nil ) -> String {
12411397 let dateFormatter = DateFormatter ( )
1242- //let timezoneOffset = TimeZone.current.secondsFromGMT()
1243- //let epochTimezoneOffset = value + Double(timezoneOffset)
12441398 if dateTimeUtils. is24Hour ( ) {
12451399 dateFormatter. setLocalizedDateFormatFromTemplate ( " HH:mm " )
12461400 } else {
12471401 dateFormatter. setLocalizedDateFormatFromTemplate ( " hh:mm " )
12481402 }
12491403
1250- //let date = Date(timeIntervalSince1970: epochTimezoneOffset)
12511404 let date = Date ( timeIntervalSince1970: time)
12521405 let formattedDate = dateFormatter. string ( from: date)
1253-
1254- return line1 + " \r \n " + formattedDate
1406+
1407+ if let line2 = line2 {
1408+ return line1 + " \r \n " + line2 + " \r \n " + formattedDate
1409+ } else {
1410+ return line1 + " \r \n " + formattedDate
1411+ }
12551412 }
12561413
1414+ func updatePredictionGraphGeneric(
1415+ dataIndex: Int ,
1416+ predictionData: [ ShareGlucoseData ] ,
1417+ chartLabel: String ,
1418+ color: UIColor
1419+ ) {
1420+ let mainChart = BGChart . lineData!. dataSets [ dataIndex] as! LineChartDataSet
1421+ let smallChart = BGChartFull . lineData!. dataSets [ dataIndex] as! LineChartDataSet
1422+ mainChart. clear ( )
1423+ smallChart. clear ( )
1424+
1425+ var colors = [ NSUIColor] ( )
1426+ let maxBGOffset : Float = 20
1427+
1428+ for i in 0 ..< predictionData. count {
1429+ let predictionVal = Double ( predictionData [ i] . sgv)
1430+ if Float ( predictionVal) > topBG - maxBGOffset {
1431+ topBG = Float ( predictionVal) + maxBGOffset
1432+ }
1433+
1434+ if i == 0 {
1435+ if UserDefaultsRepository . showDots. value {
1436+ colors. append ( ( color) . withAlphaComponent ( 0.0 ) )
1437+ } else {
1438+ colors. append ( ( color) . withAlphaComponent ( 1.0 ) )
1439+ }
1440+ } else {
1441+ colors. append ( color)
1442+ }
1443+
1444+ let value = ChartDataEntry (
1445+ x: predictionData [ i] . date,
1446+ y: predictionVal,
1447+ data: formatPillText (
1448+ line1: chartLabel,
1449+ time: predictionData [ i] . date,
1450+ line2: bgUnits. toDisplayUnits ( String ( predictionVal) )
1451+ )
1452+ )
1453+ mainChart. addEntry ( value)
1454+ smallChart. addEntry ( value)
1455+ }
1456+
1457+ smallChart. circleColors. removeAll ( )
1458+ smallChart. colors. removeAll ( )
1459+ mainChart. colors. removeAll ( )
1460+ mainChart. circleColors. removeAll ( )
1461+ if colors. count > 0 {
1462+ for color in colors {
1463+ mainChart. addColor ( color)
1464+ mainChart. circleColors. append ( color)
1465+ smallChart. addColor ( color)
1466+ smallChart. circleColors. append ( color)
1467+ }
1468+ }
1469+
1470+ BGChart . rightAxis. axisMaximum = Double ( topBG)
1471+ BGChart . data? . dataSets [ dataIndex] . notifyDataSetChanged ( )
1472+ BGChart . data? . notifyDataChanged ( )
1473+ BGChart . notifyDataSetChanged ( )
1474+ BGChartFull . data? . dataSets [ dataIndex] . notifyDataSetChanged ( )
1475+ BGChartFull . data? . notifyDataChanged ( )
1476+ BGChartFull . notifyDataSetChanged ( )
1477+ }
12571478}
0 commit comments