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
8 changes: 8 additions & 0 deletions Common/Extensions/SampleValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
import LoopKit
import LoopAlgorithm

extension SampleValue {
/// A glucose value entered by hand, such as a fingerstick or calibration.
var isManualGlucose: Bool {
guard let sample = self as? GlucoseSampleValue else { return false }
return sample.wasUserEntered && !sample.isDisplayOnly
}
}

extension Collection where Element == SampleValue {
/// O(n)
var quantityRange: ClosedRange<LoopQuantity>? {
Expand Down
6 changes: 4 additions & 2 deletions WatchApp Extension/Managers/ComplicationChartManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private let textInsets = UIEdgeInsets(top: 2, left: 2, bottom: 2, right: 2)

extension CGSize {
fileprivate static let glucosePoint = CGSize(width: 2, height: 2)
fileprivate static let manualGlucosePoint = CGSize(width: 3, height: 3)
}

extension NSAttributedString {
Expand Down Expand Up @@ -150,12 +151,13 @@ final class ComplicationChartManager {
}

private func drawHistoricalGlucose(in context: CGContext, using scaler: GlucoseChartScaler) {
context.setFillColor(UIColor.glucose.cgColor)
data?.historicalGlucose?.lazy.filter {
scaler.dates.contains($0.startDate)
}.forEach { glucose in
let origin = scaler.point(for: glucose, unit: unit)
let glucoseRect = CGRect(origin: origin, size: .glucosePoint).alignedToScreenScale(WKInterfaceDevice.current().screenScale)
let size: CGSize = glucose.isManualGlucose ? .manualGlucosePoint : .glucosePoint
let glucoseRect = CGRect(origin: origin, size: size).alignedToScreenScale(WKInterfaceDevice.current().screenScale)
context.setFillColor((glucose.isManualGlucose ? UIColor.red : UIColor.glucose).cgColor)
context.fill(glucoseRect)
}
}
Expand Down
4 changes: 2 additions & 2 deletions WatchApp Extension/Scenes/GlucoseChartScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ class GlucoseChartScene: SKScene {

data.historicalGlucose?.filter { scaler.dates.contains($0.startDate) }.forEach {
let center = scaler.point($0.startDate, $0.quantity.doubleValue(for: unit))
let size = CGSize(width: 2, height: 2)
let size = $0.isManualGlucose ? CGSize(width: 3, height: 3) : CGSize(width: 2, height: 2)
let origin = CGPoint(x: center.x - size.width / 2, y: center.y - size.height / 2)
let (sprite, created) = getSprite(forHash: $0.chartHashValue)
sprite.color = .glucose
sprite.color = $0.isManualGlucose ? .red : .glucose
sprite.zPosition = NodePlane.values.zPosition
sprite.move(to: CGRect(origin: origin, size: size).alignedToScreenScale(WKInterfaceDevice.current().screenScale), animated: !created)
inactiveNodes.removeValue(forKey: $0.chartHashValue)
Expand Down