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
5 changes: 4 additions & 1 deletion LoopFollow/Controllers/Graphs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,10 @@ extension MainViewController {
}

// Move to current reading everytime new readings load
BGChart.moveViewToAnimated(xValue: dateTimeUtils.getNowTimeIntervalUTC() - (BGChart.visibleXRange * 0.7), yValue: 0.0, axis: .right, duration: 1, easingOption: .easeInBack)
// Check if auto-scrolling should be performed
if autoScrollPauseUntil == nil || Date() > autoScrollPauseUntil! {
BGChart.moveViewToAnimated(xValue: dateTimeUtils.getNowTimeIntervalUTC() - (BGChart.visibleXRange * 0.7), yValue: 0.0, axis: .right, duration: 1, easingOption: .easeInBack)
}
}

func updatePredictionGraph(color: UIColor? = nil) {
Expand Down
13 changes: 11 additions & 2 deletions LoopFollow/ViewControllers/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
// This is a temporary safeguard until the issue with multiple calls to speakBG is fixed.
var lastSpeechTime: Date?

var autoScrollPauseUntil: Date? = nil

override func viewDidLoad() {
super.viewDidLoad()

Expand Down Expand Up @@ -824,6 +826,13 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele

}


// User has scrolled the chart
func chartTranslated(_ chartView: ChartViewBase, dX: CGFloat, dY: CGFloat) {
let isViewingLatestData = abs(BGChart.highestVisibleX - BGChart.chartXMax) < 0.001
if isViewingLatestData {
autoScrollPauseUntil = nil // User is back at the latest data, allow auto-scrolling
} else {
autoScrollPauseUntil = Date().addingTimeInterval(5 * 60) // User is viewing historical data, pause auto-scrolling
}
}
}