From 404c24ce378c887001ca261fb266c170375f2dee Mon Sep 17 00:00:00 2001 From: Nathan Racklyeft Date: Thu, 22 Sep 2016 09:14:29 -0700 Subject: [PATCH 1/2] Display an axis line for every graph as long as there are X values --- Loop/Managers/StatusChartManager.swift | 54 ++++++++++++++++++++------ 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/Loop/Managers/StatusChartManager.swift b/Loop/Managers/StatusChartManager.swift index cfb4aae45d..293fe9421f 100644 --- a/Loop/Managers/StatusChartManager.swift +++ b/Loop/Managers/StatusChartManager.swift @@ -223,6 +223,14 @@ final class StatusChartsManager { } } + /// The minimum range to display for insulin values. + private let IOBDisplayRangePoints: [ChartPoint] = [0, 1].map { + return ChartPoint( + x: ChartAxisValue(scalar: 0), + y: ChartAxisValueInt($0) + ) + } + private var COBPoints: [ChartPoint] = [] { didSet { COBChart = nil @@ -230,6 +238,14 @@ final class StatusChartsManager { } } + /// The minimum range to display for COB values. + private var COBDisplayRangePoints: [ChartPoint] = [0, 10].map { + return ChartPoint( + x: ChartAxisValue(scalar: 0), + y: ChartAxisValueInt($0) + ) + } + private var dosePoints: [ChartPoint] = [] { didSet { doseChart = nil @@ -239,7 +255,7 @@ final class StatusChartsManager { private var xAxisValues: [ChartAxisValue]? { didSet { - if let xAxisValues = xAxisValues { + if let xAxisValues = xAxisValues, xAxisValues.count > 1 { xAxisModel = ChartAxisModel(axisValues: xAxisValues, lineColor: axisLineColor) } else { xAxisModel = nil @@ -280,12 +296,16 @@ final class StatusChartsManager { } private func generateGlucoseChartWithFrame(_ frame: CGRect) -> Chart? { - guard glucosePoints.count > 1, let xAxisModel = xAxisModel else { + guard let xAxisModel = xAxisModel else { return nil } let points = glucosePoints + predictedGlucosePoints + targetGlucosePoints + targetOverridePoints + glucoseDisplayRangePoints + guard points.count > 1 else { + return nil + } + let yAxisValues = ChartAxisValuesGenerator.generateYAxisValuesWithChartPoints(points, minSegmentCount: 2, maxSegmentCount: 4, @@ -393,7 +413,7 @@ final class StatusChartsManager { } private func generateIOBChartWithFrame(_ frame: CGRect) -> Chart? { - guard IOBPoints.count > 1, let xAxisModel = xAxisModel else { + guard let xAxisModel = xAxisModel else { return nil } @@ -408,7 +428,7 @@ final class StatusChartsManager { containerPoints.append(ChartPoint(x: last.x, y: ChartAxisValueInt(0))) } - let yAxisValues = ChartAxisValuesGenerator.generateYAxisValuesWithChartPoints(IOBPoints, minSegmentCount: 2, maxSegmentCount: 3, multiple: 0.5, axisValueGenerator: { ChartAxisValueDouble($0, labelSettings: self.axisLabelSettings) }, addPaddingSegmentIfEdge: false) + let yAxisValues = ChartAxisValuesGenerator.generateYAxisValuesWithChartPoints(IOBPoints + IOBDisplayRangePoints, minSegmentCount: 2, maxSegmentCount: 3, multiple: 0.5, axisValueGenerator: { ChartAxisValueDouble($0, labelSettings: self.axisLabelSettings) }, addPaddingSegmentIfEdge: false) let yAxisModel = ChartAxisModel(axisValues: yAxisValues, lineColor: axisLineColor) @@ -420,7 +440,13 @@ final class StatusChartsManager { let lineModel = ChartLineModel(chartPoints: IOBPoints, lineColor: UIColor.IOBTintColor, lineWidth: 2, animDuration: 0, animDelay: 0) let IOBLine = ChartPointsLineLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, lineModels: [lineModel]) - let IOBArea = ChartPointsAreaLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: containerPoints, areaColor: UIColor.IOBTintColor.withAlphaComponent(0.5), animDuration: 0, animDelay: 0, addContainerPoints: false) + let iobArea: ChartPointsAreaLayer? + + if containerPoints.count > 1 { + iobArea = ChartPointsAreaLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: containerPoints, areaColor: UIColor.IOBTintColor.withAlphaComponent(0.5), animDuration: 0, animDelay: 0, addContainerPoints: false) + } else { + iobArea = nil + } // Grid lines let gridLayer = ChartGuideLinesLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, axis: .xAndY, settings: guideLinesLayerSettings, onlyVisibleX: true, onlyVisibleY: false) @@ -452,7 +478,7 @@ final class StatusChartsManager { yAxis, zeroGuidelineLayer, IOBChartCache?.highlightLayer, - IOBArea, + iobArea, IOBLine, ] @@ -472,7 +498,7 @@ final class StatusChartsManager { } private func generateCOBChartWithFrame(_ frame: CGRect) -> Chart? { - guard COBPoints.count > 1, let xAxisModel = xAxisModel else { + guard let xAxisModel = xAxisModel else { return nil } @@ -487,7 +513,7 @@ final class StatusChartsManager { containerPoints.append(ChartPoint(x: last.x, y: ChartAxisValueInt(0))) } - let yAxisValues = ChartAxisValuesGenerator.generateYAxisValuesWithChartPoints(COBPoints, minSegmentCount: 2, maxSegmentCount: 3, multiple: 10, axisValueGenerator: { ChartAxisValueDouble($0, labelSettings: self.axisLabelSettings) }, addPaddingSegmentIfEdge: false) + let yAxisValues = ChartAxisValuesGenerator.generateYAxisValuesWithChartPoints(COBPoints + COBDisplayRangePoints, minSegmentCount: 2, maxSegmentCount: 3, multiple: 10, axisValueGenerator: { ChartAxisValueDouble($0, labelSettings: self.axisLabelSettings) }, addPaddingSegmentIfEdge: false) let yAxisModel = ChartAxisModel(axisValues: yAxisValues, lineColor: axisLineColor) @@ -540,11 +566,11 @@ final class StatusChartsManager { } private func generateDoseChartWithFrame(_ frame: CGRect) -> Chart? { - guard dosePoints.count > 1, let xAxisModel = xAxisModel else { + guard let xAxisModel = xAxisModel else { return nil } - let yAxisValues = ChartAxisValuesGenerator.generateYAxisValuesWithChartPoints(dosePoints, minSegmentCount: 2, maxSegmentCount: 3, multiple: log10(2) / 2, axisValueGenerator: { ChartAxisValueDoubleLog(screenLocDouble: $0, formatter: self.integerFormatter, labelSettings: self.axisLabelSettings) }, addPaddingSegmentIfEdge: true) + let yAxisValues = ChartAxisValuesGenerator.generateYAxisValuesWithChartPoints(dosePoints + IOBDisplayRangePoints, minSegmentCount: 2, maxSegmentCount: 3, multiple: log10(2) / 2, axisValueGenerator: { ChartAxisValueDoubleLog(screenLocDouble: $0, formatter: self.integerFormatter, labelSettings: self.axisLabelSettings) }, addPaddingSegmentIfEdge: true) let yAxisModel = ChartAxisModel(axisValues: yAxisValues, lineColor: axisLineColor) @@ -556,7 +582,13 @@ final class StatusChartsManager { let lineModel = ChartLineModel(chartPoints: dosePoints, lineColor: UIColor.doseTintColor, lineWidth: 2, animDuration: 0, animDelay: 0) let doseLine = ChartPointsLineLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, lineModels: [lineModel]) - let doseArea = ChartPointsAreaLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: dosePoints, areaColor: UIColor.doseTintColor.withAlphaComponent(0.5), animDuration: 0, animDelay: 0, addContainerPoints: false) + let doseArea: ChartPointsAreaLayer? + + if dosePoints.count > 1 { + doseArea = ChartPointsAreaLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: dosePoints, areaColor: UIColor.doseTintColor.withAlphaComponent(0.5), animDuration: 0, animDelay: 0, addContainerPoints: false) + } else { + doseArea = nil + } // Grid lines let gridLayer = ChartGuideLinesLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, axis: .xAndY, settings: guideLinesLayerSettings, onlyVisibleX: true, onlyVisibleY: false) From b5ea9bbb6643bc79374d5fc689de664ceea94606 Mon Sep 17 00:00:00 2001 From: Nathan Racklyeft Date: Thu, 22 Sep 2016 20:14:10 -0700 Subject: [PATCH 2/2] Adding graph titles. Fixes #180 Still more cleanup work to do here, though. --- Loop/Base.lproj/Main.storyboard | 48 +++++++++++-------- Loop/Managers/StatusChartManager.swift | 2 +- .../PredictionTableViewController.swift | 1 + .../StatusTableViewController.swift | 12 +++-- Loop/Views/ChartTableViewCell.swift | 6 +-- 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/Loop/Base.lproj/Main.storyboard b/Loop/Base.lproj/Main.storyboard index f8dea28abc..12c4052272 100644 --- a/Loop/Base.lproj/Main.storyboard +++ b/Loop/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - - + + @@ -18,10 +18,10 @@ - + - + - + - + - - + + - + + - + + + + @@ -620,7 +628,7 @@ - +