DummyCharts.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import Charts
  2. import Foundation
  3. import SwiftUI
  4. extension MainChartView {
  5. /// empty chart that just shows the Y axis and Y grid lines. Created separately from `mainChart` to allow main chart to scroll horizontally while having a fixed Y axis
  6. var staticYAxisChart: some View {
  7. Chart {
  8. /// high and low threshold lines
  9. // TODO: workaround for now: set low value to 55, to have dynamic color shades between 55 and user-set low (approx. 70); same for high glucose
  10. let hardCodedLow = Decimal(55)
  11. let hardCodedHigh = Decimal(220)
  12. let isDynamicColorScheme = glucoseColorScheme == .dynamicColor
  13. if thresholdLines {
  14. let highColor = FreeAPS.getDynamicGlucoseColor(
  15. glucoseValue: highGlucose,
  16. highGlucoseColorValue: isDynamicColorScheme ? hardCodedHigh : highGlucose,
  17. lowGlucoseColorValue: isDynamicColorScheme ? hardCodedLow : lowGlucose,
  18. targetGlucose: currentGlucoseTarget,
  19. glucoseColorScheme: glucoseColorScheme
  20. )
  21. let lowColor = FreeAPS.getDynamicGlucoseColor(
  22. glucoseValue: lowGlucose,
  23. highGlucoseColorValue: isDynamicColorScheme ? hardCodedHigh : highGlucose,
  24. lowGlucoseColorValue: isDynamicColorScheme ? hardCodedLow : lowGlucose,
  25. targetGlucose: currentGlucoseTarget,
  26. glucoseColorScheme: glucoseColorScheme
  27. )
  28. RuleMark(y: .value("High", units == .mgdL ? highGlucose : highGlucose.asMmolL))
  29. .foregroundStyle(highColor)
  30. .lineStyle(.init(lineWidth: 1, dash: [5]))
  31. RuleMark(y: .value("Low", units == .mgdL ? lowGlucose : lowGlucose.asMmolL))
  32. .foregroundStyle(lowColor)
  33. .lineStyle(.init(lineWidth: 1, dash: [5]))
  34. }
  35. }
  36. .id("DummyMainChart")
  37. .frame(minHeight: geo.size.height * 0.28)
  38. .frame(width: screenSize.width - 10)
  39. .chartXAxis { mainChartXAxis }
  40. .chartXScale(domain: startMarker ... endMarker)
  41. .chartXAxis(.hidden)
  42. .chartYAxis { mainChartYAxis }
  43. .chartYScale(
  44. domain: units == .mgdL ? state.minYAxisValue ... state.maxYAxisValue : state.minYAxisValue.asMmolL ... state
  45. .maxYAxisValue.asMmolL
  46. )
  47. .chartLegend(.hidden)
  48. }
  49. var dummyBasalChart: some View {
  50. Chart {}
  51. .id("DummyBasalChart")
  52. .frame(minHeight: geo.size.height * 0.05)
  53. .frame(width: screenSize.width - 10)
  54. .chartXAxis { basalChartXAxis }
  55. .chartXAxis(.hidden)
  56. .chartYAxis(.hidden)
  57. .chartLegend(.hidden)
  58. }
  59. var dummyCobChart: some View {
  60. Chart {
  61. drawCOB(dummy: true)
  62. }
  63. .id("DummyCobChart")
  64. .frame(minHeight: geo.size.height * 0.12)
  65. .frame(width: screenSize.width - 10)
  66. .chartXScale(domain: startMarker ... endMarker)
  67. .chartXAxis { basalChartXAxis }
  68. .chartXAxis(.hidden)
  69. .chartYAxis { cobChartYAxis }
  70. .chartYAxis(.hidden)
  71. .chartYScale(domain: state.minValueCobChart ... state.maxValueCobChart)
  72. .chartLegend(.hidden)
  73. }
  74. }