Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4104b1f
WIP
Jan 9, 2017
3142e82
Show the glucose chart, support accordioning open/closed. Still needs a
Feb 5, 2017
88ee761
WIP
Feb 8, 2017
65a3cd3
WIP
Feb 12, 2017
3e76861
Merge branch 'dev' into dev-show-more
Feb 12, 2017
4b618d0
WIP
Feb 12, 2017
2a54839
WIP
Feb 12, 2017
7c5df77
WIP
Feb 12, 2017
428304b
WIP
Feb 23, 2017
2454471
Merge branch 'dev' into dev-show-more
Mar 4, 2017
8b2a238
Move ChartContentView into LoopUI
Mar 5, 2017
f94ef85
Merge branch 'dev' into dev-show-more
Mar 8, 2017
51f5eb1
post merge cleanup
Mar 8, 2017
7bfdef5
WIP
Mar 10, 2017
e82407f
WIP
Mar 11, 2017
bdcf83f
WIP
Mar 11, 2017
da99ffb
Make chart background clear and use appropriate colors
Mar 11, 2017
7ea1d07
Merge branch 'dev' into dev-show-more
Mar 11, 2017
3e0261c
Fix predicted glucose scene to use ChartContentView from it's new loc…
Mar 12, 2017
88282a4
animate alpha of chart in/out as we show more/less
Mar 12, 2017
c1e95f4
Set the start date for the extension chart more sensibly
Mar 13, 2017
f22767a
Minor cleanups
Mar 13, 2017
5b7e75c
Store glucose target range in the status extension context
Mar 15, 2017
c75f9ce
checkpoint
Mar 16, 2017
181185d
Break StatusChartsManager's dependency on LoopKit.
Mar 17, 2017
d69b8bb
Move Chart views, models and extensions used by both Loop and Loop St…
Mar 17, 2017
c9a1496
Break charting code's dependency on LoopKit
Mar 17, 2017
8feea50
Update to SwiftCharts 0.5.1 which should be app extension safe
Mar 17, 2017
4f0755f
Apply APPLICATION_EXTENSION_API_ONLY=YES on top of the 0.5.1 branch of
Mar 21, 2017
f888758
Merge branch 'dev' into dev-show-more
Mar 21, 2017
eca3e2d
Only show the last 30 minutes of glucose data
Mar 21, 2017
2571a78
Only serialize the most recent SensorDisplayable
Mar 21, 2017
7c032d8
Encode predicted glucose in a tighter form
Mar 21, 2017
9b74b6c
Combine the two StatusChartsManager extensions in Loop
Mar 21, 2017
98a49da
Stop using stored properties in extensions.
Mar 21, 2017
c0c48ef
Don't recalculate target range points on every prerender()
Mar 22, 2017
246267a
Set the test predicted glucose data duration to 3 hours
Mar 23, 2017
a917be1
Peg the chart end date to the last predicted glucose value
Mar 23, 2017
d732fb3
Fix name of file in header comment
Mar 24, 2017
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
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github "LoopKit/LoopKit" ~> 1.2.0
github "LoopKit/xDripG5" ~> 0.8.0
github "i-schuetz/SwiftCharts" ~> 0.5.0
github "bharat/SwiftCharts" "0.5.1-extension-api-safe"
github "mddub/dexcom-share-client-swift" ~> 0.2.0
github "mddub/G4ShareSpy" ~> 0.3.1
github "ps2/rileylink_ios" ~> 1.0
Expand Down
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github "amplitude/Amplitude-iOS" "v3.14.0"
github "amplitude/Amplitude-iOS" "v3.14.1"
github "mddub/G4ShareSpy" "v0.3.1"
github "LoopKit/LoopKit" "v1.2.0"
github "i-schuetz/SwiftCharts" "0.5.1"
github "bharat/SwiftCharts" "0.5.1-extension-api-safe"
github "mddub/dexcom-share-client-swift" "v0.2.0"
github "ps2/rileylink_ios" "v1.0"
github "LoopKit/xDripG5" "v0.8.0"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Carthage/Build/iOS/SwiftCharts.framework/SwiftCharts
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@
//

import Foundation
import LoopKit
import SwiftCharts


extension ChartPoint {
static func pointsForGlucoseRangeSchedule(_ glucoseRangeSchedule: GlucoseRangeSchedule, xAxisValues: [ChartAxisValue]) -> [ChartPoint] {
let targetRanges = glucoseRangeSchedule.between(
start: ChartAxisValueDate.dateFromScalar(xAxisValues.first!.scalar),
end: ChartAxisValueDate.dateFromScalar(xAxisValues.last!.scalar)
)
static func pointsForDatedRanges(_ targetRanges: [DatedRangeContext], xAxisValues: [ChartAxisValue]) -> [ChartPoint] {
let dateFormatter = DateFormatter()

var maxPoints: [ChartPoint] = []
Expand All @@ -36,8 +31,8 @@ extension ChartPoint {
endDate = ChartAxisValueDate(date: targetRanges[index + 1].startDate, formatter: dateFormatter)
}

let minValue = ChartAxisValueDouble(range.value.minValue)
let maxValue = ChartAxisValueDouble(range.value.maxValue)
let minValue = ChartAxisValueDouble(range.minValue)
let maxValue = ChartAxisValueDouble(range.maxValue)

maxPoints += [
ChartPoint(x: startDate, y: maxValue),
Expand All @@ -53,7 +48,7 @@ extension ChartPoint {
return maxPoints + minPoints.reversed()
}

static func pointsForGlucoseRangeScheduleOverrideDuration(_ override: AbsoluteScheduleValue<DoubleRange>, xAxisValues: [ChartAxisValue]) -> [ChartPoint] {
static func pointsForDatedRangeOverrideDuration(_ override: DatedRangeContext, xAxisValues: [ChartAxisValue]) -> [ChartPoint] {
let startDate = Date()

guard override.endDate.timeIntervalSince(startDate) > 0,
Expand All @@ -65,8 +60,8 @@ extension ChartPoint {
let dateFormatter = DateFormatter()
let startDateAxisValue = ChartAxisValueDate(date: startDate, formatter: dateFormatter)
let endDateAxisValue = ChartAxisValueDate(date: min(lastXAxisValue.date, override.endDate), formatter: dateFormatter)
let minValue = ChartAxisValueDouble(override.value.minValue)
let maxValue = ChartAxisValueDouble(override.value.maxValue)
let minValue = ChartAxisValueDouble(override.minValue)
let maxValue = ChartAxisValueDouble(override.maxValue)

return [
ChartPoint(x: startDateAxisValue, y: maxValue),
Expand All @@ -76,20 +71,20 @@ extension ChartPoint {
]
}

static func pointsForGlucoseRangeScheduleOverride(_ override: AbsoluteScheduleValue<DoubleRange>, xAxisValues: [ChartAxisValue]) -> [ChartPoint] {
static func pointsForDatedRangeOverride(_ override: DatedRangeContext, xAxisValues: [ChartAxisValue]) -> [ChartPoint] {
let startDate = Date()

guard override.endDate.timeIntervalSince(startDate) > 0,
let lastXAxisValue = xAxisValues.last as? ChartAxisValueDate
else {
return []
else {
return []
}

let dateFormatter = DateFormatter()
let startDateAxisValue = ChartAxisValueDate(date: startDate, formatter: dateFormatter)
let endDateAxisValue = ChartAxisValueDate(date: lastXAxisValue.date, formatter: dateFormatter)
let minValue = ChartAxisValueDouble(override.value.minValue)
let maxValue = ChartAxisValueDouble(override.value.maxValue)
let minValue = ChartAxisValueDouble(override.minValue)
let maxValue = ChartAxisValueDouble(override.maxValue)

return [
ChartPoint(x: startDateAxisValue, y: maxValue),
Expand All @@ -98,16 +93,5 @@ extension ChartPoint {
ChartPoint(x: startDateAxisValue, y: minValue)
]
}
}


extension ChartPoint: TimelineValue {
public var startDate: Date {
if let dateValue = x as? ChartAxisValueDate {
return dateValue.date
} else {
return Date.distantPast
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import LoopKit


extension BidirectionalCollection where Index: Strideable, Iterator.Element: Comparable, Index.Stride == Int {
Expand Down Expand Up @@ -72,24 +71,3 @@ extension BidirectionalCollection where Index: Strideable, Iterator.Element: Str
}
}


public extension Sequence where Iterator.Element: TimelineValue {
/// Returns the closest element index in the sorted sequence prior to the specified date
///
/// - parameter date: The date to use in the search
///
/// - returns: The closest index, if any exist before the specified date
func closestIndexPriorToDate(_ date: Date) -> Int? {
var closestIndex: Int?

for (index, value) in self.enumerated() {
if value.startDate <= date {
closestIndex = index
} else {
break
}
}

return closestIndex
}
}
4 changes: 4 additions & 0 deletions Common/Extensions/HKUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ extension HKUnit {
return 1
}
}

static func milligramsPerDeciliterUnit() -> HKUnit {
return HKUnit.gramUnit(with: .milli).unitDivided(by: HKUnit.literUnit(with: .deci))
}

static func millimolesPerLiterUnit() -> HKUnit {
return HKUnit.moleUnit(with: .milli, molarMass: HKUnitMolarMassBloodGlucose).unitDivided(by: HKUnit.liter())
Expand Down
2 changes: 0 additions & 2 deletions Common/Extensions/UIColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ extension UIColor {

@nonobjc static let cellBackgroundColor = UIColor(white: 239 / 255, alpha: 1)

@nonobjc static let gridColor = UIColor(white: 193 / 255, alpha: 1)

@nonobjc static let IOBTintColor = UIColor.HIGOrangeColor()

@nonobjc static let COBTintColor = UIColor(red: 99 / 255, green: 218 / 255, blue: 56 / 255, alpha: 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
import Foundation
import HealthKit

// TODO: Remove this dependency
import LoopKit

import SwiftCharts

protocol TargetPointsCalculator {
var glucosePoints: [ChartPoint] { get }
var overridePoints: [ChartPoint] { get }
var overrideDurationPoints: [ChartPoint] { get }

func calculate(_ xAxisValues: [ChartAxisValue]?)
}

final class StatusChartsManager {

Expand Down Expand Up @@ -44,9 +48,9 @@ final class StatusChartsManager {
return numberFormatter
}

private lazy var axisLineColor = UIColor.clear
private lazy var axisLineColor = UIColor.axisLineColor

private lazy var axisLabelSettings: ChartLabelSettings = ChartLabelSettings(font: UIFont.preferredFont(forTextStyle: UIFontTextStyle.caption1), fontColor: UIColor.secondaryLabelColor)
private lazy var axisLabelSettings: ChartLabelSettings = ChartLabelSettings(font: UIFont.preferredFont(forTextStyle: UIFontTextStyle.caption1), fontColor: UIColor.axisLabelColor)

private lazy var guideLinesLayerSettings: ChartGuideLinesLayerSettings = ChartGuideLinesLayerSettings(linesColor: UIColor.gridColor)

Expand Down Expand Up @@ -117,12 +121,6 @@ final class StatusChartsManager {
}
}

var glucoseTargetRangeSchedule: GlucoseRangeSchedule? {
didSet {
targetGlucosePoints = []
}
}

var glucoseDisplayRange: (min: HKQuantity, max: HKQuantity)? {
didSet {
if let range = glucoseDisplayRange {
Expand Down Expand Up @@ -168,6 +166,12 @@ final class StatusChartsManager {
/// The chart points for alternate predicted glucose
var alternatePredictedGlucosePoints: [ChartPoint]?

var targetPointsCalculator: TargetPointsCalculator? {
didSet {
targetGlucosePoints = []
}
}

private var targetGlucosePoints: [ChartPoint] = [] {
didSet {
glucoseChart = nil
Expand Down Expand Up @@ -238,7 +242,7 @@ final class StatusChartsManager {
}
}

private var xAxisValues: [ChartAxisValue]? {
internal var xAxisValues: [ChartAxisValue]? {
didSet {
if let xAxisValues = xAxisValues, xAxisValues.count > 1 {
xAxisModel = ChartAxisModel(axisValues: xAxisValues, lineColor: axisLineColor)
Expand Down Expand Up @@ -636,7 +640,7 @@ final class StatusChartsManager {
return Chart(frame: frame, layers: layers.flatMap { $0 })
}

private func generateXAxisValues() {
internal func generateXAxisValues() {
let timeFormatter = DateFormatter()
timeFormatter.dateFormat = "h a"

Expand Down Expand Up @@ -676,25 +680,16 @@ final class StatusChartsManager {
generateXAxisValues()
}

if let xAxisValues = xAxisValues, xAxisValues.count > 1,
targetGlucosePoints.count == 0,
let targets = glucoseTargetRangeSchedule
{
targetGlucosePoints = ChartPoint.pointsForGlucoseRangeSchedule(targets, xAxisValues: xAxisValues)

if let override = targets.temporaryOverride {
targetOverridePoints = ChartPoint.pointsForGlucoseRangeScheduleOverride(override, xAxisValues: xAxisValues)

targetOverrideDurationPoints = ChartPoint.pointsForGlucoseRangeScheduleOverrideDuration(override, xAxisValues: xAxisValues)
} else {
targetOverridePoints = []
targetOverrideDurationPoints = []
}
if let calculator = targetPointsCalculator,
targetGlucosePoints.count == 0 {
calculator.calculate(xAxisValues)
targetGlucosePoints = calculator.glucosePoints
targetOverridePoints = calculator.overridePoints
targetOverrideDurationPoints = calculator.overrideDurationPoints
}
}
}


private extension HKUnit {
var glucoseUnitYAxisSegmentSize: Double {
if self == HKUnit.milligramsPerDeciliterUnit() {
Expand Down
Loading