Skip to content
Open
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
25 changes: 22 additions & 3 deletions LoopFollow/Controllers/Graphs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ import UIKit

import Charts

/// Fill colors for the override and temp-target bars on the BG graph.
///
/// Loop draws overrides green and temp targets purple, while Trio (and other
/// OpenAPS-based algorithms) use the inverse — overrides purple, temp targets
/// green. We follow the active backend's convention so the colors match the
/// looping app the user is running.
enum TreatmentGraphColors {
static var override: NSUIColor {
Storage.shared.device.value == "Loop" ? .systemGreen : .systemPurple
}

static var tempTarget: NSUIColor {
Storage.shared.device.value == "Loop" ? .systemPurple : .systemGreen
}
}

enum GraphDataIndex: Int {
case bg = 0
case prediction = 1
Expand Down Expand Up @@ -201,7 +217,7 @@ class TempTargetRenderer: LineChartRenderer {
}

context.saveGState()
context.setFillColor(NSUIColor.systemPurple.withAlphaComponent(0.5).cgColor)
context.setFillColor(TreatmentGraphColors.tempTarget.withAlphaComponent(0.5).cgColor)
context.fill(rect)
context.restoreGState()
}
Expand Down Expand Up @@ -381,7 +397,7 @@ extension MainViewController {
lineOverride.lineWidth = 0
lineOverride.drawFilledEnabled = true
lineOverride.fillFormatter = OverrideFillFormatter()
lineOverride.fillColor = NSUIColor.systemGreen
lineOverride.fillColor = TreatmentGraphColors.override
lineOverride.fillAlpha = 0.6
lineOverride.drawCirclesEnabled = false
lineOverride.axisDependency = YAxis.AxisDependency.right
Expand Down Expand Up @@ -1453,7 +1469,7 @@ extension MainViewController {
lineOverride.lineWidth = 0
lineOverride.drawFilledEnabled = true
lineOverride.fillFormatter = OverrideFillFormatter()
lineOverride.fillColor = NSUIColor.systemGreen
lineOverride.fillColor = TreatmentGraphColors.override
lineOverride.fillAlpha = 0.6
lineOverride.drawCirclesEnabled = false
lineOverride.axisDependency = YAxis.AxisDependency.right
Expand Down Expand Up @@ -1676,6 +1692,9 @@ extension MainViewController {
var smallChart = BGChartFull.lineData!.dataSets[dataIndex] as! LineChartDataSet
chart.clear()
smallChart.clear()
// Refresh the fill color in case the backend (Loop vs Trio) changed.
chart.fillColor = TreatmentGraphColors.override
smallChart.fillColor = TreatmentGraphColors.override
let thisData = overrideGraphData

var colors = [NSUIColor]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extension MainViewController {
}

Observable.shared.override.value = activeOverrideNote
if Storage.shared.device.value == "Trio" {
if Storage.shared.device.value != "Loop" {
if let note = activeOverrideNote {
infoManager.updateInfoData(type: .override, value: note)
} else {
Expand Down
Loading