Browse Source

fix slider

polscm32 1 năm trước cách đây
mục cha
commit
8e8b1779ee

+ 60 - 60
Trio/Sources/Modules/Main/View/OnboardingSteps/BasalProfileStepView.swift

@@ -49,9 +49,9 @@ struct BasalProfileStepView: View {
                             .font(.headline)
                             .padding(.horizontal)
 
-//                        basalProfileChart
-//                            .frame(height: 180)
-//                            .padding(.horizontal)
+                        basalProfileChart
+                            .frame(height: 180)
+                            .padding(.horizontal)
                     }
                     .padding(.vertical, 5)
                     .background(Color.purple.opacity(0.05))
@@ -332,61 +332,61 @@ struct BasalProfileStepView: View {
     }
 
     // Chart for visualizing basal profile
-//    private var basalProfileChart: some View {
-//        Chart {
-//            ForEach(Array(onboardingData.basalProfileItems.enumerated()), id: \.element.id) { index, item in
-//                let displayValue = onboardingData.basalProfileRateValues[item.rateIndex]
-//
-//                let tzOffset = TimeZone.current.secondsFromGMT() * -1
-//                let startDate = Date(timeIntervalSinceReferenceDate: onboardingData.basalProfileTimeValues[item.timeIndex])
-//                    .addingTimeInterval(TimeInterval(tzOffset))
-//                let endDate = onboardingData.basalProfileItems.count > index + 1 ?
-//                    Date(
-//                        timeIntervalSinceReferenceDate: onboardingData
-//                            .basalProfileTimeValues[onboardingData.basalProfileItems[index + 1].timeIndex]
-//                    )
-//                    .addingTimeInterval(TimeInterval(tzOffset)) :
-//                    Date(timeIntervalSinceReferenceDate: onboardingData.basalProfileTimeValues.last!).addingTimeInterval(30 * 60)
-//                    .addingTimeInterval(TimeInterval(tzOffset))
-//
-//                RectangleMark(
-//                    xStart: .value("start", startDate),
-//                    xEnd: .value("end", endDate),
-//                    yStart: .value("rate-start", displayValue),
-//                    yEnd: .value("rate-end", 0)
-//                ).foregroundStyle(
-//                    .linearGradient(
-//                        colors: [
-//                            Color.purple.opacity(0.6),
-//                            Color.purple.opacity(0.1)
-//                        ],
-//                        startPoint: .bottom,
-//                        endPoint: .top
-//                    )
-//                ).alignsMarkStylesWithPlotArea()
-//
-//                LineMark(x: .value("End Date", startDate), y: .value("Ratio", displayValue))
-//                    .lineStyle(.init(lineWidth: 1)).foregroundStyle(Color.purple)
-//
-//                LineMark(x: .value("Start Date", endDate), y: .value("Ratio", displayValue))
-//                    .lineStyle(.init(lineWidth: 1)).foregroundStyle(Color.purple)
-//            }
-//        }
-//        .chartXAxis {
-//            AxisMarks(values: .automatic(desiredCount: 6)) { _ in
-//                AxisValueLabel(format: .dateTime.hour())
-//                AxisGridLine(centered: true, stroke: StrokeStyle(lineWidth: 1, dash: [2, 4]))
-//            }
-//        }
-//        .chartXScale(
-//            domain: Calendar.current.startOfDay(for: chartScale!) ... Calendar.current.startOfDay(for: chartScale!)
-//                .addingTimeInterval(60 * 60 * 24)
-//        )
-//        .chartYAxis {
-//            AxisMarks(values: .automatic(desiredCount: 4)) { _ in
-//                AxisValueLabel()
-//                AxisGridLine(centered: true, stroke: StrokeStyle(lineWidth: 1, dash: [2, 4]))
-//            }
-//        }
-//    }
+    private var basalProfileChart: some View {
+        Chart {
+            ForEach(Array(onboardingData.basalProfileItems.enumerated()), id: \.element.id) { index, item in
+                let displayValue = onboardingData.basalProfileRateValues[item.rateIndex]
+
+                let tzOffset = TimeZone.current.secondsFromGMT() * -1
+                let startDate = Date(timeIntervalSinceReferenceDate: onboardingData.basalProfileTimeValues[item.timeIndex])
+                    .addingTimeInterval(TimeInterval(tzOffset))
+                let endDate = onboardingData.basalProfileItems.count > index + 1 ?
+                    Date(
+                        timeIntervalSinceReferenceDate: onboardingData
+                            .basalProfileTimeValues[onboardingData.basalProfileItems[index + 1].timeIndex]
+                    )
+                    .addingTimeInterval(TimeInterval(tzOffset)) :
+                    Date(timeIntervalSinceReferenceDate: onboardingData.basalProfileTimeValues.last!).addingTimeInterval(30 * 60)
+                    .addingTimeInterval(TimeInterval(tzOffset))
+
+                RectangleMark(
+                    xStart: .value("start", startDate),
+                    xEnd: .value("end", endDate),
+                    yStart: .value("rate-start", displayValue),
+                    yEnd: .value("rate-end", 0)
+                ).foregroundStyle(
+                    .linearGradient(
+                        colors: [
+                            Color.purple.opacity(0.6),
+                            Color.purple.opacity(0.1)
+                        ],
+                        startPoint: .bottom,
+                        endPoint: .top
+                    )
+                ).alignsMarkStylesWithPlotArea()
+
+                LineMark(x: .value("End Date", startDate), y: .value("Rate", displayValue))
+                    .lineStyle(.init(lineWidth: 1)).foregroundStyle(Color.purple)
+
+                LineMark(x: .value("Start Date", endDate), y: .value("Rate", displayValue))
+                    .lineStyle(.init(lineWidth: 1)).foregroundStyle(Color.purple)
+            }
+        }
+        .chartXAxis {
+            AxisMarks(values: .automatic(desiredCount: 6)) { _ in
+                AxisValueLabel(format: .dateTime.hour())
+                AxisGridLine(centered: true, stroke: StrokeStyle(lineWidth: 1, dash: [2, 4]))
+            }
+        }
+        .chartXScale(
+            domain: Calendar.current.startOfDay(for: chartScale!) ... Calendar.current.startOfDay(for: chartScale!)
+                .addingTimeInterval(60 * 60 * 24)
+        )
+        .chartYAxis {
+            AxisMarks(values: .automatic(desiredCount: 4)) { _ in
+                AxisValueLabel()
+                AxisGridLine(centered: true, stroke: StrokeStyle(lineWidth: 1, dash: [2, 4]))
+            }
+        }
+    }
 }

+ 1 - 1
Trio/Sources/Modules/Onboarding/Model.swift

@@ -119,7 +119,7 @@ enum OnboardingStep: Int, CaseIterable, Identifiable {
     var initialBasalProfileItems: [BasalProfileEditor.Item] = []
     var basalProfileItems: [BasalProfileEditor.Item] = []
     let basalProfileTimeValues = stride(from: 0.0, to: 1.days.timeInterval, by: 30.minutes.timeInterval).map { $0 }
-    private(set) var basalProfileRateValues: [Decimal] = []
+    var basalProfileRateValues: [Decimal] = stride(from: 0.05, to: 3.05, by: 0.05).map { Decimal($0) }
 
     // Glucose Target
     var targetLow: Decimal = 70