switched startdate and enddate, enddate is always current date

This commit is contained in:
Johan Degraeve 2019-10-26 12:06:40 +02:00
parent 82aa163cc3
commit e22b8bcc1a
3 changed files with 32 additions and 19 deletions

View File

@ -19,6 +19,7 @@
F804870C2336D90200EBDDB7 /* M5Stack+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = F804870A2336D90200EBDDB7 /* M5Stack+CoreDataClass.swift */; };
F804870D2336D90200EBDDB7 /* M5Stack+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = F804870B2336D90200EBDDB7 /* M5Stack+CoreDataProperties.swift */; };
F80610C4222D4E4D00D8F236 /* ActionClosureable-extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F80610C3222D4E4D00D8F236 /* ActionClosureable-extension.swift */; };
F80859272364355F00F3829D /* ConstantsGlucoseChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = F80859262364355F00F3829D /* ConstantsGlucoseChart.swift */; };
F81D6D4822BD5F62005EFAE2 /* DexcomShareUploadManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F81D6D4722BD5F62005EFAE2 /* DexcomShareUploadManager.swift */; };
F81D6D4E22BFC762005EFAE2 /* TextsDexcomShareTestResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = F81D6D4D22BFC762005EFAE2 /* TextsDexcomShareTestResult.swift */; };
F81D6D5222C27F18005EFAE2 /* BgReading+DexcomShare.swift in Sources */ = {isa = PBXBuildFile; fileRef = F81D6D5122C27F18005EFAE2 /* BgReading+DexcomShare.swift */; };
@ -270,6 +271,7 @@
F804870A2336D90200EBDDB7 /* M5Stack+CoreDataClass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "M5Stack+CoreDataClass.swift"; sourceTree = "<group>"; };
F804870B2336D90200EBDDB7 /* M5Stack+CoreDataProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "M5Stack+CoreDataProperties.swift"; sourceTree = "<group>"; };
F80610C3222D4E4D00D8F236 /* ActionClosureable-extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ActionClosureable-extension.swift"; sourceTree = "<group>"; };
F80859262364355F00F3829D /* ConstantsGlucoseChart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantsGlucoseChart.swift; sourceTree = "<group>"; };
F81D6D4522B67F55005EFAE2 /* pt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pt; path = pt.lproj/SpeakReading.strings; sourceTree = "<group>"; };
F81D6D4722BD5F62005EFAE2 /* DexcomShareUploadManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DexcomShareUploadManager.swift; sourceTree = "<group>"; };
F81D6D4D22BFC762005EFAE2 /* TextsDexcomShareTestResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextsDexcomShareTestResult.swift; sourceTree = "<group>"; };
@ -1405,6 +1407,7 @@
F8A1587022EDC865007F5B5D /* ConstantsSpeakReadingLanguages.swift */,
F8A1586E22EDC7EE007F5B5D /* ConstantsSuspensionPrevention.swift */,
F8A389EC23342EB10010F405 /* ConstantsNightScout.swift */,
F80859262364355F00F3829D /* ConstantsGlucoseChart.swift */,
);
name = Constants;
path = xdrip/Constants;
@ -1843,6 +1846,7 @@
F8A54ADC22D911BA00934E7A /* AuthChallengeTxMessage.swift in Sources */,
F8BECB33235E64530060DAE1 /* TimeZone.swift in Sources */,
F8025C1321DA683400ECF0C0 /* Data.swift in Sources */,
F80859272364355F00F3829D /* ConstantsGlucoseChart.swift in Sources */,
F85DC2EF21CFE2F500B9F74A /* Sensor+CoreDataProperties.swift in Sources */,
F8A54AFA22D9156600934E7A /* CGMMiaoMiaoTransmitter.swift in Sources */,
F8BECB02235CE3E20060DAE1 /* BloodGlucoseChartView.swift in Sources */,

View File

@ -0,0 +1,8 @@
import Foundation
enum ConstantsGlucoseChart {
// default value for chart width in hours
static let defaultChartWidthInHours = 6.0;
}

View File

@ -15,22 +15,6 @@ public final class StatusChartsManager {
return chartSettings.leading + chartSettings.trailing + labelsWidthY + chartSettings.labelsToAxisSpacingY
}
/// The earliest date on the X-axis
public var startDate = Date() {
didSet {
if startDate != oldValue {
trace("New chart start date: %@", log: self.log, type: .info, String(describing: startDate))
xAxisValues = nil
// Set a new minimum end date
endDate = startDate.addingTimeInterval(.hours(3))
}
}
}
public var gestureRecognizer: UIGestureRecognizer?
/// The latest allowed date on the X-axis
@ -115,14 +99,30 @@ public final class StatusChartsManager {
didSet {
if endDate != oldValue {
trace("New chart end date: %@", log: self.log, type: .info, String(describing: endDate))
trace("New chart enddate: %@", log: self.log, type: .info, String(describing: endDate))
xAxisValues = nil
// Set a new startdate
startDate = endDate.addingTimeInterval(.hours(-ConstantsGlucoseChart.defaultChartWidthInHours))
}
}
}
/// The earliest date on the X-axis
private var startDate = Date() {
didSet {
if startDate != oldValue {
trace("New chart startdate: %@", log: self.log, type: .info, String(describing: startDate))
xAxisValues = nil
}
}
}
/// A ChartAxisValue models a value along a particular chart axis. For example, two ChartAxisValues represent the two components of a ChartPoint. It has a backing Double scalar value, which provides a canonical form for all subclasses to be laid out along an axis. It also has one or more labels that are drawn in the chart.
///
/// see https://github.com/i-schuetz/SwiftCharts/blob/ec538d027d6d4c64028d85f86d3d72fcda41c016/SwiftCharts/AxisValues/ChartAxisValue.swift#L12, is not meant to be instantiated
@ -193,7 +193,6 @@ public final class StatusChartsManager {
y: ChartAxisValueDouble($0.1)
)
}
}
@ -322,6 +321,7 @@ public final class StatusChartsManager {
let timeFormatter = DateFormatter()
timeFormatter.dateFormat = "h a"
/// the startdate and the enddate as ChartPoint
let points = [
ChartPoint(
x: ChartAxisValueDate(date: startDate, formatter: timeFormatter),
@ -333,6 +333,7 @@ public final class StatusChartsManager {
)
]
/// how many full hours between startdate and enddate
let segments = ceil(endDate.timeIntervalSince(startDate).hours)
let xAxisValues = ChartAxisValuesStaticGenerator.generateXAxisValuesWithChartPoints(points, minSegmentCount: segments - 1, maxSegmentCount: segments + 1, multiple: TimeInterval(hours: 1), axisValueGenerator: {