GraphSettingsView.swift 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // LoopFollow
  2. // GraphSettingsView.swift
  3. import SwiftUI
  4. struct GraphSettingsView: View {
  5. @ObservedObject private var showDots = Storage.shared.showDots
  6. @ObservedObject private var showLines = Storage.shared.showLines
  7. @ObservedObject private var showValues = Storage.shared.showValues
  8. @ObservedObject private var showAbsorption = Storage.shared.showAbsorption
  9. @ObservedObject private var showDIALines = Storage.shared.showDIALines
  10. @ObservedObject private var show30MinLine = Storage.shared.show30MinLine
  11. @ObservedObject private var show90MinLine = Storage.shared.show90MinLine
  12. @ObservedObject private var showMidnightLines = Storage.shared.showMidnightLines
  13. @ObservedObject private var showYesterdayLine = Storage.shared.showYesterdayLine
  14. @ObservedObject private var smallGraphTreatments = Storage.shared.smallGraphTreatments
  15. @ObservedObject private var smallGraphHeight = Storage.shared.smallGraphHeight
  16. @ObservedObject private var predictionToLoad = Storage.shared.predictionToLoad
  17. @ObservedObject private var predictionDisplayType = Storage.shared.predictionDisplayType
  18. @ObservedObject private var minBasalScale = Storage.shared.minBasalScale
  19. @ObservedObject private var minBGScale = Storage.shared.minBGScale
  20. @ObservedObject private var downloadDays = Storage.shared.downloadDays
  21. private var nightscoutEnabled: Bool { IsNightscoutEnabled() }
  22. var body: some View {
  23. Form {
  24. // ── Graph Display ────────────────────────────────────────────
  25. Section("Graph Display") {
  26. Toggle("Display Dots", isOn: $showDots.value)
  27. .onChange(of: showDots.value) { _ in markDirty() }
  28. Toggle("Display Lines", isOn: $showLines.value)
  29. .onChange(of: showLines.value) { _ in markDirty() }
  30. if nightscoutEnabled {
  31. Toggle("Show DIA Lines", isOn: $showDIALines.value)
  32. .onChange(of: showDIALines.value) { _ in markDirty() }
  33. Toggle("Show −30 min Line", isOn: $show30MinLine.value)
  34. .onChange(of: show30MinLine.value) { _ in markDirty() }
  35. Toggle("Show −90 min Line", isOn: $show90MinLine.value)
  36. .onChange(of: show90MinLine.value) { _ in markDirty() }
  37. Toggle("Show Yesterday's BG", isOn: $showYesterdayLine.value)
  38. .onChange(of: showYesterdayLine.value) { _ in markDirty() }
  39. }
  40. Toggle("Show Midnight Lines", isOn: $showMidnightLines.value)
  41. .onChange(of: showMidnightLines.value) { _ in markDirty() }
  42. }
  43. // ── Treatments ───────────────────────────────────────────────
  44. if nightscoutEnabled {
  45. Section("Treatments") {
  46. Toggle("Show Carb/Bolus Values", isOn: $showValues.value)
  47. Toggle("Show Carb Absorption", isOn: $showAbsorption.value)
  48. Toggle("Treatments on Small Graph",
  49. isOn: $smallGraphTreatments.value)
  50. }
  51. }
  52. // ── Small Graph ──────────────────────────────────────────────
  53. Section("Small Graph") {
  54. SettingsStepperRow(
  55. title: "Height",
  56. range: 40 ... 80,
  57. step: 5,
  58. value: $smallGraphHeight.value,
  59. format: { "\(Int($0)) pt" }
  60. )
  61. .onChange(of: smallGraphHeight.value) { _ in markDirty() }
  62. }
  63. // ── Prediction ───────────────────────────────────────────────
  64. if nightscoutEnabled {
  65. Section("Prediction") {
  66. SettingsStepperRow(
  67. title: "Hours of Prediction",
  68. range: 0 ... 6,
  69. step: 0.25,
  70. value: $predictionToLoad.value,
  71. format: { "\($0.localized(maxFractionDigits: 2)) h" }
  72. )
  73. if Storage.shared.device.value != "Loop" {
  74. Picker("Prediction Style", selection: $predictionDisplayType.value) {
  75. ForEach(PredictionDisplayType.allCases, id: \.self) { type in
  76. Text(type.displayName).tag(type)
  77. }
  78. }
  79. .onChange(of: predictionDisplayType.value) { _ in markDirty() }
  80. }
  81. }
  82. }
  83. // ── Basal / BG scale ─────────────────────────────────────────
  84. if nightscoutEnabled {
  85. Section("Basal / BG Scale") {
  86. SettingsStepperRow(
  87. title: "Min Basal",
  88. range: 0.5 ... 20,
  89. step: 0.5,
  90. value: $minBasalScale.value,
  91. format: { "\($0.localized(maxFractionDigits: 1)) U/h" }
  92. )
  93. BGPicker(
  94. title: "Min BG Scale",
  95. range: 40 ... 400,
  96. value: $minBGScale.value
  97. )
  98. .onChange(of: minBGScale.value) { _ in markDirty() }
  99. }
  100. }
  101. // ── History window ───────────────────────────────────────────
  102. if nightscoutEnabled {
  103. Section("History") {
  104. SettingsStepperRow(
  105. title: "Show Days Back",
  106. range: 1 ... 4,
  107. step: 1,
  108. value: $downloadDays.value,
  109. format: { "\(Int($0)) d" }
  110. )
  111. }
  112. }
  113. }
  114. .preferredColorScheme(Storage.shared.appearanceMode.value.colorScheme)
  115. .navigationBarTitle("Graph Settings", displayMode: .inline)
  116. }
  117. /// Marks the chart as needing a redraw
  118. private func markDirty() {
  119. Observable.shared.chartSettingsChanged.value = true
  120. }
  121. }