Jelajahi Sumber

Fix ISF chart Y-axis label formatting for mmol/L units

During onboarding, when importing ISF settings from Nightscout, the chart
Y-axis labels were not properly formatted for mmol/L units.

Updated the Y-axis to use the existing numberFormatter which correctly
formats values based on the selected units:
- mmol/L: Shows 1 decimal place
- mg/dL: Shows no decimal places

The chart scale remains dynamic and adjusts to the data range automatically,
but now displays properly formatted axis labels matching the user's unit
preference.

Fixes #557
Sjoerd Bozon 11 bulan lalu
induk
melakukan
3b9d3a1f10

+ 7 - 3
Trio/Sources/Modules/Onboarding/View/OnboardingSteps/TherapySettings/InsulinSensitivityStepView.swift

@@ -137,7 +137,7 @@ struct InsulinSensitivityStepView: View {
     private var isfChart: some View {
         Chart {
             ForEach(Array(state.isfItems.enumerated()), id: \.element.id) { index, item in
-                let displayValue = state.isfRateValues[item.rateIndex]
+                let displayValue = state.units == .mgdL ? state.isfRateValues[item.rateIndex] : state.isfRateValues[item.rateIndex].asMmolL
 
                 let startDate = Calendar.current
                     .startOfDay(for: now)
@@ -188,8 +188,12 @@ struct InsulinSensitivityStepView: View {
                 .addingTimeInterval(60 * 60 * 24)
         )
         .chartYAxis {
-            AxisMarks(values: .automatic(desiredCount: 4)) { _ in
-                AxisValueLabel()
+            AxisMarks(values: .automatic(desiredCount: 4)) { value in
+                if let val = value.as(Double.self) {
+                    AxisValueLabel {
+                        Text(numberFormatter.string(from: NSNumber(value: val)) ?? "")
+                    }
+                }
                 AxisGridLine(centered: true, stroke: StrokeStyle(lineWidth: 1, dash: [2, 4]))
             }
         }