moved layout related settings to constants
This commit is contained in:
parent
c5f9ad6165
commit
95870fbdee
|
@ -223,7 +223,6 @@
|
|||
F8BECB1E235CFB1E0060DAE1 /* ChartPointsTouchHighlightLayerViewCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8BECB1D235CFB1E0060DAE1 /* ChartPointsTouchHighlightLayerViewCache.swift */; };
|
||||
F8BECB20235E04910060DAE1 /* ChartPointsContextFillLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8BECB1F235E04910060DAE1 /* ChartPointsContextFillLayer.swift */; };
|
||||
F8BECB22235E0A8E0060DAE1 /* BidirectionalCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8BECB21235E0A8E0060DAE1 /* BidirectionalCollection.swift */; };
|
||||
F8BECB24235E0B030060DAE1 /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8BECB23235E0B030060DAE1 /* UIColor.swift */; };
|
||||
F8BECB26235E0BB60060DAE1 /* ChartPointsScatterDownTrianglesLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8BECB25235E0BB60060DAE1 /* ChartPointsScatterDownTrianglesLayer.swift */; };
|
||||
F8BECB28235E0C3F0060DAE1 /* ChartPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8BECB27235E0C3F0060DAE1 /* ChartPoint.swift */; };
|
||||
F8BECB2E235E0E060060DAE1 /* SampleValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8BECB2D235E0E060060DAE1 /* SampleValue.swift */; };
|
||||
|
@ -596,7 +595,6 @@
|
|||
F8BECB1D235CFB1E0060DAE1 /* ChartPointsTouchHighlightLayerViewCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartPointsTouchHighlightLayerViewCache.swift; sourceTree = "<group>"; };
|
||||
F8BECB1F235E04910060DAE1 /* ChartPointsContextFillLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartPointsContextFillLayer.swift; sourceTree = "<group>"; };
|
||||
F8BECB21235E0A8E0060DAE1 /* BidirectionalCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BidirectionalCollection.swift; sourceTree = "<group>"; };
|
||||
F8BECB23235E0B030060DAE1 /* UIColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = "<group>"; };
|
||||
F8BECB25235E0BB60060DAE1 /* ChartPointsScatterDownTrianglesLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartPointsScatterDownTrianglesLayer.swift; sourceTree = "<group>"; };
|
||||
F8BECB27235E0C3F0060DAE1 /* ChartPoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartPoint.swift; sourceTree = "<group>"; };
|
||||
F8BECB2D235E0E060060DAE1 /* SampleValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleValue.swift; sourceTree = "<group>"; };
|
||||
|
@ -702,7 +700,6 @@
|
|||
F8B3A78A225D473D004BA588 /* UIAlertController.swift */,
|
||||
F898EDEB233F549100BFB79B /* UIBarButtonItem.swift */,
|
||||
F898EDE9233F53BF00BFB79B /* UIButton.swift */,
|
||||
F8BECB23235E0B030060DAE1 /* UIColor.swift */,
|
||||
F898EDF1234A8A0500BFB79B /* UInt8.swift */,
|
||||
F898EDF3234A8A3200BFB79B /* UInt16.swift */,
|
||||
F898EDF5234A8A5700BFB79B /* UInt32.swift */,
|
||||
|
@ -1684,7 +1681,6 @@
|
|||
F8C5EBEA22F49AC700563B5F /* CGMDroplet1Transmitter.swift in Sources */,
|
||||
F8EEDD4422FD80A600D2D610 /* LibreOOPResponse.swift in Sources */,
|
||||
F8BECB28235E0C3F0060DAE1 /* ChartPoint.swift in Sources */,
|
||||
F8BECB24235E0B030060DAE1 /* UIColor.swift in Sources */,
|
||||
F821CF56229BF43A005C1E43 /* AlertKind.swift in Sources */,
|
||||
F85DC2ED21CFE2F500B9F74A /* BgReading+CoreDataProperties.swift in Sources */,
|
||||
F8A54AE422D911BA00934E7A /* NSData+CRC.swift in Sources */,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import Foundation
|
||||
import UIKit
|
||||
|
||||
enum ConstantsGlucoseChart {
|
||||
|
||||
|
@ -10,38 +10,60 @@ enum ConstantsGlucoseChart {
|
|||
/// H is hour 24 hour format, "h a" is hour 12 hour format with a either am or pm
|
||||
static let defaultTimeAxisLabelFormat = "H"
|
||||
|
||||
/// if unit is mgdl, we wil have a horizointal line each ... mgdl
|
||||
static let chartTableIncrementForMgDL = 50.0
|
||||
|
||||
/// if unit is mmol, we wil have a horizointal line each ... mmol
|
||||
static let chartTableIncrementForMmol = 2.0
|
||||
|
||||
/// usually 40.0 mgdl is the lowest value that cgm's give, putting it to 38 guarantees the points will always be visible
|
||||
///
|
||||
/// only in mgdl because the label will not be shown, hence no bizar values to be shown when going to mgdl
|
||||
static let absoluteMinimumChartValueInMgdl = 38.0
|
||||
|
||||
/// the minimum value that a cgm can show, it should be greater than absoluteMinimumChartValueInMgdl
|
||||
static let minimumCGMGlucoseValueInMgdl = 40.0
|
||||
/// if there's no readings to show with value higher than the maximum in this array, then this array will determine the maximum possible value in the chart, in mgdl
|
||||
static let initialGlucoseValueRangeInMgDl = [50.0, 100.0, 150.0, 200.0]
|
||||
|
||||
/// default initial max mgdl value in chart, in mgdl - xdrip will try to maximize the use of the available height. If there's no glucose reading higher than this value, then the maximum in the graph will be this value
|
||||
///
|
||||
/// it's default, because a user will be able to modify the value later in the settings - in the code, the value will be
|
||||
static let defaultInitialMaxChartValueInMgdl = 200.0
|
||||
/// if there's no readings to show with value higher than the maximum in this array, then this array will determine the maximum possible value in the chart, in mmol
|
||||
static let initialGlucoseValueRangeInMmol = [3.0, 6.0, 9.0, 12.0]
|
||||
|
||||
/// default initial max mmol value in chart, in mmol - xdrip will try to maximize the use of the available height. If there's no glucose reading higher than this value, then the maximum in the graph will be this value
|
||||
///
|
||||
/// it's default, because a user will be able to modify the value later in the settings - in the code, the value will be
|
||||
static let defaultInitialMaxChartValueInMmol = 11.0
|
||||
/// if the maximum in initialGlucoseValueRangeInMgDl isn't enough to show all values, if there's no readings to show with value higher than the maximum in this array, then this array will determine the maximum possible value in the chart, in mgdl
|
||||
static let secondGlucoseValueRangeInMgDl = [250.0, 300.0]
|
||||
|
||||
/// default increase in maxium mgdl value in the chart, in mgdl - xdrip will try to maximize the use of the available height. If there's a glucose reading higher than the initial value, then the maximum will be increased with this value, until all readings fit in the chart
|
||||
///
|
||||
/// it's default, because a user will be able to modify the value later in the settings
|
||||
static let defaultIncreaseMaxChartValueInMgdl = 100.0
|
||||
/// if the maximum in initialGlucoseValueRangeInMgDl isn't enough to show all values, if there's no readings to show with value higher than the maximum in this array, then this array will determine the maximum possible value in the chart, in mgdl
|
||||
static let secondGlucoseValueRangeInMmol = [15.0, 18.0]
|
||||
|
||||
/// default increase in maxium mmol value in the chart, in mmol - xdrip will try to maximize the use of the available height. If there's a glucose reading higher than the initial value, then the maximum will be increased with this value, until all readings fit in the chart
|
||||
///
|
||||
/// it's default, because a user will be able to modify the value later in the settings
|
||||
static let defaultIncreaseMaxChartValueInMmol = 6.0
|
||||
/// if the maximum in secondGlucoseValueRangeInMgDl isn't enough to show all values, if there's no readings to show with value higher than the maximum in this array, then this array will determine the maximum possible value in the chart, in mgdl
|
||||
static let thirdGlucoseValueRangeInMgDl = [350.0, 400.0]
|
||||
|
||||
/// if the maximum in initialGlucoseValueRangeInMgDl isn't enough to show all values, if there's no readings to show with value higher than the maximum in this array, then this array will determine the maximum possible value in the chart, in mgdl
|
||||
static let thirdGlucoseValueRangeInMmol = [21.0, 23.0]
|
||||
|
||||
/// axis line color
|
||||
static let axisLineColor = UIColor.black
|
||||
|
||||
/// axis line label
|
||||
static let axisLabelColor = UIColor.black
|
||||
|
||||
/// grid color
|
||||
static let gridColor = UIColor.gray
|
||||
|
||||
/// glucose color
|
||||
static let glucoseTintColor = UIColor.green
|
||||
|
||||
/// labels width for vertical axis
|
||||
static let yAxisLabelsWidth: CGFloat = 30
|
||||
|
||||
/// Empty space in points added to the leading edge of the chart
|
||||
static let leading: CGFloat = 0
|
||||
|
||||
/// Empty space in points added to the top edge of the chart
|
||||
static let top: CGFloat = 8
|
||||
|
||||
/// Empty space in points added to the trailing edge of the chart
|
||||
static let trailing: CGFloat = 4
|
||||
|
||||
/// Empty space in points added to the bottom edge of the chart
|
||||
static let bottom: CGFloat = 0
|
||||
|
||||
/// The spacing in points between X axis labels and the X axis line
|
||||
static let labelsToAxisSpacingX: CGFloat = 6
|
||||
|
||||
/// The spacing in points between axis title labels and axis labels
|
||||
static let axisTitleLabelsToLabelsSpacing: CGFloat = 0
|
||||
|
||||
}
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
//
|
||||
// UIColor.swift
|
||||
// Naterade
|
||||
//
|
||||
// Created by Nathan Racklyeft on 1/23/16.
|
||||
// Copyright © 2016 Nathan Racklyeft. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
extension UIColor {
|
||||
|
||||
// MARK: - HIG colors
|
||||
// See: https://developer.apple.com/ios/human-interface-guidelines/visual-design/color/
|
||||
|
||||
static func HIGTealBlueColor() -> UIColor {
|
||||
return UIColor(red: 90 / 255, green: 200 / 255, blue: 250 / 255, alpha: 1)
|
||||
}
|
||||
|
||||
static func HIGYellowColor() -> UIColor {
|
||||
return UIColor(red: 1, green: 204 / 255, blue: 0, alpha: 1)
|
||||
}
|
||||
|
||||
static func HIGOrangeColor() -> UIColor {
|
||||
return UIColor(red: 1, green: 149 / 255, blue: 0 / 255, alpha: 1)
|
||||
}
|
||||
|
||||
static func HIGPinkColor() -> UIColor {
|
||||
return UIColor(red: 1, green: 45 / 255, blue: 85 / 255, alpha: 1)
|
||||
}
|
||||
|
||||
static func HIGBlueColor() -> UIColor {
|
||||
return UIColor(red: 0, green: 122 / 255, blue: 1, alpha: 1)
|
||||
}
|
||||
|
||||
static func HIGGreenColor() -> UIColor {
|
||||
return UIColor(red: 76 / 255, green: 217 / 255, blue: 100 / 255, alpha: 1)
|
||||
}
|
||||
|
||||
static func HIGRedColor() -> UIColor {
|
||||
return UIColor(red: 1, green: 59 / 255, blue: 48 / 255, alpha: 1)
|
||||
}
|
||||
|
||||
static func HIGPurpleColor() -> UIColor {
|
||||
return UIColor(red: 88 / 255, green: 86 / 255, blue: 214 / 255, alpha: 1)
|
||||
}
|
||||
|
||||
static func HIGGrayColor() -> UIColor {
|
||||
return UIColor(red: 142 / 255, green: 143 / 255, blue: 147 / 255, alpha: 1)
|
||||
}
|
||||
|
||||
|
||||
@nonobjc static var tintColor: UIColor? = nil
|
||||
|
||||
@nonobjc static let secondaryLabelColor = UIColor.HIGGrayColor()
|
||||
|
||||
@nonobjc static let cellBackgroundColor = UIColor(white: 239 / 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)
|
||||
|
||||
@nonobjc static let agingColor = UIColor.HIGYellowColor()
|
||||
|
||||
@nonobjc static let staleColor = UIColor.HIGRedColor()
|
||||
|
||||
@nonobjc static let unknownColor = UIColor(red: 198 / 255, green: 199 / 255, blue: 201 / 255, alpha: 1)
|
||||
|
||||
@nonobjc static let deleteColor = UIColor.HIGRedColor()
|
||||
|
||||
@nonobjc static let axisLabelColor = secondaryLabelColor
|
||||
|
||||
@nonobjc static let axisLineColor = UIColor.clear
|
||||
|
||||
@nonobjc static let doseTintColor = UIColor.HIGOrangeColor()
|
||||
|
||||
@nonobjc static let freshColor = UIColor.HIGGreenColor()
|
||||
|
||||
@nonobjc static let glucoseTintColor = UIColor(red: 0 / 255, green: 176 / 255, blue: 255 / 255, alpha: 1)
|
||||
|
||||
@nonobjc static let gridColor = UIColor(white: 193 / 255, alpha: 1)
|
||||
|
||||
@nonobjc static let pumpStatusNormal = secondaryLabelColor
|
||||
|
||||
}
|
|
@ -10,11 +10,6 @@ public final class StatusChartsManager {
|
|||
|
||||
// MARK: - public properties
|
||||
|
||||
/// The amount of horizontal space reserved for fixed margins
|
||||
public var fixedHorizontalMargin: CGFloat {
|
||||
return chartSettings.leading + chartSettings.trailing + labelsWidthY + chartSettings.labelsToAxisSpacingY
|
||||
}
|
||||
|
||||
public var gestureRecognizer: UIGestureRecognizer?
|
||||
|
||||
/// The latest allowed date on the X-axis
|
||||
|
@ -53,15 +48,7 @@ public final class StatusChartsManager {
|
|||
|
||||
private let chartSettings: ChartSettings
|
||||
|
||||
private let labelsWidthY: CGFloat = 30
|
||||
|
||||
private var integerFormatter: NumberFormatter {
|
||||
let numberFormatter = NumberFormatter()
|
||||
numberFormatter.numberStyle = .none
|
||||
numberFormatter.maximumFractionDigits = 0
|
||||
|
||||
return numberFormatter
|
||||
}
|
||||
private let labelsWidthY = ConstantsGlucoseChart.yAxisLabelsWidth
|
||||
|
||||
private var chartLabelSettings: ChartLabelSettings
|
||||
|
||||
|
@ -111,8 +98,8 @@ public final class StatusChartsManager {
|
|||
|
||||
private var glucoseChartCache: ChartPointsTouchHighlightLayerViewCache?
|
||||
|
||||
/// dateformatter for chartpoints ???
|
||||
private let dateFormatter: DateFormatter = {
|
||||
/// dateformatter for timestamp in chartpoints
|
||||
private let chartPointDateFormatter: DateFormatter = {
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateStyle = .none
|
||||
dateFormatter.timeStyle = .short
|
||||
|
@ -147,6 +134,29 @@ public final class StatusChartsManager {
|
|||
axisLabelTimeFormatter.dateFormat = UserDefaults.standard.chartTimeAxisLabelFormat
|
||||
|
||||
}
|
||||
|
||||
convenience public init() {
|
||||
|
||||
self.init(
|
||||
colors: ChartColorPalette(
|
||||
axisLine: ConstantsGlucoseChart.axisLineColor,
|
||||
axisLabel: ConstantsGlucoseChart.axisLabelColor,
|
||||
grid: ConstantsGlucoseChart.gridColor,
|
||||
glucoseTint: ConstantsGlucoseChart.glucoseTintColor
|
||||
),
|
||||
settings: {
|
||||
var settings = ChartSettings()
|
||||
settings.top = ConstantsGlucoseChart.top
|
||||
settings.bottom = ConstantsGlucoseChart.bottom
|
||||
settings.trailing = ConstantsGlucoseChart.trailing
|
||||
settings.leading = ConstantsGlucoseChart.leading
|
||||
settings.axisTitleLabelsToLabelsSpacing = ConstantsGlucoseChart.axisTitleLabelsToLabelsSpacing
|
||||
settings.labelsToAxisSpacingX = ConstantsGlucoseChart.labelsToAxisSpacingX
|
||||
settings.clipInnerFrame = false
|
||||
return settings
|
||||
}()
|
||||
)
|
||||
}
|
||||
|
||||
// MARK: - public functions
|
||||
|
||||
|
@ -156,16 +166,20 @@ public final class StatusChartsManager {
|
|||
let now = Date()
|
||||
//for testing only, 1 per 5 minutes
|
||||
//let intervals = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
|
||||
let intervals = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
|
||||
let glucose = intervals.map { (Date(timeInterval: -Double($0)*300.0, since: now), 10.0 + Double($0)*2.0) }
|
||||
let intervals = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]
|
||||
let glucose = intervals.map { (Date(timeInterval: -(Double($0)*900), since: now), (10.0 + Double($0)*20.0).mgdlToMmol(mgdl: UserDefaults.standard.bloodGlucoseUnitIsMgDl)) }
|
||||
//let glucose = [(now, 110.0), (now.addingTimeInterval(-300), 120.0), (now.addingTimeInterval(-600), 130.0)]
|
||||
|
||||
glucoseChartPoints = glucose.map {
|
||||
ChartPoint(
|
||||
x: ChartAxisValueDate(date: $0.0, formatter: dateFormatter),
|
||||
x: ChartAxisValueDate(date: $0.0, formatter: chartPointDateFormatter),
|
||||
y: ChartAxisValueDouble($0.1)
|
||||
)
|
||||
}
|
||||
|
||||
/*glucoseChartPoints.map {
|
||||
debuglogging("scalar = " + $0.y.scalar.description)
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -201,7 +215,7 @@ public final class StatusChartsManager {
|
|||
}
|
||||
}
|
||||
|
||||
public func glucoseChartWithFrame(_ frame: CGRect, chartTableIncrement: Double) -> Chart? {
|
||||
public func glucoseChartWithFrame(_ frame: CGRect) -> Chart? {
|
||||
|
||||
if let chart = glucoseChart, chart.frame != frame {
|
||||
|
||||
|
@ -211,7 +225,7 @@ public final class StatusChartsManager {
|
|||
}
|
||||
|
||||
if glucoseChart == nil {
|
||||
glucoseChart = generateGlucoseChartWithFrame(frame, chartTableIncrement: chartTableIncrement)
|
||||
glucoseChart = generateGlucoseChartWithFrame(frame)
|
||||
}
|
||||
|
||||
return glucoseChart
|
||||
|
@ -228,53 +242,56 @@ public final class StatusChartsManager {
|
|||
|
||||
// MARK: - private functions
|
||||
|
||||
private func generateGlucoseChartWithFrame(_ frame: CGRect, chartTableIncrement: Double) -> Chart? {
|
||||
private func generateGlucoseChartWithFrame(_ frame: CGRect) -> Chart? {
|
||||
|
||||
guard let xAxisModel = xAxisModel, let xAxisValues = xAxisValues else {return nil}
|
||||
|
||||
// just to save typing
|
||||
let unitIsMgDl = UserDefaults.standard.bloodGlucoseUnitIsMgDl
|
||||
|
||||
// create yAxisValues, start with 38 mgdl, this is to make sure we show a bit lower than the real lowest value which is isually 40 mgdl, make the label invisible
|
||||
let firstYAxisValue: ChartAxisValue = ChartAxisValueDouble((ConstantsGlucoseChart.absoluteMinimumChartValueInMgdl).mgdlToMmol(mgdl: unitIsMgDl), labelSettings: chartLabelSettings)
|
||||
// create yAxisValues, start with 38 mgdl, this is to make sure we show a bit lower than the real lowest value which is isually 40 mgdl, make the label hidden
|
||||
let firstYAxisValue = ChartAxisValueDouble((ConstantsGlucoseChart.absoluteMinimumChartValueInMgdl).mgdlToMmol(mgdl: unitIsMgDl), labelSettings: chartLabelSettings)
|
||||
firstYAxisValue.hidden = true
|
||||
|
||||
// now create 40, still make the label invisible
|
||||
let secondYAxisValue: ChartAxisValue = ChartAxisValueDouble((ConstantsGlucoseChart.minimumCGMGlucoseValueInMgdl).mgdlToMmol(mgdl: unitIsMgDl), labelSettings: chartLabelSettings)
|
||||
secondYAxisValue.hidden = true
|
||||
// create now the yAxisValues and add the first
|
||||
var yAxisValues = [firstYAxisValue as ChartAxisValue]
|
||||
|
||||
// create now the yAxisValues and add the first two
|
||||
var yAxisValues = [firstYAxisValue, secondYAxisValue]
|
||||
|
||||
// determine the maximum value in the glucosechartPoints, in mgdl
|
||||
// determine the maximum value in the glucosechartPoint
|
||||
// start with maximum value defined in constants
|
||||
var maximumValueInGlucoseChartPointsInMgdl = ConstantsGlucoseChart.defaultInitialMaxChartValueInMgdl
|
||||
var maximumValueInGlucoseChartPoints = ConstantsGlucoseChart.absoluteMinimumChartValueInMgdl.mgdlToMmol(mgdl: unitIsMgDl)
|
||||
// now iterate through glucosechartpoints to determine the maximum
|
||||
for glucoseChartPoint in glucoseChartPoints {
|
||||
maximumValueInGlucoseChartPointsInMgdl = max(maximumValueInGlucoseChartPointsInMgdl, glucoseChartPoint.y.scalar.mmolToMgdl(mgdl: unitIsMgDl))
|
||||
maximumValueInGlucoseChartPoints = max(maximumValueInGlucoseChartPoints, glucoseChartPoint.y.scalar)
|
||||
}
|
||||
|
||||
// now the maximum in the chart needs to be calculated
|
||||
var maximumToShowInChartInUserUnit = unitIsMgDl ? ConstantsGlucoseChart.defaultInitialMaxChartValueInMgdl:ConstantsGlucoseChart.defaultInitialMaxChartValueInMmol
|
||||
// increase the maximum as long as the valule is lower than maximumValueInGlucoseChartPointsInMgdl
|
||||
while maximumToShowInChartInUserUnit < maximumValueInGlucoseChartPointsInMgdl.mgdlToMmol(mgdl: unitIsMgDl) {
|
||||
maximumToShowInChartInUserUnit += unitIsMgDl ? ConstantsGlucoseChart.defaultIncreaseMaxChartValueInMgdl:ConstantsGlucoseChart.defaultIncreaseMaxChartValueInMmol
|
||||
// add first series
|
||||
if unitIsMgDl {
|
||||
yAxisValues += ConstantsGlucoseChart.initialGlucoseValueRangeInMgDl.map { ChartAxisValueDouble($0, labelSettings: chartLabelSettings)}
|
||||
} else {
|
||||
yAxisValues += ConstantsGlucoseChart.initialGlucoseValueRangeInMmol.map { ChartAxisValueDouble($0, labelSettings: chartLabelSettings)}
|
||||
}
|
||||
|
||||
// get increment to use on yAxis
|
||||
let incrementToUse = unitIsMgDl ? ConstantsGlucoseChart.chartTableIncrementForMgDL : ConstantsGlucoseChart.chartTableIncrementForMmol
|
||||
|
||||
// add the remaining chartpoints
|
||||
while yAxisValues.last!.scalar < maximumToShowInChartInUserUnit {
|
||||
yAxisValues.append(ChartAxisValueDouble(yAxisValues.last!.scalar + incrementToUse, labelSettings: chartLabelSettings))
|
||||
// if the maxium yAxisValue doesn't support the maximum glucose value, then add the next range
|
||||
if yAxisValues.last!.scalar < maximumValueInGlucoseChartPoints {
|
||||
if unitIsMgDl {
|
||||
yAxisValues += ConstantsGlucoseChart.secondGlucoseValueRangeInMgDl.map { ChartAxisValueDouble($0, labelSettings: chartLabelSettings)}
|
||||
} else {
|
||||
yAxisValues += ConstantsGlucoseChart.secondGlucoseValueRangeInMmol.map { ChartAxisValueDouble($0, labelSettings: chartLabelSettings)}
|
||||
}
|
||||
}
|
||||
|
||||
// if the maxium yAxisValue doesn't support the maximum glucose value, then add the next range
|
||||
if yAxisValues.last!.scalar < maximumValueInGlucoseChartPoints {
|
||||
if unitIsMgDl {
|
||||
yAxisValues += ConstantsGlucoseChart.thirdGlucoseValueRangeInMgDl.map { ChartAxisValueDouble($0, labelSettings: chartLabelSettings)}
|
||||
} else {
|
||||
yAxisValues += ConstantsGlucoseChart.thirdGlucoseValueRangeInMmol.map { ChartAxisValueDouble($0, labelSettings: chartLabelSettings)}
|
||||
}
|
||||
}
|
||||
|
||||
// the last label should not be visible
|
||||
yAxisValues.last?.hidden = true
|
||||
|
||||
yAxisValues.map {
|
||||
debuglogging("scalar = " + $0.scalar.description)
|
||||
}
|
||||
|
||||
let yAxisModel = ChartAxisModel(axisValues: yAxisValues, lineColor: colors.axisLine, labelSpaceReservationMode: .fixed(labelsWidthY))
|
||||
|
||||
let coordsSpace = ChartCoordsSpaceLeftBottomSingleAxis(chartSettings: chartSettings, chartFrame: frame, xModel: xAxisModel, yModel: yAxisModel)
|
||||
|
|
|
@ -16,7 +16,7 @@ public struct ChartColorPalette {
|
|||
public let grid: UIColor
|
||||
public let glucoseTint: UIColor
|
||||
|
||||
public init(axisLine: UIColor, axisLabel: UIColor, grid: UIColor, glucoseTint: UIColor, doseTint: UIColor) {
|
||||
public init(axisLine: UIColor, axisLabel: UIColor, grid: UIColor, glucoseTint: UIColor) {
|
||||
|
||||
self.axisLine = axisLine
|
||||
self.axisLabel = axisLabel
|
||||
|
|
|
@ -39,8 +39,8 @@ final class RootViewController: UIViewController {
|
|||
|
||||
@IBAction func preSnoozeButtonAction(_ sender: UIButton) {
|
||||
|
||||
statusChartsManager.updateChart()
|
||||
statusChartsManager.prerender()
|
||||
glucoseChartManager?.updateChart()
|
||||
glucoseChartManager?.prerender()
|
||||
chartOutlet.reloadChart()
|
||||
/*
|
||||
let alert = UIAlertController(title: "Info", message: "Unfortuantely, presnooze functionality is not yet implemented", actionHandler: nil)
|
||||
|
@ -137,29 +137,8 @@ final class RootViewController: UIViewController {
|
|||
/// manages m5Stack that this app knows
|
||||
private var m5StackManager: M5StackManager?
|
||||
|
||||
private lazy var statusChartsManager: StatusChartsManager = {
|
||||
let statusChartsManager = StatusChartsManager(
|
||||
colors: ChartColorPalette(
|
||||
axisLine: .axisLineColor,
|
||||
axisLabel: .axisLabelColor,
|
||||
grid: .gridColor,
|
||||
glucoseTint: .glucoseTintColor,
|
||||
doseTint: .doseTintColor
|
||||
),
|
||||
settings: {
|
||||
var settings = ChartSettings()
|
||||
settings.top = 4
|
||||
settings.bottom = 8
|
||||
settings.trailing = 8
|
||||
settings.axisTitleLabelsToLabelsSpacing = 0
|
||||
settings.labelsToAxisSpacingX = 6
|
||||
settings.clipInnerFrame = false
|
||||
return settings
|
||||
}()
|
||||
)
|
||||
|
||||
return statusChartsManager
|
||||
}()
|
||||
/// manage glucose chart
|
||||
private var glucoseChartManager: StatusChartsManager?
|
||||
|
||||
// MARK: - View Life Cycle
|
||||
|
||||
|
@ -185,10 +164,10 @@ final class RootViewController: UIViewController {
|
|||
// create transmitter based on UserDefaults
|
||||
self.initializeCGMTransmitter()
|
||||
|
||||
self.statusChartsManager.prerender()
|
||||
self.glucoseChartManager?.prerender()
|
||||
self.chartOutlet.chartGenerator = { [weak self] (frame) in
|
||||
|
||||
return self?.statusChartsManager.glucoseChartWithFrame(frame, chartTableIncrement: UserDefaults.standard.bloodGlucoseUnitIsMgDl ? ConstantsGlucoseChart.chartTableIncrementForMgDL : ConstantsGlucoseChart.chartTableIncrementForMmol)?.view
|
||||
return self?.glucoseChartManager?.glucoseChartWithFrame(frame)?.view
|
||||
|
||||
}
|
||||
|
||||
|
@ -329,6 +308,9 @@ final class RootViewController: UIViewController {
|
|||
|
||||
// setup m5StackManager
|
||||
m5StackManager = M5StackManager(coreDataManager: coreDataManager)
|
||||
|
||||
// setup glucoseChartManager
|
||||
glucoseChartManager = StatusChartsManager()
|
||||
}
|
||||
|
||||
/// process new glucose data received from transmitter.
|
||||
|
|
Loading…
Reference in New Issue