Przeglądaj źródła

Add: Now graph line

Jon Fawcett 5 lat temu
rodzic
commit
3fa0d7790f

+ 13 - 0
LoopFollow/Controllers/Graphs.swift

@@ -199,6 +199,10 @@ extension MainViewController {
         ul.lineColor = NSUIColor.systemYellow.withAlphaComponent(0.5)
         BGChart.rightAxis.addLimitLine(ul)
         
+        // Add Now Line
+        createNowLine()
+        startGraphNowTimer()
+        
         // Setup the main graph overall details
         BGChart.xAxis.valueFormatter = ChartXValueFormatter()
         BGChart.xAxis.granularity = 1800
@@ -230,6 +234,15 @@ extension MainViewController {
         
     }
     
+    func createNowLine() {
+        BGChart.xAxis.removeAllLimitLines()
+        let ul = ChartLimitLine()
+        ul.limit = Double(dateTimeUtils.getNowTimeIntervalUTC())
+        ul.lineColor = NSUIColor.systemGray.withAlphaComponent(0.5)
+        ul.lineWidth = 1
+        BGChart.xAxis.addLimitLine(ul)
+    }
+    
     func updateBGGraphSettings() {
         let dataIndex = 0
         let dataIndexPrediction = 1

+ 15 - 0
LoopFollow/Controllers/Timers.swift

@@ -74,6 +74,21 @@ extension MainViewController {
         
     }
     
+    // Runs a 60 second timer when an alarm is snoozed
+    // Prevents the alarm from triggering again while saving the snooze time to settings
+    // End function needs nothing done
+    func startGraphNowTimer(time: TimeInterval = 60) {
+        
+        graphNowTimer = Timer.scheduledTimer(timeInterval: time,
+                                               target: self,
+                                               selector: #selector(MainViewController.graphNowTimerDidEnd(_:)),
+                                               userInfo: nil,
+                                               repeats: true)
+    }
+    
+    @objc func graphNowTimerDidEnd(_ timer:Timer) {
+        createNowLine()
+    }
     
     // Runs a 60 second timer when an alarm is snoozed
     // Prevents the alarm from triggering again while saving the snooze time to settings