Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions LoopFollow/Controllers/Graphs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ extension MainViewController {
let maxBGOffset: Float = 50

var colors = [NSUIColor]()

topBG = UserDefaultsRepository.minBGScale.value
for i in 0..<entries.count{
if Float(entries[i].sgv) > topBG - maxBGOffset {
topBG = Float(entries[i].sgv) + maxBGOffset
Expand Down Expand Up @@ -605,12 +607,12 @@ extension MainViewController {

if UserDefaultsRepository.debugLog.value { writeDebugLog(value: "Total Colors: " + mainChart.colors.count.description) }

BGChart.rightAxis.axisMaximum = Double(topBG)
BGChart.rightAxis.axisMaximum = Double(calculateMaxBgGraphValue())
BGChart.setVisibleXRangeMinimum(600)
BGChart.data?.dataSets[dataIndex].notifyDataSetChanged()
BGChart.data?.notifyDataChanged()
BGChart.notifyDataSetChanged()
BGChartFull.rightAxis.axisMaximum = Double(topBG)
BGChartFull.rightAxis.axisMaximum = Double(calculateMaxBgGraphValue())
BGChartFull.data?.dataSets[dataIndex].notifyDataSetChanged()
BGChartFull.data?.notifyDataChanged()
BGChartFull.notifyDataSetChanged()
Expand Down Expand Up @@ -642,10 +644,12 @@ extension MainViewController {

var colors = [NSUIColor]()
let maxBGOffset: Float = 20

topPredictionBG = UserDefaultsRepository.minBGScale.value
for i in 0..<predictionData.count {
var predictionVal = Double(predictionData[i].sgv)
if Float(predictionVal) > topBG - maxBGOffset {
topBG = Float(predictionVal) + maxBGOffset
if Float(predictionVal) > topPredictionBG - maxBGOffset {
topPredictionBG = Float(predictionVal) + maxBGOffset
}

if i == 0 {
Expand Down Expand Up @@ -679,7 +683,7 @@ extension MainViewController {
smallChart.circleColors.append(colors[i])
}
}
BGChart.rightAxis.axisMaximum = Double(topBG)
BGChart.rightAxis.axisMaximum = Double(calculateMaxBgGraphValue())
BGChart.data?.dataSets[dataIndex].notifyDataSetChanged()
BGChart.data?.notifyDataChanged()
BGChart.notifyDataSetChanged()
Expand Down Expand Up @@ -1332,8 +1336,8 @@ extension MainViewController {

func updateOverrideGraph() {
var dataIndex = 6
var yTop: Double = Double(topBG - 5)
var yBottom: Double = Double(topBG - 25)
var yTop: Double = Double(calculateMaxBgGraphValue() - 5)
var yBottom: Double = Double(calculateMaxBgGraphValue() - 25)
var chart = BGChart.lineData!.dataSets[dataIndex] as! LineChartDataSet
var smallChart = BGChartFull.lineData!.dataSets[dataIndex] as! LineChartDataSet
chart.clear()
Expand Down Expand Up @@ -1427,8 +1431,8 @@ extension MainViewController {

for i in 0..<predictionData.count {
let predictionVal = Double(predictionData[i].sgv)
if Float(predictionVal) > topBG - maxBGOffset {
topBG = Float(predictionVal) + maxBGOffset
if Float(predictionVal) > topPredictionBG - maxBGOffset {
topPredictionBG = Float(predictionVal) + maxBGOffset
}

if i == 0 {
Expand Down Expand Up @@ -1467,7 +1471,7 @@ extension MainViewController {
}
}

BGChart.rightAxis.axisMaximum = Double(topBG)
BGChart.rightAxis.axisMaximum = Double(calculateMaxBgGraphValue())
BGChart.data?.dataSets[dataIndex].notifyDataSetChanged()
BGChart.data?.notifyDataChanged()
BGChart.notifyDataSetChanged()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension MainViewController {

var predictioncolor = UIColor.systemGray
PredictionLabel.textColor = predictioncolor

topPredictionBG = UserDefaultsRepository.minBGScale.value
if let enactdata = lastLoopRecord["enacted"] as? [String:AnyObject],
let predbgdata = enactdata["predBGs"] as? [String: AnyObject] {
let predictionTypes: [(type: String, colorName: String, dataIndex: Int)] = [
Expand Down
2 changes: 1 addition & 1 deletion LoopFollow/Controllers/Nightscout/Treatments/Carbs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension MainViewController {
lastFoundIndex = sgv.foundIndex

var offset = -50
if sgv.sgv < Double(topBG - 100) {
if sgv.sgv < Double(calculateMaxBgGraphValue() - 100) {
let bolusTime = findNearestBolusbyTime(timeWithin: 300, needle: dateTimeStamp, haystack: bolusData, startingIndex: lastFoundBolus)
lastFoundBolus = bolusTime.foundIndex

Expand Down
Loading