AGPView.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // LoopFollow
  2. // AGPView.swift
  3. import SwiftUI
  4. struct AGPView: View {
  5. @ObservedObject var viewModel: AGPViewModel
  6. var body: some View {
  7. if !viewModel.agpData.isEmpty {
  8. VStack(alignment: .leading, spacing: 8) {
  9. Text("Ambulatory Glucose Profile (AGP)")
  10. .font(.caption)
  11. .foregroundColor(.secondary)
  12. AGPGraphView(agpData: viewModel.agpData)
  13. .frame(height: 200)
  14. .allowsHitTesting(false)
  15. .clipped()
  16. // Legend
  17. HStack(spacing: 16) {
  18. LegendItem(color: .gray.opacity(0.6), label: "5th-95th")
  19. LegendItem(color: .blue.opacity(0.7), label: "25th-75th")
  20. LegendItem(color: .blue, label: String(localized: "Median"))
  21. }
  22. .font(.caption2)
  23. }
  24. .frame(maxWidth: .infinity, alignment: .leading)
  25. .padding()
  26. .background(Color(.systemGray6))
  27. .cornerRadius(12)
  28. }
  29. }
  30. }
  31. struct LegendItem: View {
  32. let color: Color
  33. let label: String
  34. var body: some View {
  35. HStack(spacing: 4) {
  36. Rectangle()
  37. .fill(color)
  38. .frame(width: 12, height: 12)
  39. Text(label)
  40. .foregroundColor(.secondary)
  41. }
  42. }
  43. }