| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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
- // low glucose, high glucose and target is parsed in state to mmol/L; parse it back to mg/dl here for comparison
- let lowGlucose = units == .mgdL ? lowGlucose : lowGlucose.asMgdL
- let highGlucose = units == .mgdL ? highGlucose : highGlucose.asMgdL
- let targetGlucose = units == .mgdL ? currentGlucoseTarget : currentGlucoseTarget.asMgdL
- let pointMarkColor: Color = FreeAPS.getDynamicGlucoseColor(
- glucoseValue: Decimal(item.glucose),
- highGlucoseColorValue: highGlucose,
- lowGlucoseColorValue: lowGlucose,
- targetGlucose: targetGlucose,
- glucoseColorScheme: glucoseColorScheme,
- offset: 20
- )
- 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)
- }
- }
- }
- }
- }
- }
|