GraphSettingsView.swift 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 smallGraphTreatments = Storage.shared.smallGraphTreatments
  14. @ObservedObject private var smallGraphHeight = Storage.shared.smallGraphHeight
  15. @ObservedObject private var predictionToLoad = Storage.shared.predictionToLoad
  16. @ObservedObject private var minBasalScale = Storage.shared.minBasalScale
  17. @ObservedObject private var minBGScale = Storage.shared.minBGScale
  18. @ObservedObject private var lowLine = Storage.shared.lowLine
  19. @ObservedObject private var highLine = Storage.shared.highLine
  20. @ObservedObject private var downloadDays = Storage.shared.downloadDays
  21. private var nightscoutEnabled: Bool { IsNightscoutEnabled() }
  22. var body: some View {
  23. NavigationView {
  24. Form {
  25. // ── Graph Display ────────────────────────────────────────────
  26. Section("Graph Display") {
  27. Toggle("Display Dots", isOn: $showDots.value)
  28. .onChange(of: showDots.value) { _ in markDirty() }
  29. Toggle("Display Lines", isOn: $showLines.value)
  30. .onChange(of: showLines.value) { _ in markDirty() }
  31. if nightscoutEnabled {
  32. Toggle("Show DIA Lines", isOn: $showDIALines.value)
  33. .onChange(of: showDIALines.value) { _ in markDirty() }
  34. Toggle("Show −30 min Line", isOn: $show30MinLine.value)
  35. .onChange(of: show30MinLine.value) { _ in markDirty() }
  36. Toggle("Show −90 min Line", isOn: $show90MinLine.value)
  37. .onChange(of: show90MinLine.value) { _ in markDirty() }
  38. }
  39. Toggle("Show Midnight Lines", isOn: $showMidnightLines.value)
  40. .onChange(of: showMidnightLines.value) { _ in markDirty() }
  41. }
  42. // ── Treatments ───────────────────────────────────────────────
  43. if nightscoutEnabled {
  44. Section("Treatments") {
  45. Toggle("Show Carb/Bolus Values", isOn: $showValues.value)
  46. Toggle("Show Carb Absorption", isOn: $showAbsorption.value)
  47. Toggle("Treatments on Small Graph",
  48. isOn: $smallGraphTreatments.value)
  49. }
  50. }
  51. // ── Small Graph ──────────────────────────────────────────────
  52. Section("Small Graph") {
  53. SettingsStepperRow(
  54. title: "Height",
  55. range: 40 ... 80,
  56. step: 5,
  57. value: $smallGraphHeight.value,
  58. format: { "\(Int($0)) pt" }
  59. )
  60. .onChange(of: smallGraphHeight.value) { _ in markDirty() }
  61. }
  62. // ── Prediction ───────────────────────────────────────────────
  63. if nightscoutEnabled {
  64. Section("Prediction") {
  65. SettingsStepperRow(
  66. title: "Hours of Prediction",
  67. range: 0 ... 6,
  68. step: 0.25,
  69. value: $predictionToLoad.value,
  70. format: { "\($0.localized(maxFractionDigits: 2)) h" }
  71. )
  72. }
  73. }
  74. // ── Basal / BG scale ─────────────────────────────────────────
  75. if nightscoutEnabled {
  76. Section("Basal / BG Scale") {
  77. SettingsStepperRow(
  78. title: "Min Basal",
  79. range: 0.5 ... 20,
  80. step: 0.5,
  81. value: $minBasalScale.value,
  82. format: { "\($0.localized(maxFractionDigits: 1)) U/h" }
  83. )
  84. BGPicker(
  85. title: "Min BG Scale",
  86. range: 40 ... 400,
  87. value: $minBGScale.value
  88. )
  89. .onChange(of: minBGScale.value) { _ in markDirty() }
  90. }
  91. }
  92. // ── Target lines ─────────────────────────────────────────────
  93. Section("Target Lines") {
  94. BGPicker(title: "Low BG Line",
  95. range: 40 ... 120,
  96. value: $lowLine.value)
  97. .onChange(of: lowLine.value) { _ in markDirty() }
  98. BGPicker(title: "High BG Line",
  99. range: 120 ... 400,
  100. value: $highLine.value)
  101. .onChange(of: highLine.value) { _ in markDirty() }
  102. }
  103. // ── History window ───────────────────────────────────────────
  104. if nightscoutEnabled {
  105. Section("History") {
  106. SettingsStepperRow(
  107. title: "Show Days Back",
  108. range: 1 ... 4,
  109. step: 1,
  110. value: $downloadDays.value,
  111. format: { "\(Int($0)) d" }
  112. )
  113. }
  114. }
  115. }
  116. }
  117. .preferredColorScheme(Storage.shared.forceDarkMode.value ? .dark : nil)
  118. .navigationBarTitle("Graph Settings", displayMode: .inline)
  119. }
  120. /// Marks the chart as needing a redraw
  121. private func markDirty() {
  122. Observable.shared.chartSettingsChanged.value = true
  123. }
  124. }