Skip to content

Commit 51fe214

Browse files
bjorkertmarionbarker
authored andcommitted
Match Trio's override/temp-target colors for non-Loop backends (#668)
1 parent 99cd60e commit 51fe214

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

LoopFollow/Controllers/Graphs.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ import UIKit
77

88
import Charts
99

10+
/// Fill colors for the override and temp-target bars on the BG graph.
11+
///
12+
/// Loop draws overrides green and temp targets purple, while Trio (and other
13+
/// OpenAPS-based algorithms) use the inverse — overrides purple, temp targets
14+
/// green. We follow the active backend's convention so the colors match the
15+
/// looping app the user is running.
16+
enum TreatmentGraphColors {
17+
static var override: NSUIColor {
18+
Storage.shared.device.value == "Loop" ? .systemGreen : .systemPurple
19+
}
20+
21+
static var tempTarget: NSUIColor {
22+
Storage.shared.device.value == "Loop" ? .systemPurple : .systemGreen
23+
}
24+
}
25+
1026
enum GraphDataIndex: Int {
1127
case bg = 0
1228
case prediction = 1
@@ -201,7 +217,7 @@ class TempTargetRenderer: LineChartRenderer {
201217
}
202218

203219
context.saveGState()
204-
context.setFillColor(NSUIColor.systemPurple.withAlphaComponent(0.5).cgColor)
220+
context.setFillColor(TreatmentGraphColors.tempTarget.withAlphaComponent(0.5).cgColor)
205221
context.fill(rect)
206222
context.restoreGState()
207223
}
@@ -381,7 +397,7 @@ extension MainViewController {
381397
lineOverride.lineWidth = 0
382398
lineOverride.drawFilledEnabled = true
383399
lineOverride.fillFormatter = OverrideFillFormatter()
384-
lineOverride.fillColor = NSUIColor.systemGreen
400+
lineOverride.fillColor = TreatmentGraphColors.override
385401
lineOverride.fillAlpha = 0.6
386402
lineOverride.drawCirclesEnabled = false
387403
lineOverride.axisDependency = YAxis.AxisDependency.right
@@ -1460,7 +1476,7 @@ extension MainViewController {
14601476
lineOverride.lineWidth = 0
14611477
lineOverride.drawFilledEnabled = true
14621478
lineOverride.fillFormatter = OverrideFillFormatter()
1463-
lineOverride.fillColor = NSUIColor.systemGreen
1479+
lineOverride.fillColor = TreatmentGraphColors.override
14641480
lineOverride.fillAlpha = 0.6
14651481
lineOverride.drawCirclesEnabled = false
14661482
lineOverride.axisDependency = YAxis.AxisDependency.right
@@ -1683,6 +1699,9 @@ extension MainViewController {
16831699
var smallChart = BGChartFull.lineData!.dataSets[dataIndex] as! LineChartDataSet
16841700
chart.clear()
16851701
smallChart.clear()
1702+
// Refresh the fill color in case the backend (Loop vs Trio) changed.
1703+
chart.fillColor = TreatmentGraphColors.override
1704+
smallChart.fillColor = TreatmentGraphColors.override
16861705
let thisData = overrideGraphData
16871706

16881707
var colors = [NSUIColor]()

LoopFollow/Controllers/Nightscout/Treatments/Overrides.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ extension MainViewController {
8080
}
8181

8282
Observable.shared.override.value = activeOverrideNote
83-
if Storage.shared.device.value == "Trio" {
83+
if Storage.shared.device.value != "Loop" {
8484
if let note = activeOverrideNote {
8585
infoManager.updateInfoData(type: .override, value: note)
8686
} else {

0 commit comments

Comments
 (0)