Просмотр исходного кода

Uppercase Acronyms for lines in Forecast Chart

Deniz Cengiz 1 год назад
Родитель
Сommit
716836eae3

+ 1 - 1
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

@@ -201,7 +201,7 @@ extension MainChartView {
                 domain: units == .mgdL ? state.minYAxisValue ... state.maxYAxisValue : state.minYAxisValue
                     .asMmolL ... state.maxYAxisValue.asMmolL
             )
-            .backport.chartForegroundStyleScale(state: state)
+            .chartLegend(.hidden)
         }
     }
 }

+ 22 - 1
FreeAPS/Sources/Modules/Treatments/View/ForecastChart.swift

@@ -163,7 +163,28 @@ struct ForecastChart: View {
         .chartXScale(domain: startMarker ... endMarker)
         .chartYAxis { forecastChartYAxis }
         .chartYScale(domain: state.units == .mgdL ? 0 ... 300 : 0.asMmolL ... 300.asMmolL)
-        .backport.chartForegroundStyleScale(state: state)
+        .chartLegend {
+            if state.forecastDisplayType == ForecastDisplayType.lines {
+                HStack {
+                    HStack {
+                        Image(systemName: "circle.fill").foregroundStyle(Color.insulin)
+                        Text("IOB").foregroundStyle(Color.secondary)
+                    }
+                    HStack {
+                        Image(systemName: "circle.fill").foregroundStyle(Color.uam)
+                        Text("UAM").foregroundStyle(Color.secondary)
+                    }
+                    HStack {
+                        Image(systemName: "circle.fill").foregroundStyle(Color.zt)
+                        Text("ZT").foregroundStyle(Color.secondary)
+                    }
+                    HStack {
+                        Image(systemName: "circle.fill").foregroundStyle(Color.orange)
+                        Text("COB").foregroundStyle(Color.secondary)
+                    }
+                }.font(.caption2)
+            }
+        }
     }
 
     @ViewBuilder var selectionPopover: some View {

+ 0 - 25
FreeAPS/Sources/Views/ViewModifiers.swift

@@ -169,28 +169,3 @@ extension View {
 struct Backport<Content: View> {
     let content: Content
 }
-
-extension Backport {
-    @ViewBuilder func chartForegroundStyleScale(state: any StateModel) -> some View {
-        if (state as? Treatments.StateModel)?.forecastDisplayType == ForecastDisplayType.lines ||
-            (state as? Home.StateModel)?.forecastDisplayType == ForecastDisplayType.lines
-        {
-            let modifiedContent = content
-                .chartForegroundStyleScale([
-                    "iob": .blue,
-                    "uam": Color.uam,
-                    "zt": Color.zt,
-                    "cob": .orange
-                ])
-
-            if state is Home.StateModel {
-                modifiedContent
-                    .chartLegend(.hidden)
-            } else {
-                modifiedContent
-            }
-        } else {
-            content
-        }
-    }
-}