Przeglądaj źródła

Modularize Main Chart -> WiP

polscm32 1 rok temu
rodzic
commit
4e8613485b

+ 16 - 0
FreeAPS.xcodeproj/project.pbxproj

@@ -247,6 +247,10 @@
 		581516A92BCEEDF800BF67D7 /* NSPredicates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 581516A82BCEEDF800BF67D7 /* NSPredicates.swift */; };
 		581AC4392BE22ED10038760C /* JSONConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 581AC4382BE22ED10038760C /* JSONConverter.swift */; };
 		58237D9E2BCF0A6B00A47A79 /* PopupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58237D9D2BCF0A6B00A47A79 /* PopupView.swift */; };
+		582DF9752C8CDB92001F516D /* GlucoseChartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582DF9742C8CDB92001F516D /* GlucoseChartView.swift */; };
+		582DF9772C8CDBE7001F516D /* InsulinView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582DF9762C8CDBE7001F516D /* InsulinView.swift */; };
+		582DF9792C8CE1E5001F516D /* MainChartHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582DF9782C8CE1E5001F516D /* MainChartHelper.swift */; };
+		582DF97B2C8CE209001F516D /* CarbView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582DF97A2C8CE209001F516D /* CarbView.swift */; };
 		582FAE432C05102C00D1C13F /* CoreDataError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582FAE422C05102C00D1C13F /* CoreDataError.swift */; };
 		583684062BD178DB00070A60 /* GlucoseStored+helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583684052BD178DB00070A60 /* GlucoseStored+helper.swift */; };
 		583684082BD195A700070A60 /* Determination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 583684072BD195A700070A60 /* Determination.swift */; };
@@ -890,6 +894,10 @@
 		581516A82BCEEDF800BF67D7 /* NSPredicates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSPredicates.swift; sourceTree = "<group>"; };
 		581AC4382BE22ED10038760C /* JSONConverter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONConverter.swift; sourceTree = "<group>"; };
 		58237D9D2BCF0A6B00A47A79 /* PopupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopupView.swift; sourceTree = "<group>"; };
+		582DF9742C8CDB92001F516D /* GlucoseChartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlucoseChartView.swift; sourceTree = "<group>"; };
+		582DF9762C8CDBE7001F516D /* InsulinView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsulinView.swift; sourceTree = "<group>"; };
+		582DF9782C8CE1E5001F516D /* MainChartHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainChartHelper.swift; sourceTree = "<group>"; };
+		582DF97A2C8CE209001F516D /* CarbView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarbView.swift; sourceTree = "<group>"; };
 		582FAE422C05102C00D1C13F /* CoreDataError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataError.swift; sourceTree = "<group>"; };
 		583684052BD178DB00070A60 /* GlucoseStored+helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GlucoseStored+helper.swift"; sourceTree = "<group>"; };
 		583684072BD195A700070A60 /* Determination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Determination.swift; sourceTree = "<group>"; };
@@ -1760,6 +1768,9 @@
 			isa = PBXGroup;
 			children = (
 				BD3CC0712B0B89D50013189E /* MainChartView.swift */,
+				582DF9742C8CDB92001F516D /* GlucoseChartView.swift */,
+				582DF9762C8CDBE7001F516D /* InsulinView.swift */,
+				582DF97A2C8CE209001F516D /* CarbView.swift */,
 			);
 			path = Chart;
 			sourceTree = "<group>";
@@ -1948,6 +1959,7 @@
 				DD1DB7CB2BECCA1F0048B367 /* BuildDetails.swift */,
 				DD6B7CB12C7B6F0800B75029 /* Rounding.swift */,
 				58CE8B882C8C6B62007A6A10 /* GradientStops.swift */,
+				582DF9782C8CE1E5001F516D /* MainChartHelper.swift */,
 			);
 			path = Helpers;
 			sourceTree = "<group>";
@@ -3265,6 +3277,7 @@
 				DD57C4C02C4C7103001A5B28 /* TempTargetsSlider+CoreDataClass.swift in Sources */,
 				DD57C4C12C4C7103001A5B28 /* TempTargetsSlider+CoreDataProperties.swift in Sources */,
 				DD57C4C22C4C7103001A5B28 /* Forecast+CoreDataClass.swift in Sources */,
+				582DF9752C8CDB92001F516D /* GlucoseChartView.swift in Sources */,
 				DD57C4C32C4C7103001A5B28 /* Forecast+CoreDataProperties.swift in Sources */,
 				DD57C4C42C4C7103001A5B28 /* BolusStored+CoreDataClass.swift in Sources */,
 				DD1745302C55AE5300211FAC /* TargetBehaviorProvider.swift in Sources */,
@@ -3293,6 +3306,7 @@
 				CE48C86628CA6B48007C0598 /* OmniPodManagerExtensions.swift in Sources */,
 				CEB434E728B9053300B70274 /* LoopUIColorPalette+Default.swift in Sources */,
 				19F95FF329F10FBC00314DDC /* StatDataFlow.swift in Sources */,
+				582DF97B2C8CE209001F516D /* CarbView.swift in Sources */,
 				3811DE2225C9D48300A708ED /* MainProvider.swift in Sources */,
 				3811DE0C25C9D32F00A708ED /* BaseProvider.swift in Sources */,
 				CE95BF5A2BA62E4A00DC3DE3 /* PluginSource.swift in Sources */,
@@ -3399,6 +3413,7 @@
 				BD4064D12C4ED26900582F43 /* CoreDataObserver.swift in Sources */,
 				38E44536274E411700EC9A94 /* Disk.swift in Sources */,
 				19A910362A24D6D700C8951B /* DateFilter.swift in Sources */,
+				582DF9792C8CE1E5001F516D /* MainChartHelper.swift in Sources */,
 				E06B911A275B5EEA003C04B6 /* Array+Extension.swift in Sources */,
 				38EA0600262091870064E39B /* BolusProgressViewStyle.swift in Sources */,
 				389ECDFE2601061500D86C4F /* View+Snapshot.swift in Sources */,
@@ -3436,6 +3451,7 @@
 				BDF34EBE2C0A31D100D51995 /* CustomNotification.swift in Sources */,
 				BDC2EA472C3045AD00E5BBD0 /* Override.swift in Sources */,
 				1BBB001DAD60F3B8CEA4B1C7 /* ISFEditorStateModel.swift in Sources */,
+				582DF9772C8CDBE7001F516D /* InsulinView.swift in Sources */,
 				F816826028DB441800054060 /* BluetoothTransmitter.swift in Sources */,
 				DD68889D2C386E17006E3C44 /* NightscoutExercise.swift in Sources */,
 				5864E8592C42CFAE00294306 /* DeterminationStorage.swift in Sources */,

+ 65 - 0
FreeAPS/Sources/Helpers/MainChartHelper.swift

@@ -0,0 +1,65 @@
+import Foundation
+
+enum MainChartHelper {
+    /// calculates the glucose value thats the nearest to parameter 'time'
+    static func timeToNearestGlucose(glucoseValues: [GlucoseStored], time: TimeInterval) -> GlucoseStored? {
+        guard !glucoseValues.isEmpty else {
+            return nil
+        }
+
+        var low = 0
+        var high = glucoseValues.count - 1
+        var closestGlucose: GlucoseStored?
+
+        // binary search to find next glucose
+        while low <= high {
+            let mid = low + (high - low) / 2
+            let midTime = glucoseValues[mid].date?.timeIntervalSince1970 ?? 0
+
+            if midTime == time {
+                return glucoseValues[mid]
+            } else if midTime < time {
+                low = mid + 1
+            } else {
+                high = mid - 1
+            }
+
+            // update if necessary
+            if closestGlucose == nil || abs(midTime - time) < abs(closestGlucose!.date?.timeIntervalSince1970 ?? 0 - time) {
+                closestGlucose = glucoseValues[mid]
+            }
+        }
+
+        return closestGlucose
+    }
+
+    enum Config {
+        static let bolusSize: CGFloat = 5
+        static let bolusScale: CGFloat = 1
+        static let carbsSize: CGFloat = 5
+        static let carbsScale: CGFloat = 0.3
+        static let fpuSize: CGFloat = 10
+        static let maxGlucose = 270
+        static let minGlucose = 45
+    }
+
+    static var bolusFormatter: NumberFormatter {
+        let formatter = NumberFormatter()
+        formatter.numberStyle = .decimal
+        formatter.minimumIntegerDigits = 0
+        formatter.maximumFractionDigits = 2
+        formatter.decimalSeparator = "."
+        return formatter
+    }
+
+    static var carbsFormatter: NumberFormatter {
+        let formatter = NumberFormatter()
+        formatter.numberStyle = .decimal
+        formatter.maximumFractionDigits = 0
+        return formatter
+    }
+
+    static func bolusOffset(units: GlucoseUnits) -> Decimal {
+        units == .mgdL ? 30 : 1.66
+    }
+}

+ 4 - 1
FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift

@@ -139,6 +139,9 @@ extension Bolus {
                     group.addTask {
                         await self.setupSettings()
                     }
+                    group.addTask {
+                        self.registerObservers()
+                    }
 
                     if self.waitForSuggestionInitial {
                         group.addTask {
@@ -202,7 +205,7 @@ extension Bolus {
             }
         }
 
-        private func setupObservers() {
+        private func registerObservers() {
             broadcaster.register(DeterminationObserver.self, observer: self)
             broadcaster.register(BolusFailureObserver.self, observer: self)
         }

+ 61 - 0
FreeAPS/Sources/Modules/Home/View/Chart/CarbView.swift

@@ -0,0 +1,61 @@
+import Charts
+import Foundation
+import SwiftUI
+
+struct CarbView: ChartContent {
+    let glucoseData: [GlucoseStored]
+    let units: GlucoseUnits
+    let carbData: [CarbEntryStored]
+    let fpuData: [CarbEntryStored]
+    let minValue: Decimal
+
+    var body: some ChartContent {
+        drawCarbs()
+        drawFpus()
+    }
+
+    private func drawCarbs() -> some ChartContent {
+        ForEach(carbData) { carb in
+            let carbAmount = carb.carbs
+            let carbDate = carb.date ?? Date()
+
+            if let glucose = MainChartHelper.timeToNearestGlucose(
+                glucoseValues: glucoseData,
+                time: carbDate.timeIntervalSince1970
+            )?.glucose {
+                let yPosition = (units == .mgdL ? Decimal(glucose) : Decimal(glucose).asMmolL) - MainChartHelper
+                    .bolusOffset(units: units)
+                let size = (MainChartHelper.Config.carbsSize + CGFloat(carbAmount) * MainChartHelper.Config.carbsScale)
+                let limitedSize = size > 30 ? 30 : size
+
+                PointMark(
+                    x: .value("Time", carbDate, unit: .second),
+                    y: .value("Value", yPosition)
+                )
+                .symbol {
+                    Image(systemName: "arrowtriangle.down.fill").font(.system(size: limitedSize)).foregroundStyle(Color.orange)
+                        .rotationEffect(.degrees(180))
+                }
+                .annotation(position: .bottom) {
+                    Text(MainChartHelper.carbsFormatter.string(from: carbAmount as NSNumber)!).font(.caption2)
+                        .foregroundStyle(Color.primary)
+                }
+            }
+        }
+    }
+
+    private func drawFpus() -> some ChartContent {
+        ForEach(fpuData, id: \.id) { fpu in
+            let fpuAmount = fpu.carbs
+            let size = (MainChartHelper.Config.fpuSize + CGFloat(fpuAmount) * MainChartHelper.Config.carbsScale) * 1.8
+            let yPosition = minValue
+
+            PointMark(
+                x: .value("Time", fpu.date ?? Date(), unit: .second),
+                y: .value("Value", yPosition)
+            )
+            .symbolSize(size)
+            .foregroundStyle(Color.brown)
+        }
+    }
+}

+ 53 - 0
FreeAPS/Sources/Modules/Home/View/Chart/GlucoseChartView.swift

@@ -0,0 +1,53 @@
+import Charts
+import Foundation
+import SwiftUI
+
+struct GlucoseChartView: ChartContent {
+    let glucoseData: [GlucoseStored]
+    let manualGlucoseData: [GlucoseStored]
+    let units: GlucoseUnits
+    let highGlucose: Decimal
+    let lowGlucose: Decimal
+    let smooth: Bool
+    let gradientStops: [Gradient.Stop]
+
+    var body: some ChartContent {
+        drawGlucoseChart()
+    }
+
+    private func drawGlucoseChart() -> some ChartContent {
+        ForEach(glucoseData) { item in
+            let glucoseToDisplay = units == .mgdL ? Decimal(item.glucose) : Decimal(item.glucose).asMmolL
+
+            if smooth {
+                LineMark(x: .value("Time", item.date ?? Date()), y: .value("Value", glucoseToDisplay))
+                    .foregroundStyle(
+                        LinearGradient(
+                            gradient: Gradient(stops: gradientStops),
+                            startPoint: .bottom,
+                            endPoint: .top
+                        )
+                    )
+                    .symbol(.circle)
+                    .symbolSize(34)
+            } else {
+                if glucoseToDisplay > highGlucose {
+                    PointMark(
+                        x: .value("Time", item.date ?? Date(), unit: .second),
+                        y: .value("Value", glucoseToDisplay)
+                    ).foregroundStyle(Color.orange.gradient).symbolSize(20)
+                } else if glucoseToDisplay < lowGlucose {
+                    PointMark(
+                        x: .value("Time", item.date ?? Date(), unit: .second),
+                        y: .value("Value", glucoseToDisplay)
+                    ).foregroundStyle(Color.red.gradient).symbolSize(20)
+                } else {
+                    PointMark(
+                        x: .value("Time", item.date ?? Date(), unit: .second),
+                        y: .value("Value", glucoseToDisplay)
+                    ).foregroundStyle(Color.green.gradient).symbolSize(20)
+                }
+            }
+        }
+    }
+}

+ 43 - 0
FreeAPS/Sources/Modules/Home/View/Chart/InsulinView.swift

@@ -0,0 +1,43 @@
+import Charts
+import Foundation
+import SwiftUI
+
+struct InsulinView: ChartContent {
+    let glucoseData: [GlucoseStored]
+    let insulinData: [PumpEventStored]
+    let units: GlucoseUnits
+
+    var body: some ChartContent {
+        drawBoluses()
+    }
+
+    private func drawBoluses() -> some ChartContent {
+        ForEach(insulinData) { insulin in
+            let amount = insulin.bolus?.amount ?? 0 as NSDecimalNumber
+            let bolusDate = insulin.timestamp ?? Date()
+
+            if amount != 0, let glucose = MainChartHelper.timeToNearestGlucose(
+                glucoseValues: glucoseData,
+                time: bolusDate.timeIntervalSince1970
+            )?.glucose {
+                let yPosition = (units == .mgdL ? Decimal(glucose) : Decimal(glucose).asMmolL) + MainChartHelper
+                    .bolusOffset(units: units)
+                let size = (MainChartHelper.Config.bolusSize + CGFloat(truncating: amount) * MainChartHelper.Config.bolusScale) *
+                    1.8
+
+                PointMark(
+                    x: .value("Time", bolusDate, unit: .second),
+                    y: .value("Value", yPosition)
+                )
+                .symbol {
+                    Image(systemName: "arrowtriangle.down.fill").font(.system(size: size)).foregroundStyle(Color.insulin)
+                }
+                .annotation(position: .top) {
+                    Text(MainChartHelper.bolusFormatter.string(from: amount) ?? "")
+                        .font(.caption2)
+                        .foregroundStyle(Color.primary)
+                }
+            }
+        }
+    }
+}

+ 27 - 173
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

@@ -25,16 +25,6 @@ private struct ChartTempTarget: Hashable {
 }
 
 struct MainChartView: View {
-    private enum Config {
-        static let bolusSize: CGFloat = 5
-        static let bolusScale: CGFloat = 1
-        static let carbsSize: CGFloat = 5
-        static let carbsScale: CGFloat = 0.3
-        static let fpuSize: CGFloat = 10
-        static let maxGlucose = 270
-        static let minGlucose = 45
-    }
-
     var geo: GeometryProxy
     @Binding var units: GlucoseUnits
     @Binding var announcement: [Announcement]
@@ -76,34 +66,10 @@ struct MainChartView: View {
     @Environment(\.colorScheme) var colorScheme
     @Environment(\.calendar) var calendar
 
-    private var bolusFormatter: NumberFormatter {
-        let formatter = NumberFormatter()
-        formatter.numberStyle = .decimal
-        formatter.minimumIntegerDigits = 0
-        formatter.maximumFractionDigits = 2
-        formatter.decimalSeparator = "."
-        return formatter
-    }
-
-    private var carbsFormatter: NumberFormatter {
-        let formatter = NumberFormatter()
-        formatter.numberStyle = .decimal
-        formatter.maximumFractionDigits = 0
-        return formatter
-    }
-
     private var upperLimit: Decimal {
         units == .mgdL ? 400 : 22.2
     }
 
-    private var defaultBolusPosition: Int {
-        units == .mgdL ? 120 : 7
-    }
-
-    private var bolusOffset: Decimal {
-        units == .mgdL ? 30 : 1.66
-    }
-
     private var selectedGlucose: GlucoseStored? {
         if let selection = selection {
             let lowerBound = selection.addingTimeInterval(-150)
@@ -252,14 +218,35 @@ extension MainChartView {
                 drawStartRuleMark()
                 drawEndRuleMark()
                 drawCurrentTimeMarker()
-                drawFpus()
-                drawBoluses()
                 drawTempTargets()
                 drawActiveOverrides()
                 drawOverrideRunStored()
-                drawGlucose(dummy: false)
+
+                GlucoseChartView(
+                    glucoseData: state.glucoseFromPersistence,
+                    manualGlucoseData: state.manualGlucoseFromPersistence,
+                    units: state.units,
+                    highGlucose: state.highGlucose,
+                    lowGlucose: state.lowGlucose,
+                    smooth: state.smooth,
+                    gradientStops: state.gradientStops
+                )
+
+                InsulinView(
+                    glucoseData: state.glucoseFromPersistence,
+                    insulinData: state.insulinFromPersistence,
+                    units: state.units
+                )
+
+                CarbView(
+                    glucoseData: state.glucoseFromPersistence,
+                    units: state.units,
+                    carbData: state.carbsFromPersistence,
+                    fpuData: state.fpusFromPersistence,
+                    minValue: minValue
+                )
+
                 drawManualGlucose()
-                drawCarbs()
 
                 if state.forecastDisplayType == .lines {
                     drawForecastsLines()
@@ -355,7 +342,7 @@ extension MainChartView {
                 if let selectedIOBValue, let iob = selectedIOBValue.iob {
                     HStack {
                         Image(systemName: "syringe.fill").frame(width: 15)
-                        Text(bolusFormatter.string(from: iob) ?? "")
+                        Text(MainChartHelper.bolusFormatter.string(from: iob) ?? "")
                             .bold()
                             + Text(NSLocalizedString(" U", comment: "Insulin unit"))
                     }.foregroundStyle(Color.insulin).font(.body)
@@ -364,7 +351,7 @@ extension MainChartView {
                 if let selectedCOBValue {
                     HStack {
                         Image(systemName: "fork.knife").frame(width: 15)
-                        Text(carbsFormatter.string(from: selectedCOBValue.cob as NSNumber) ?? "")
+                        Text(MainChartHelper.carbsFormatter.string(from: selectedCOBValue.cob as NSNumber) ?? "")
                             .bold()
                             + Text(NSLocalizedString(" g", comment: "gram of carbs"))
                     }.foregroundStyle(Color.orange).font(.body)
@@ -486,107 +473,6 @@ extension MainChartView {
 // MARK: - Calculations
 
 extension MainChartView {
-    private func drawBoluses() -> some ChartContent {
-        ForEach(state.insulinFromPersistence) { insulin in
-            let amount = insulin.bolus?.amount ?? 0 as NSDecimalNumber
-            let bolusDate = insulin.timestamp ?? Date()
-
-            if amount != 0, let glucose = timeToNearestGlucose(time: bolusDate.timeIntervalSince1970)?.glucose {
-                let yPosition = (units == .mgdL ? Decimal(glucose) : Decimal(glucose).asMmolL) + bolusOffset
-                let size = (Config.bolusSize + CGFloat(truncating: amount) * Config.bolusScale) * 1.8
-
-                PointMark(
-                    x: .value("Time", bolusDate, unit: .second),
-                    y: .value("Value", yPosition)
-                )
-                .symbol {
-                    Image(systemName: "arrowtriangle.down.fill").font(.system(size: size)).foregroundStyle(Color.insulin)
-                }
-                .annotation(position: .top) {
-                    Text(bolusFormatter.string(from: amount) ?? "")
-                        .font(.caption2)
-                        .foregroundStyle(Color.primary)
-                }
-            }
-        }
-    }
-
-    private func drawCarbs() -> some ChartContent {
-        /// carbs
-        ForEach(state.carbsFromPersistence) { carb in
-            let carbAmount = carb.carbs
-            let carbDate = carb.date ?? Date()
-
-            if let glucose = timeToNearestGlucose(time: carbDate.timeIntervalSince1970)?.glucose {
-                let yPosition = (units == .mgdL ? Decimal(glucose) : Decimal(glucose).asMmolL) - bolusOffset
-                let size = (Config.carbsSize + CGFloat(carbAmount) * Config.carbsScale)
-                let limitedSize = size > 30 ? 30 : size
-
-                PointMark(
-                    x: .value("Time", carbDate, unit: .second),
-                    y: .value("Value", yPosition)
-                )
-                .symbol {
-                    Image(systemName: "arrowtriangle.down.fill").font(.system(size: limitedSize)).foregroundStyle(Color.orange)
-                        .rotationEffect(.degrees(180))
-                }
-                .annotation(position: .bottom) {
-                    Text(carbsFormatter.string(from: carbAmount as NSNumber)!).font(.caption2)
-                        .foregroundStyle(Color.primary)
-                }
-            }
-        }
-    }
-
-    private func drawFpus() -> some ChartContent {
-        /// fpus
-        ForEach(state.fpusFromPersistence, id: \.id) { fpu in
-            let fpuAmount = fpu.carbs
-            let size = (Config.fpuSize + CGFloat(fpuAmount) * Config.carbsScale) * 1.8
-            let yPosition = minValue
-
-            PointMark(
-                x: .value("Time", fpu.date ?? Date(), unit: .second),
-                y: .value("Value", yPosition)
-            )
-            .symbolSize(size)
-            .foregroundStyle(Color.brown)
-        }
-    }
-
-    private func drawGlucose(dummy _: Bool) -> some ChartContent {
-        /// glucose point mark
-        /// filtering for high and low bounds in settings
-        ForEach(state.glucoseFromPersistence) { item in
-            let glucoseToDisplay = units == .mgdL ? Decimal(item.glucose) : Decimal(item.glucose).asMmolL
-
-            if smooth {
-                LineMark(x: .value("Time", item.date ?? Date()), y: .value("Value", glucoseToDisplay))
-                    .foregroundStyle(
-                        .linearGradient(stops: state.gradientStops, startPoint: .bottom, endPoint: .top)
-                    )
-                    .symbol(.circle).symbolSize(34)
-            } else {
-                if glucoseToDisplay > highGlucose {
-                    PointMark(
-                        x: .value("Time", item.date ?? Date(), unit: .second),
-                        y: .value("Value", glucoseToDisplay)
-                    ).foregroundStyle(Color.orange.gradient).symbolSize(20)
-                } else if glucoseToDisplay < lowGlucose {
-                    PointMark(
-                        x: .value("Time", item.date ?? Date(), unit: .second),
-                        y: .value("Value", glucoseToDisplay)
-                    ).foregroundStyle(Color.red.gradient).symbolSize(20)
-                } else {
-                    PointMark(
-                        x: .value("Time", item.date ?? Date(), unit: .second),
-                        y: .value("Value", glucoseToDisplay)
-                    ).foregroundStyle(Color.green.gradient).symbolSize(20)
-                }
-            }
-        }
-    }
-
     private func timeForIndex(_ index: Int32) -> Date {
         let currentTime = Date()
         let timeInterval = TimeInterval(index * 300)
@@ -920,38 +806,6 @@ extension MainChartView {
         }
     }
 
-    /// calculates the glucose value thats the nearest to parameter 'time'
-    private func timeToNearestGlucose(time: TimeInterval) -> GlucoseStored? {
-        guard !state.glucoseFromPersistence.isEmpty else {
-            return nil
-        }
-
-        var low = 0
-        var high = state.glucoseFromPersistence.count - 1
-        var closestGlucose: GlucoseStored?
-
-        // binary search to find next glucose
-        while low <= high {
-            let mid = low + (high - low) / 2
-            let midTime = state.glucoseFromPersistence[mid].date?.timeIntervalSince1970 ?? 0
-
-            if midTime == time {
-                return state.glucoseFromPersistence[mid]
-            } else if midTime < time {
-                low = mid + 1
-            } else {
-                high = mid - 1
-            }
-
-            // update if necessary
-            if closestGlucose == nil || abs(midTime - time) < abs(closestGlucose!.date?.timeIntervalSince1970 ?? 0 - time) {
-                closestGlucose = state.glucoseFromPersistence[mid]
-            }
-        }
-
-        return closestGlucose
-    }
-
     private func fullWidth(viewWidth: CGFloat) -> CGFloat {
         viewWidth * CGFloat(hours) / CGFloat(min(max(screenHours, 2), 24))
     }