From ebc67b37b3a012c827d98478414ec471304a4e6e Mon Sep 17 00:00:00 2001 From: aug0211 <659845+aug0211@users.noreply.github.com> Date: Sat, 9 May 2026 18:55:21 -0400 Subject: [PATCH] Bug fix: carb dots overlapping SMB dots on the chart - Restores pre-PR #305 behavior; no other dot positioning changes - Carb dots entered alongside an SMB were rendering at the same Y position as the SMB triangle, visually overlapping - The carb-vs-bolus collision logic was supposed to lift the carb dot above the bolus to BG+70, but only checked for Boluses (not SMB) - Regression comes from PR #305 (SMB display differentiated from boluses), which split SMBs into their own smbData array. - After the split, findNearestBolusbyTime in processNSCarbs no longer saw SMBs as "nearby treatments," so carb-near-SMB fell through to the default BG+20 offset: the same Y as the SMB itself. - processNSCarbs now also looks up smbData. - A carb within 300s of either a bolus OR SMB lifts to BG+70; otherwise BG+20. --- LoopFollow/Controllers/Nightscout/Treatments/Carbs.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/LoopFollow/Controllers/Nightscout/Treatments/Carbs.swift b/LoopFollow/Controllers/Nightscout/Treatments/Carbs.swift index 5d75adb2d..3d07e82b7 100644 --- a/LoopFollow/Controllers/Nightscout/Treatments/Carbs.swift +++ b/LoopFollow/Controllers/Nightscout/Treatments/Carbs.swift @@ -10,6 +10,7 @@ extension MainViewController { carbData.removeAll() var lastFoundIndex = 0 var lastFoundBolus = 0 + var lastFoundSmb = 0 for currentEntry in entries.reversed() { var carbDate: String @@ -35,7 +36,10 @@ extension MainViewController { let bolusTime = findNearestBolusbyTime(timeWithin: 300, needle: dateTimeStamp, haystack: bolusData, startingIndex: lastFoundBolus) lastFoundBolus = bolusTime.foundIndex - offset = bolusTime.offset ? 70 : 20 + let smbTime = findNearestBolusbyTime(timeWithin: 300, needle: dateTimeStamp, haystack: smbData, startingIndex: lastFoundSmb) + lastFoundSmb = smbTime.foundIndex + + offset = (bolusTime.offset || smbTime.offset) ? 70 : 20 } if dateTimeStamp < (dateTimeUtils.getNowTimeIntervalUTC() + (3600 * Storage.shared.predictionToLoad.value)) {