فهرست منبع

Major Updates: dot/bar option for carb and bolus, absorption time, graph scale, prediction line attachment, override top bar,

Jon Fawcett 5 سال پیش
والد
کامیت
e97915fe46

+ 151 - 26
LoopFollow/Controllers/Graphs.swift

@@ -17,6 +17,9 @@ extension MainViewController {
         if chartView == BGChartFull {
             BGChart.moveViewToX(entry.x)
         }
+        if entry.data as? String == "hide"{
+            BGChart.highlightValue(nil, callDelegate: false)
+        }
     }
     
     func chartTranslated(_ chartView: ChartViewBase, dX: CGFloat, dY: CGFloat) {
@@ -104,7 +107,8 @@ extension MainViewController {
         lineBasal.setColor(NSUIColor.systemBlue, alpha: 0.5)
         lineBasal.lineWidth = 0
         lineBasal.drawFilledEnabled = true
-        lineBasal.fillColor = NSUIColor.systemBlue.withAlphaComponent(0.8)
+        lineBasal.fillColor = NSUIColor.systemBlue
+        lineBasal.fillAlpha = 0.5
         lineBasal.drawCirclesEnabled = false
         lineBasal.axisDependency = YAxis.AxisDependency.left
         lineBasal.highlightEnabled = true
@@ -119,13 +123,28 @@ extension MainViewController {
         lineBolus.drawCircleHoleEnabled = false
         lineBolus.setDrawHighlightIndicators(false)
         lineBolus.setColor(NSUIColor.systemBlue, alpha: 1.0)
-        lineBolus.drawCirclesEnabled = true
         lineBolus.lineWidth = 0
-        lineBolus.highlightEnabled = false
         lineBolus.axisDependency = YAxis.AxisDependency.right
         lineBolus.valueFormatter = ChartYDataValueFormatter()
-        lineBolus.drawValuesEnabled = true
         lineBolus.valueTextColor = NSUIColor.label
+        lineBolus.fillFormatter = BolusFillFormatter()
+        lineBolus.fillColor = NSUIColor.systemBlue
+        lineBolus.fillAlpha = 0.6
+        if UserDefaultsRepository.graphBars.value {
+            lineBolus.drawCirclesEnabled = false
+            lineBolus.drawFilledEnabled = true
+        } else {
+            lineBolus.drawCirclesEnabled = true
+            lineBolus.drawFilledEnabled = false
+        }
+        if UserDefaultsRepository.showValues.value {
+            lineBolus.drawValuesEnabled = true
+            lineBolus.highlightEnabled = false
+        } else {
+            lineBolus.drawValuesEnabled = false
+            lineBolus.highlightEnabled = true
+        }
+        
 
         
         // Carbs
@@ -136,13 +155,28 @@ extension MainViewController {
         lineCarbs.drawCircleHoleEnabled = false
         lineCarbs.setDrawHighlightIndicators(false)
         lineCarbs.setColor(NSUIColor.systemBlue, alpha: 1.0)
-        lineCarbs.drawCirclesEnabled = true
         lineCarbs.lineWidth = 0
-        lineCarbs.highlightEnabled = false
         lineCarbs.axisDependency = YAxis.AxisDependency.right
         lineCarbs.valueFormatter = ChartYDataValueFormatter()
-        lineCarbs.drawValuesEnabled = true
         lineCarbs.valueTextColor = NSUIColor.label
+        lineCarbs.fillFormatter = CarbFillFormatter()
+        lineCarbs.fillColor = NSUIColor.systemOrange
+        lineCarbs.fillAlpha = 0.6
+        if UserDefaultsRepository.graphBars.value {
+            lineCarbs.drawCirclesEnabled = false
+            lineCarbs.drawFilledEnabled = true
+        } else {
+            lineCarbs.drawCirclesEnabled = true
+            lineCarbs.drawFilledEnabled = false
+        }
+        if UserDefaultsRepository.showValues.value {
+            lineCarbs.drawValuesEnabled = true
+            lineCarbs.highlightEnabled = false
+        } else {
+            lineCarbs.drawValuesEnabled = false
+            lineCarbs.highlightEnabled = true
+        }
+        
         
         // create Scheduled Basal graph data
         var chartBasalScheduledEntry = [ChartDataEntry]()
@@ -164,7 +198,8 @@ extension MainViewController {
         lineOverride.lineWidth = 0
         lineOverride.drawFilledEnabled = true
         lineOverride.fillFormatter = OverrideFillFormatter()
-        lineOverride.fillColor = NSUIColor.systemTeal.withAlphaComponent(0.8)
+        lineOverride.fillColor = NSUIColor.systemGreen
+        lineOverride.fillAlpha = 0.6
         lineOverride.drawCirclesEnabled = false
         lineOverride.axisDependency = YAxis.AxisDependency.right
         lineOverride.highlightEnabled = true
@@ -183,7 +218,7 @@ extension MainViewController {
         lineBGCheck.highlightEnabled = false
         lineBGCheck.axisDependency = YAxis.AxisDependency.right
         lineBGCheck.valueFormatter = ChartYDataValueFormatter()
-        lineBGCheck.drawValuesEnabled = false
+        lineBGCheck.drawValuesEnabled = UserDefaultsRepository.showValues.value
         
         // Setup the chart data of all lines
         let data = LineChartData()
@@ -231,21 +266,28 @@ extension MainViewController {
         BGChart.leftAxis.enabled = true
         BGChart.leftAxis.labelPosition = YAxis.LabelPosition.insideChart
         BGChart.leftAxis.axisMaximum = maxBasal
-        BGChart.leftAxis.axisMinimum = -1
+        BGChart.leftAxis.axisMinimum = 0
         BGChart.leftAxis.drawGridLinesEnabled = false
+        BGChart.leftAxis.granularityEnabled = true
+        BGChart.leftAxis.granularity = 0.5
+        //BGChart.leftAxis.inverted = true
         
         BGChart.rightAxis.labelTextColor = NSUIColor.label
         BGChart.rightAxis.labelPosition = YAxis.LabelPosition.insideChart
-        BGChart.rightAxis.axisMinimum = Double(UserDefaultsRepository.minBGValue.value)
-        BGChart.rightAxis.axisMaximum = Double(maxBG)
+        BGChart.rightAxis.axisMinimum = 0.0
+        BGChart.rightAxis.axisMaximum = 400.0
         BGChart.rightAxis.gridLineDashLengths = [5.0, 5.0]
+        BGChart.rightAxis.drawGridLinesEnabled = false
         BGChart.rightAxis.valueFormatter = ChartYMMOLValueFormatter()
+        BGChart.rightAxis.granularityEnabled = true
+        BGChart.rightAxis.granularity = 50
         
         BGChart.legend.enabled = false
         BGChart.scaleYEnabled = false
-        BGChart.drawGridBackgroundEnabled = false
-        //BGChart.gridBackgroundColor = NSUIColor.secondarySystemBackground
-      
+        BGChart.drawGridBackgroundEnabled = true
+        BGChart.gridBackgroundColor = NSUIColor.secondarySystemBackground
+        
+        BGChart.highlightValue(nil, callDelegate: false)
         
         BGChart.data = data
         BGChart.setExtraOffsets(left: 10, top: 10, right: 10, bottom: 10)
@@ -281,7 +323,7 @@ extension MainViewController {
             linePrediction.drawCirclesEnabled = false
         }
         
-        BGChart.rightAxis.axisMinimum = Double(UserDefaultsRepository.minBGValue.value)
+        BGChart.rightAxis.axisMinimum = 0
         
         // Clear limit lines so they don't add multiples when changing the settings
         BGChart.rightAxis.removeAllLimitLines()
@@ -354,7 +396,7 @@ extension MainViewController {
             }
         }
         
-        BGChart.rightAxis.axisMaximum = Double(maxBG)
+        BGChart.rightAxis.axisMaximum = 400
         BGChart.setVisibleXRangeMinimum(600)
         BGChart.data?.dataSets[dataIndex].notifyDataSetChanged()
         BGChart.data?.notifyDataChanged()
@@ -461,20 +503,55 @@ extension MainViewController {
     
     func updateBolusGraph() {
         var dataIndex = 3
+        var yTop: Double = 370
+        var yBottom: Double = 345
         BGChart.lineData?.dataSets[dataIndex].clear()
+
         for i in 0..<bolusData.count{
             let formatter = NumberFormatter()
             formatter.minimumFractionDigits = 0
             formatter.maximumFractionDigits = 2
-            formatter.minimumIntegerDigits = 1
+            formatter.minimumIntegerDigits = 0
             var offset = 0
             if UserDefaultsRepository.offsetCarbsBolus.value {
                 offset = 10
             }
-            //let value = ChartDataEntry(x: Double(bolusData[i].date), y: Double(bolusData[i].sgv + offset), data: formatter.string(from: NSNumber(value: bolusData[i].value)))
-            let value = ChartDataEntry(x: Double(bolusData[i].date), y: -5, data: formatter.string(from: NSNumber(value: bolusData[i].value)))
-            BGChart.data?.dataSets[dataIndex].addEntry(value)
+            
+            
+            if UserDefaultsRepository.graphBars.value {
+                var dateSpread = bolusData[i].value * 2 * 60
+                if dateSpread < 60 { dateSpread * 2 }
+                
+                var startDotTime = bolusData[i].date
+                var startInnerDotTime = bolusData[i].date + 1
+                var endInnerDotTime = bolusData[i].date + dateSpread - 1
+                var endDotTime = bolusData[i].date + dateSpread
+                
+                if i < bolusData.count - 1 {
+                    if endDotTime >= bolusData[i + 1].date {
+                        endDotTime = bolusData[i + 1].date - 4
+                        endInnerDotTime = endDotTime - 1
+                        
+                        // Skip this loop if it's too short of a time to add the dots
+                        if endDotTime <= startDotTime { continue }
+                    }
+                }
+                
+                let preStartDot = ChartDataEntry(x: Double(startDotTime), y: yBottom, data: "hide")
+                BGChart.data?.dataSets[dataIndex].addEntry(preStartDot)
+
+                let startDot = ChartDataEntry(x: Double(startInnerDotTime), y: yTop, data: formatter.string(from: NSNumber(value: bolusData[i].value)))
+                BGChart.data?.dataSets[dataIndex].addEntry(startDot)
+                
+                let preEndDot = ChartDataEntry(x: Double(endInnerDotTime), y: yTop, data: formatter.string(from: NSNumber(value: bolusData[i].value)))
+                BGChart.data?.dataSets[dataIndex].addEntry(preEndDot)
 
+                let endDot = ChartDataEntry(x: Double(endDotTime), y: yBottom, data: "hide")
+                BGChart.data?.dataSets[dataIndex].addEntry(endDot)
+            } else {
+                let dot = ChartDataEntry(x: Double(bolusData[i].date), y: Double(bolusData[i].sgv + offset), data: formatter.string(from: NSNumber(value: bolusData[i].value)))
+                BGChart.data?.dataSets[dataIndex].addEntry(dot)
+            }
         }
         
         BGChart.data?.dataSets[dataIndex].notifyDataSetChanged()
@@ -484,6 +561,8 @@ extension MainViewController {
     
     func updateCarbGraph() {
         var dataIndex = 4
+        var yTop: Double = 340
+        var yBottom: Double = 315
         BGChart.lineData?.dataSets[dataIndex].clear()
         for i in 0..<carbData.count{
             let formatter = NumberFormatter()
@@ -494,9 +573,47 @@ extension MainViewController {
             if UserDefaultsRepository.offsetCarbsBolus.value {
                 offset = 30
             }
-           //  let value = ChartDataEntry(x: Double(carbData[i].date), y: Double(carbData[i].sgv + offset), data: formatter.string(from: NSNumber(value: carbData[i].value)))
-            let value = ChartDataEntry(x: Double(carbData[i].date), y: -25, data: formatter.string(from: NSNumber(value: carbData[i].value)))
-            BGChart.data?.dataSets[dataIndex].addEntry(value)
+            
+            var valueString: String = formatter.string(from: NSNumber(value: carbData[i].value))!
+            
+            if carbData[i].absorptionTime > 0 && UserDefaultsRepository.showAbsorption.value {
+                let hours = carbData[i].absorptionTime / 60
+                valueString += " " + String(hours) + "h"
+            }
+            
+            if UserDefaultsRepository.graphBars.value {
+                var dateSpread = carbData[i].value / 10 * 60 * 2
+                
+                var startDotTime = carbData[i].date
+                var startInnerDotTime = carbData[i].date + 1
+                var endInnerDotTime = carbData[i].date + dateSpread - 1
+                var endDotTime = carbData[i].date + dateSpread
+                
+                if i < carbData.count - 1 {
+                    if endDotTime >= carbData[i + 1].date {
+                        endDotTime = carbData[i + 1].date - 4
+                        endInnerDotTime = endDotTime - 1
+                        
+                        // Skip this loop if it's too short of a time to add the dots
+                        if endDotTime <= startDotTime { continue }
+                    }
+                }
+                
+                let preStartDot = ChartDataEntry(x: Double(startDotTime), y: yBottom, data: "hide")
+                BGChart.data?.dataSets[dataIndex].addEntry(preStartDot)
+                let startDot = ChartDataEntry(x: Double(startInnerDotTime), y: yTop, data: valueString)
+                BGChart.data?.dataSets[dataIndex].addEntry(startDot)
+                
+                let endDot = ChartDataEntry(x: Double(endInnerDotTime), y: yTop, data: valueString)
+                BGChart.data?.dataSets[dataIndex].addEntry(endDot)
+                let postEndDot = ChartDataEntry(x: Double(endDotTime), y: yBottom, data: "hide")
+                BGChart.data?.dataSets[dataIndex].addEntry(postEndDot)
+            } else {
+                let dot = ChartDataEntry(x: Double(carbData[i].date), y: Double(carbData[i].sgv + offset), data: valueString)
+                BGChart.data?.dataSets[dataIndex].addEntry(dot)
+            }
+            
+            
 
         }
         
@@ -572,6 +689,8 @@ extension MainViewController {
     
     func updateOverrideGraph() {
         var dataIndex = 6
+        var yTop: Double = 399
+        var yBottom: Double = 375
         var chart = BGChart.lineData!.dataSets[dataIndex] as! LineChartDataSet
         chart.clear()
         
@@ -582,7 +701,10 @@ extension MainViewController {
             let labelText = overrideGraphData[i].reason
             
             // Start Dot
-            let value = ChartDataEntry(x: Double(overrideGraphData[i].date), y: Double(overrideGraphData[i].sgv), data: labelText)
+            // Shift dots 30 seconds to create an empty 0 space between consecutive temps
+            let preStartDot = ChartDataEntry(x: Double(overrideGraphData[i].date), y: yBottom, data: "hide")
+            BGChart.data?.dataSets[dataIndex].addEntry(preStartDot)
+            let value = ChartDataEntry(x: Double(overrideGraphData[i].date + 1), y: yTop, data: labelText)
             BGChart.data?.dataSets[dataIndex].addEntry(value)
             
             if Double(overrideGraphData[i].insulNeedsScaleFactor) == 1.0 {
@@ -594,8 +716,11 @@ extension MainViewController {
             }
             
             // End Dot
-            let endDot = ChartDataEntry(x: Double(overrideGraphData[i].endDate), y: Double(overrideGraphData[i].sgv), data: labelText)
+            let endDot = ChartDataEntry(x: Double(overrideGraphData[i].endDate - 1), y: yTop, data: labelText)
             BGChart.data?.dataSets[dataIndex].addEntry(endDot)
+            // Post end dot
+            let postEndDot = ChartDataEntry(x: Double(overrideGraphData[i].endDate), y: yBottom, data: "hide")
+            BGChart.data?.dataSets[dataIndex].addEntry(postEndDot)
             
             if Double(overrideGraphData[i].insulNeedsScaleFactor) == 1.0 {
                 colors.append(NSUIColor.systemGray.withAlphaComponent(0.0))

+ 43 - 16
LoopFollow/Controllers/NightScout.swift

@@ -32,12 +32,20 @@ extension MainViewController {
     }
     
     //NS Bolus Data  Struct
-    struct bolusCarbGraphStruct: Codable {
+    struct bolusGraphStruct: Codable {
         var value: Double
         var date: TimeInterval
         var sgv: Int
     }
     
+    //NS Bolus Data  Struct
+    struct carbGraphStruct: Codable {
+        var value: Double
+        var date: TimeInterval
+        var sgv: Int
+        var absorptionTime: Int
+    }
+    
     func isStaleData() -> Bool {
         if bgData.count > 0 {
             let now = dateTimeUtils.getNowTimeIntervalUTC()
@@ -480,9 +488,9 @@ extension MainViewController {
                         PredictionLabel.textColor = UIColor.systemPurple
                         if UserDefaultsRepository.downloadPrediction.value && latestLoopTime < lastLoopTime {
                             predictionData.removeAll()
-                            var predictionTime = lastLoopTime + 300
+                            var predictionTime = lastLoopTime
                             let toLoad = Int(UserDefaultsRepository.predictionToLoad.value * 12)
-                            var i = 1
+                            var i = 0
                             while i <= toLoad {
                                 if i < prediction.count {
                                     let prediction = ShareGlucoseData(sgv: prediction[i], date: predictionTime, direction: "flat")
@@ -883,9 +891,9 @@ extension MainViewController {
                 basalScheduleData.append(startDot)
                 var endDate = basal2Day[i].endDate
                 
-                // if it's the last one in the profile or date is greater than now, set it to the last BG dot
+                // if it's the last one in the profile or date is greater than now, set it to 30 minutes from now
                 if i == basal2Day.count - 1  || endDate > dateTimeUtils.getNowTimeIntervalUTC() {
-                    endDate = Double(dateTimeUtils.getNowTimeIntervalUTC())
+                    endDate = Double(dateTimeUtils.getNowTimeIntervalUTC() + (30 * 60))
                 }
 
                 let endDot = basalGraphStruct(basalRate: basal2Day[i].basalRate, date: endDate)
@@ -1219,7 +1227,7 @@ extension MainViewController {
                 
                 if dateTimeStamp < (dateTimeUtils.getNowTimeIntervalUTC() + (60 * 60)) {
                     // Make the dot
-                    let dot = bolusCarbGraphStruct(value: bolus, date: Double(dateTimeStamp), sgv: Int(sgv.sgv))
+                    let dot = bolusGraphStruct(value: bolus, date: Double(dateTimeStamp), sgv: Int(sgv.sgv))
                     bolusData.append(dot)
                 }
             } catch {
@@ -1252,6 +1260,9 @@ extension MainViewController {
             } else {
                 return
             }
+            
+            let absorptionTime = currentEntry?["absorptionTime"] as? Int ?? 0
+            
             // Fix for FreeAPS milliseconds in timestamp
             var strippedZone = String(carbDate.dropLast())
             strippedZone = strippedZone.components(separatedBy: ".")[0]
@@ -1272,7 +1283,7 @@ extension MainViewController {
             
             if dateTimeStamp < (dateTimeUtils.getNowTimeIntervalUTC() + (60 * 60)) {
                 // Make the dot
-                let dot = bolusCarbGraphStruct(value: Double(carbs), date: Double(dateTimeStamp), sgv: Int(sgv.sgv))
+                let dot = carbGraphStruct(value: Double(carbs), date: Double(dateTimeStamp), sgv: Int(sgv.sgv), absorptionTime: absorptionTime)
                 carbData.append(dot)
             }
             
@@ -1360,20 +1371,36 @@ extension MainViewController {
             dateFormatter.locale = Locale(identifier: "en_US")
             dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
             let dateString = dateFormatter.date(from: strippedZone)
-            let dateTimeStamp = dateString!.timeIntervalSince1970
+            var dateTimeStamp = dateString!.timeIntervalSince1970
+            if dateTimeStamp < dateTimeUtils.getTimeInterval24HoursAgo() {
+                dateTimeStamp = dateTimeUtils.getTimeInterval24HoursAgo()
+            }
             
             guard let multipler = currentEntry?["insulinNeedsScaleFactor"] as? Double else { continue }
-            guard let duration = currentEntry?["duration"] as? Double else { continue }
+            var duration: Double = 5.0
+            if let durationType = currentEntry?["durationType"] as? String {
+                duration = dateTimeUtils.getNowTimeIntervalUTC() - dateTimeStamp + (60 * 60)
+            } else {
+                duration = (currentEntry?["duration"] as? Double)!
+                duration = duration * 60
+            }
+            
             guard let enteredBy = currentEntry?["enteredBy"] as? String else { continue }
             guard let reason = currentEntry?["reason"] as? String else { continue }
-            guard let ranges = currentEntry?["correctionRange"] as? [Int] else { continue }
-            guard let low = ranges[0] as? Int else { continue }
-            guard let high = ranges[1] as? Int else { continue }
-            let endDate = dateTimeStamp + (duration * 60)
+            
             var range: [Int] = []
-            range.append(low)
-            range.append(high)
-           
+            if let ranges = currentEntry?["correctionRange"] as? [Int] {
+                if ranges.count == 2 {
+                    guard let low = ranges[0] as? Int else { continue }
+                    guard let high = ranges[1] as? Int else { continue }
+                    range.append(low)
+                    range.append(high)
+                }
+                
+            }
+                        
+            let endDate = dateTimeStamp + (duration)
+
             let dot = DataStructs.overrideStruct(insulNeedsScaleFactor: multipler, date: dateTimeStamp, endDate: endDate, duration: duration, correctionRange: range, enteredBy: enteredBy, reason: reason, sgv: -20)
             overrideGraphData.append(dot)
             

+ 37 - 0
LoopFollow/ViewControllers/GraphSettingsViewController.swift

@@ -55,6 +55,19 @@ class GraphSettingsViewController: FormViewController {
             row3.evaluateHidden()
         }
         
+        if let row4 = form.rowBy(tag: "showValues") as? SwitchRow {
+            row4.hidden = .function(["hide"],  {form in
+                return isHidden
+            })
+            row4.evaluateHidden()
+        }
+        if let row5 = form.rowBy(tag: "showAbsorption") as? SwitchRow {
+            row5.hidden = .function(["hide"],  {form in
+                return isHidden
+            })
+            row5.evaluateHidden()
+        }
+        
     }
     
     private func buildGraphSettings() {
@@ -101,6 +114,30 @@ class GraphSettingsViewController: FormViewController {
                         UserDefaultsRepository.offsetCarbsBolus.value = value
                         
             }
+            <<< SwitchRow("showValues"){ row in
+                row.title = "Show Carb/Bolus Values"
+                row.value = UserDefaultsRepository.showValues.value
+            }.onChange { [weak self] row in
+                        guard let value = row.value else { return }
+                        UserDefaultsRepository.showValues.value = value
+                        
+            }
+                <<< SwitchRow("showAbsorption"){ row in
+                    row.title = "Show Carb Absorption"
+                    row.value = UserDefaultsRepository.showAbsorption.value
+                }.onChange { [weak self] row in
+                            guard let value = row.value else { return }
+                            UserDefaultsRepository.showAbsorption.value = value
+                            
+                }
+            <<< SwitchRow("graphBars"){ row in
+                row.title = "Carb/Bolus Bar Graph"
+                row.value = UserDefaultsRepository.graphBars.value
+            }.onChange { [weak self] row in
+                        guard let value = row.value else { return }
+                        UserDefaultsRepository.graphBars.value = value
+                        
+            }
             <<< StepperRow("predictionToLoad") { row in
                 row.title = "Hours of Prediction"
                 row.cell.stepper.stepValue = 0.25

+ 2 - 2
LoopFollow/ViewControllers/MainViewController.swift

@@ -103,8 +103,8 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
     var basalProfile: [basalProfileStruct] = []
     var basalData: [basalGraphStruct] = []
     var basalScheduleData: [basalGraphStruct] = []
-    var bolusData: [bolusCarbGraphStruct] = []
-    var carbData: [bolusCarbGraphStruct] = []
+    var bolusData: [bolusGraphStruct] = []
+    var carbData: [carbGraphStruct] = []
     var overrideData: [DataStructs.overrideGraphStruct] = []
     var overrideGraphData: [DataStructs.overrideStruct] = []
     var predictionData: [ShareGlucoseData] = []

+ 18 - 2
LoopFollow/helpers/Chart.swift

@@ -11,7 +11,19 @@ import Charts
 
 final class OverrideFillFormatter: IFillFormatter {
     func getFillLinePosition(dataSet: ILineChartDataSet, dataProvider: LineChartDataProvider) -> CGFloat {
-        return -40
+        return 375
+    }
+}
+
+final class CarbFillFormatter: IFillFormatter {
+    func getFillLinePosition(dataSet: ILineChartDataSet, dataProvider: LineChartDataProvider) -> CGFloat {
+        return 315
+    }
+}
+
+final class BolusFillFormatter: IFillFormatter {
+    func getFillLinePosition(dataSet: ILineChartDataSet, dataProvider: LineChartDataProvider) -> CGFloat {
+        return 345
     }
 }
 
@@ -71,6 +83,7 @@ final class ChartYMMOLValueFormatter: IAxisValueFormatter {
 
 
 
+
 class ChartMarker: MarkerView {
     private var text = String()
 
@@ -142,6 +155,7 @@ class PillMarker: MarkerImage {
     }
 
     override func draw(context: CGContext, point: CGPoint) {
+        
         // custom padding around text
         let labelWidth = labelText.size(withAttributes: attrs).width + 10
         // if you modify labelHeigh you will have to tweak baselineOffset in attrs
@@ -150,7 +164,9 @@ class PillMarker: MarkerImage {
         // place pill above the marker, centered along x
         var rectangle = CGRect(x: point.x, y: point.y, width: labelWidth, height: labelHeight)
         rectangle.origin.x -= rectangle.width / 2.0
-        let spacing: CGFloat = 20
+        var spacing: CGFloat = 20
+        if point.y < 200 { spacing = -20 }
+        
         rectangle.origin.y -= rectangle.height + spacing
 
         // rounded rect

+ 3 - 0
LoopFollow/repository/UserDefaults.swift

@@ -40,6 +40,9 @@ class UserDefaultsRepository {
     // Graph Settings
     static let chartScaleX = UserDefaultsValue<Float>(key: "chartScaleX", default: 18.0)
     static let showDots = UserDefaultsValue<Bool>(key: "showDots", default: true)
+    static let showValues = UserDefaultsValue<Bool>(key: "showValues", default: true)
+    static let graphBars = UserDefaultsValue<Bool>(key: "graphBars", default: true)
+    static let showAbsorption = UserDefaultsValue<Bool>(key: "showAbsorption", default: true)
     static let showLines = UserDefaultsValue<Bool>(key: "showLines", default: true)
     static let offsetCarbsBolus = UserDefaultsValue<Bool>(key: "offsetCarbsBolus", default: true)
     static let hoursToLoad = UserDefaultsValue<Int>(key: "hoursToLoad", default: 24)