From 1bede2b67e1a6a09fdfbd475b4290f1b5e3a35dd Mon Sep 17 00:00:00 2001 From: dm61 Date: Sat, 28 Jul 2018 22:14:03 -0600 Subject: [PATCH] Add suspend threshold line to glucose chart --- .../StatusViewController.swift | 2 ++ Loop Status Extension/UIColor+Widget.swift | 2 ++ Loop/Extensions/ChartColorPalette+Loop.swift | 2 +- Loop/Extensions/UIColor+Loop.swift | 2 ++ .../PredictionTableViewController.swift | 1 + .../StatusTableViewController.swift | 1 + LoopUI/Managers/StatusChartsManager.swift | 18 ++++++++++++++++++ LoopUI/Models/ChartColorPalette.swift | 4 +++- 8 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Loop Status Extension/StatusViewController.swift b/Loop Status Extension/StatusViewController.swift index 68d1856898..7a2bc2592c 100644 --- a/Loop Status Extension/StatusViewController.swift +++ b/Loop Status Extension/StatusViewController.swift @@ -36,6 +36,7 @@ class StatusViewController: UIViewController, NCWidgetProviding { axisLine: .axisLineColor, axisLabel: .axisLabelColor, grid: .gridColor, + threshold: .thresholdLineColor, glucoseTint: .glucoseTintColor, doseTint: .doseTintColor ), @@ -295,6 +296,7 @@ class StatusViewController: UIViewController, NCWidgetProviding { } self.charts.targetGlucoseSchedule = defaults.loopSettings?.glucoseTargetRangeSchedule + self.charts.suspendThresholdValue = nil // do not add SuspendThreshold line to the widget self.charts.prerender() self.glucoseChartContentView.reloadChart() diff --git a/Loop Status Extension/UIColor+Widget.swift b/Loop Status Extension/UIColor+Widget.swift index e97e76504e..984b2fab68 100644 --- a/Loop Status Extension/UIColor+Widget.swift +++ b/Loop Status Extension/UIColor+Widget.swift @@ -25,4 +25,6 @@ extension UIColor { @nonobjc static let pumpStatusNormal = UIColor(red: 100 / 255, green: 101 / 255, blue: 105 / 255, alpha: 1) @nonobjc static let subtitleLabelColor = UIColor(white: 0, alpha: 0.4) + + @nonobjc static let thresholdLineColor = UIColor.HIGRedColor() } diff --git a/Loop/Extensions/ChartColorPalette+Loop.swift b/Loop/Extensions/ChartColorPalette+Loop.swift index 382fb7b69f..3cc5c5861d 100644 --- a/Loop/Extensions/ChartColorPalette+Loop.swift +++ b/Loop/Extensions/ChartColorPalette+Loop.swift @@ -11,6 +11,6 @@ import LoopUI extension ChartColorPalette { static var `default`: ChartColorPalette { - return ChartColorPalette(axisLine: .axisLineColor, axisLabel: .axisLabelColor, grid: .gridColor, glucoseTint: .glucoseTintColor, doseTint: .doseTintColor) + return ChartColorPalette(axisLine: .axisLineColor, axisLabel: .axisLabelColor, grid: .gridColor, threshold: .thresholdLineColor, glucoseTint: .glucoseTintColor, doseTint: .doseTintColor) } } diff --git a/Loop/Extensions/UIColor+Loop.swift b/Loop/Extensions/UIColor+Loop.swift index 1301fc72f9..bda2969988 100644 --- a/Loop/Extensions/UIColor+Loop.swift +++ b/Loop/Extensions/UIColor+Loop.swift @@ -23,4 +23,6 @@ extension UIColor { @nonobjc static let gridColor = UIColor(white: 193 / 255, alpha: 1) @nonobjc static let pumpStatusNormal = secondaryLabelColor + + @nonobjc static let thresholdLineColor = UIColor.HIGRedColor() } diff --git a/Loop/View Controllers/PredictionTableViewController.swift b/Loop/View Controllers/PredictionTableViewController.swift index b572b79f5c..d9b2bebf14 100644 --- a/Loop/View Controllers/PredictionTableViewController.swift +++ b/Loop/View Controllers/PredictionTableViewController.swift @@ -132,6 +132,7 @@ class PredictionTableViewController: ChartsTableViewController, IdentifiableClas if self.refreshContext.remove(.targets) != nil { self.charts.targetGlucoseSchedule = manager.settings.glucoseTargetRangeSchedule + self.charts.suspendThresholdValue = manager.settings.suspendThreshold?.quantity.doubleValue(for: self.charts.glucoseUnit) } reloadGroup.leave() diff --git a/Loop/View Controllers/StatusTableViewController.swift b/Loop/View Controllers/StatusTableViewController.swift index c4a53d9a89..1c40851954 100644 --- a/Loop/View Controllers/StatusTableViewController.swift +++ b/Loop/View Controllers/StatusTableViewController.swift @@ -378,6 +378,7 @@ final class StatusTableViewController: ChartsTableViewController { if currentContext.contains(.targets) { self.charts.targetGlucoseSchedule = self.deviceManager.loopManager.settings.glucoseTargetRangeSchedule } + self.charts.suspendThresholdValue = self.deviceManager.loopManager.settings.suspendThreshold?.quantity.doubleValue(for: self.charts.glucoseUnit) // Active Insulin if let iobValues = iobValues { diff --git a/LoopUI/Managers/StatusChartsManager.swift b/LoopUI/Managers/StatusChartsManager.swift index d605937b15..b3b82b2645 100644 --- a/LoopUI/Managers/StatusChartsManager.swift +++ b/LoopUI/Managers/StatusChartsManager.swift @@ -216,6 +216,9 @@ public final class StatusChartsManager { glucoseChart = nil } } + + /// Suspend Threshold value + public var suspendThresholdValue: Double? = nil /// The chart points for IOB public var iobPoints: [ChartPoint] = [] { @@ -368,6 +371,20 @@ public final class StatusChartsManager { ) ] ) + + // SuspendThreshold line + var suspendThresholdLayer: ChartPointsLineLayer? = nil + if suspendThresholdValue != nil { + if suspendThresholdValue! >= yAxisLayer.axis.first { + let lineModel = ChartLineModel( + chartPoints: [ChartPoint(x: ChartAxisValueDouble(xAxisLayer.axis.first), + y: ChartAxisValueDouble(suspendThresholdValue!)), + ChartPoint(x: ChartAxisValueDouble(xAxisLayer.axis.last), + y: ChartAxisValueDouble(suspendThresholdValue!))], + lineColor: colors.threshold.withAlphaComponent(0.4), lineWidth: 1, animDuration: 0, animDelay: 0) + suspendThresholdLayer = ChartPointsLineLayer(xAxis: xAxisLayer.axis, yAxis: yAxisLayer.axis, lineModels: [lineModel]) + } + } // Grid lines let gridLayer = ChartGuideLinesForValuesLayer(xAxis: xAxisLayer.axis, yAxis: yAxisLayer.axis, settings: guideLinesLayerSettings, axisValuesX: Array(xAxisValues.dropFirst().dropLast()), axisValuesY: yAxisValues) @@ -411,6 +428,7 @@ public final class StatusChartsManager { let layers: [ChartLayer?] = [ gridLayer, targetsLayer, + suspendThresholdLayer, xAxisLayer, yAxisLayer, glucoseChartCache?.highlightLayer, diff --git a/LoopUI/Models/ChartColorPalette.swift b/LoopUI/Models/ChartColorPalette.swift index 773e73b83f..6e5c54358f 100644 --- a/LoopUI/Models/ChartColorPalette.swift +++ b/LoopUI/Models/ChartColorPalette.swift @@ -13,13 +13,15 @@ public struct ChartColorPalette { public let axisLine: UIColor public let axisLabel: UIColor public let grid: UIColor + public let threshold: UIColor public let glucoseTint: UIColor public let doseTint: UIColor - public init(axisLine: UIColor, axisLabel: UIColor, grid: UIColor, glucoseTint: UIColor, doseTint: UIColor) { + public init(axisLine: UIColor, axisLabel: UIColor, grid: UIColor, threshold: UIColor, glucoseTint: UIColor, doseTint: UIColor) { self.axisLine = axisLine self.axisLabel = axisLabel self.grid = grid + self.threshold = threshold self.glucoseTint = glucoseTint self.doseTint = doseTint }