|
|
@@ -8,15 +8,30 @@ struct MainChartView2: View {
|
|
|
@Binding var highGlucose: Decimal
|
|
|
@Binding var lowGlucose: Decimal
|
|
|
@Binding var carbs: [CarbsEntry]
|
|
|
+ @Binding var basalProfile: [BasalProfileEntry]
|
|
|
|
|
|
var body: some View {
|
|
|
VStack(alignment: .center, spacing: 8, content: {
|
|
|
- GlucoseChart(glucose: $glucose, screenHours: $screenHours, highGlucose: $highGlucose, lowGlucose: $lowGlucose)
|
|
|
- .padding(.bottom, 20)
|
|
|
- CarbsChart(carbs: $carbs, screenHours: $screenHours)
|
|
|
- .padding(.bottom, 8)
|
|
|
+ ZStack {
|
|
|
+ GlucoseChart(glucose: $glucose, screenHours: $screenHours, highGlucose: $highGlucose, lowGlucose: $lowGlucose)
|
|
|
+ VStack {
|
|
|
+ Spacer()
|
|
|
+ .frame(height: 280)
|
|
|
+ CarbsChart(carbs: $carbs, screenHours: $screenHours)
|
|
|
+ }
|
|
|
+ }
|
|
|
+// GlucoseChart(glucose: $glucose, screenHours: $screenHours, highGlucose: $highGlucose, lowGlucose: $lowGlucose)
|
|
|
+// .padding(.bottom, 20)
|
|
|
+// CarbsChart(carbs: $carbs, screenHours: $screenHours)
|
|
|
+// .padding(.bottom, 8)
|
|
|
+
|
|
|
BasalChart(tempBasals: $tempBasals, screenHours: $screenHours)
|
|
|
.padding(.bottom, 8)
|
|
|
+
|
|
|
+// ZStack {
|
|
|
+// BasalChart(tempBasals: $tempBasals, basalProfile: $basalProfile, screenHours: $screenHours)
|
|
|
+// BasalProfileChart(basalProfile: $basalProfile)
|
|
|
+// }
|
|
|
Legend()
|
|
|
})
|
|
|
}
|
|
|
@@ -44,6 +59,7 @@ struct GlucoseChart: View {
|
|
|
.lineStyle(StrokeStyle(lineWidth: 1, dash: [5]))
|
|
|
|
|
|
// MARK: TO DO -> at the moment this rule mark is not visible because the chart is not scrollable
|
|
|
+
|
|
|
if let currentTime = getCurrentTime() {
|
|
|
RuleMark(x: .value("Current Time", currentTime))
|
|
|
.foregroundStyle(Color.gray)
|
|
|
@@ -92,6 +108,7 @@ struct BasalChart: View {
|
|
|
var body: some View {
|
|
|
VStack {
|
|
|
let filteredBasal: [PumpHistoryEvent] = filterBasalData(for: screenHours)
|
|
|
+
|
|
|
Chart(filteredBasal) {
|
|
|
BarMark(
|
|
|
x: .value("Time", $0.timestamp),
|
|
|
@@ -101,8 +118,8 @@ struct BasalChart: View {
|
|
|
.cornerRadius(0)
|
|
|
}
|
|
|
.frame(height: 80)
|
|
|
-// .rotationEffect(.degrees(180))
|
|
|
-// .chartXAxis(.hidden)
|
|
|
+ // .rotationEffect(.degrees(180))
|
|
|
+ // .chartXAxis(.hidden)
|
|
|
.chartYAxis(.hidden)
|
|
|
.chartPlotStyle { plotArea in
|
|
|
plotArea.background(.blue.gradient.opacity(0.1))
|
|
|
@@ -122,21 +139,72 @@ struct BasalChart: View {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+struct BasalProfileChart: View {
|
|
|
+ @Binding var basalProfile: [BasalProfileEntry]
|
|
|
+ @Binding var screenHours: Int16
|
|
|
+
|
|
|
+ var body: some View {
|
|
|
+ let filteredBasalProfile: [BasalProfileEntry] = filterBasalProfileData(for: screenHours)
|
|
|
+
|
|
|
+ VStack {
|
|
|
+// MARK: DOES NOT WORK
|
|
|
+
|
|
|
+// filtering function seems not to work...displays nothing
|
|
|
+
|
|
|
+ Chart(filteredBasalProfile) {
|
|
|
+ LineMark(
|
|
|
+ x: .value("start", $0.minutes),
|
|
|
+ y: .value("rate", $0.rate)
|
|
|
+ ).foregroundStyle(Color.blue.gradient)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func filterBasalProfileData(for hours: Int16) -> [BasalProfileEntry] {
|
|
|
+ guard hours > 0 else {
|
|
|
+ return basalProfile
|
|
|
+ }
|
|
|
+
|
|
|
+ let currentDate = Date()
|
|
|
+ let startDate = Calendar.current.date(byAdding: .hour, value: -Int(hours), to: currentDate) ?? currentDate
|
|
|
+
|
|
|
+ return basalProfile.filter { entry in
|
|
|
+ if let entryDate = dateFormatter.date(from: entry.start) {
|
|
|
+ return entryDate >= startDate
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private let dateFormatter: DateFormatter = {
|
|
|
+ let formatter = DateFormatter()
|
|
|
+ formatter.dateFormat = "HH:mm:ss"
|
|
|
+ return formatter
|
|
|
+ }()
|
|
|
+}
|
|
|
+
|
|
|
// MARK: COB
|
|
|
|
|
|
struct CarbsChart: View {
|
|
|
@Binding var carbs: [CarbsEntry]
|
|
|
@Binding var screenHours: Int16
|
|
|
+ static var triangle: BasicChartSymbolShape { .triangle }
|
|
|
|
|
|
var body: some View {
|
|
|
VStack {
|
|
|
+// MARK: DOES NOT WORK PROPERLY
|
|
|
+// scaling is not correct because of swift charts automatic scaling...
|
|
|
+
|
|
|
let filteredCarbs: [CarbsEntry] = filterCarbData(for: screenHours)
|
|
|
Chart(filteredCarbs) {
|
|
|
PointMark(
|
|
|
x: .value("Time", $0.createdAt),
|
|
|
- y: .value("Value", 40)
|
|
|
+ y: .value("Value", 10)
|
|
|
)
|
|
|
.foregroundStyle(Color.loopYellow.gradient)
|
|
|
+ .symbolSize(50)
|
|
|
+ .symbol(CarbsChart.triangle)
|
|
|
}
|
|
|
.frame(height: 80)
|
|
|
.chartYAxis(.hidden)
|