DummyCharts.swift 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if thresholdLines {
  10. let highColor = FreeAPS.getDynamicGlucoseColor(
  11. glucoseValue: highGlucose,
  12. highGlucoseColorValue: highGlucose,
  13. lowGlucoseColorValue: highGlucose,
  14. targetGlucose: units == .mgdL ? currentGlucoseTarget : currentGlucoseTarget.asMmolL,
  15. glucoseColorScheme: glucoseColorScheme,
  16. offset: units == .mgdL ? Decimal(20) : Decimal(20).asMmolL
  17. )
  18. let lowColor = FreeAPS.getDynamicGlucoseColor(
  19. glucoseValue: lowGlucose,
  20. highGlucoseColorValue: highGlucose,
  21. lowGlucoseColorValue: lowGlucose,
  22. targetGlucose: units == .mgdL ? currentGlucoseTarget : currentGlucoseTarget.asMmolL,
  23. glucoseColorScheme: glucoseColorScheme,
  24. offset: units == .mgdL ? Decimal(20) : Decimal(20).asMmolL
  25. )
  26. RuleMark(y: .value("High", highGlucose))
  27. .foregroundStyle(highColor)
  28. .lineStyle(.init(lineWidth: 1, dash: [5]))
  29. RuleMark(y: .value("Low", lowGlucose))
  30. .foregroundStyle(lowColor)
  31. .lineStyle(.init(lineWidth: 1, dash: [5]))
  32. }
  33. }
  34. .id("DummyMainChart")
  35. .frame(minHeight: geo.size.height * 0.28)
  36. .frame(width: screenSize.width - 10)
  37. .chartXAxis { mainChartXAxis }
  38. .chartXScale(domain: startMarker ... endMarker)
  39. .chartXAxis(.hidden)
  40. .chartYAxis { mainChartYAxis }
  41. .chartYScale(
  42. domain: units == .mgdL ? state.minYAxisValue ... state.maxYAxisValue : state.minYAxisValue.asMmolL ... state
  43. .maxYAxisValue.asMmolL
  44. )
  45. .chartLegend(.hidden)
  46. }
  47. var dummyBasalChart: some View {
  48. Chart {}
  49. .id("DummyBasalChart")
  50. .frame(minHeight: geo.size.height * 0.05)
  51. .frame(width: screenSize.width - 10)
  52. .chartXAxis { basalChartXAxis }
  53. .chartXAxis(.hidden)
  54. .chartYAxis(.hidden)
  55. .chartLegend(.hidden)
  56. }
  57. var dummyCobChart: some View {
  58. Chart {
  59. drawCOB(dummy: true)
  60. }
  61. .id("DummyCobChart")
  62. .frame(minHeight: geo.size.height * 0.12)
  63. .frame(width: screenSize.width - 10)
  64. .chartXScale(domain: startMarker ... endMarker)
  65. .chartXAxis { basalChartXAxis }
  66. .chartXAxis(.hidden)
  67. .chartYAxis { cobChartYAxis }
  68. .chartYAxis(.hidden)
  69. .chartYScale(domain: state.minValueCobChart ... state.maxValueCobChart)
  70. .chartLegend(.hidden)
  71. }
  72. }