| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import Charts
- import Foundation
- import SwiftUI
- struct GlucoseChartView: ChartContent {
- let glucoseData: [GlucoseStored]
- let units: GlucoseUnits
- let highGlucose: Decimal
- let lowGlucose: Decimal
- let currentGlucoseTarget: Decimal
- let isSmoothingEnabled: Bool
- let glucoseColorScheme: GlucoseColorScheme
- var body: some ChartContent {
- drawGlucoseChart()
- }
- private func drawGlucoseChart() -> some ChartContent {
- ForEach(glucoseData) { item in
- let glucoseToDisplay = units == .mgdL ? Decimal(item.glucose) : Decimal(item.glucose).asMmolL
- let pointMarkColor = FreeAPS.getDynamicGlucoseColor(
- glucoseValue: glucoseToDisplay,
- highGlucoseColorValue: highGlucose,
- lowGlucoseColorValue: lowGlucose,
- targetGlucose: currentGlucoseTarget,
- glucoseColorScheme: glucoseColorScheme,
- offset: units == .mgdL ? 20 : 20.asMmolL
- )
- if !isSmoothingEnabled {
- PointMark(
- x: .value("Time", item.date ?? Date(), unit: .second),
- y: .value("Value", glucoseToDisplay)
- )
- .foregroundStyle(pointMarkColor)
- .symbolSize(20)
- .symbol {
- if item.isManual {
- Image(systemName: "drop.fill")
- .font(.system(size: 10))
- .symbolRenderingMode(.monochrome)
- .bold()
- .foregroundStyle(.red)
- } else {
- Image(systemName: "circle.fill")
- .font(.system(size: 5))
- .bold()
- .foregroundStyle(pointMarkColor)
- }
- }
- } else {
- PointMark(
- x: .value("Time", item.date ?? Date(), unit: .second),
- y: .value("Value", glucoseToDisplay)
- )
- .symbol {
- if item.isManual {
- Image(systemName: "drop.fill")
- .font(.system(size: 10))
- .symbolRenderingMode(.monochrome)
- .bold()
- .foregroundStyle(.red)
- } else {
- Image(systemName: "record.circle.fill")
- .font(.system(size: 8))
- .bold()
- .foregroundStyle(pointMarkColor)
- }
- }
- }
- }
- }
- }
|