import SwiftUI import Charts struct ActivityGraphView: View { let samples: [IntensitySample] let metric: IntensityMetric let lowerBound: Double let upperBound: Double var body: some View { Chart { ForEach(samples) { sample in AreaMark( x: .value("Time", sample.date), y: .value(metric.label, sample.value) ) .foregroundStyle( .linearGradient( colors: [.blue.opacity(0.3), .blue.opacity(0.05)], startPoint: .top, endPoint: .bottom ) ) LineMark( x: .value("Time", sample.date), y: .value(metric.label, sample.value) ) .foregroundStyle(.blue) .lineStyle(StrokeStyle(lineWidth: 1.5)) } // Dimming overlay for trimmed start region if lowerBound > 0, let startDate = samples.first?.date, let endDate = samples.last?.date { let trimStart = startDate.addingTimeInterval( lowerBound * endDate.timeIntervalSince(startDate) ) RectangleMark( xStart: .value("", startDate), xEnd: .value("", trimStart) ) .foregroundStyle(Color(.systemBackground).opacity(0.7)) } // Dimming overlay for trimmed end region if upperBound < 1, let startDate = samples.first?.date, let endDate = samples.last?.date { let trimEnd = startDate.addingTimeInterval( upperBound * endDate.timeIntervalSince(startDate) ) RectangleMark( xStart: .value("", trimEnd), xEnd: .value("", endDate) ) .foregroundStyle(Color(.systemBackground).opacity(0.7)) } } .chartXAxis(.hidden) .chartYAxis { AxisMarks(position: .leading, values: .automatic(desiredCount: 3)) { value in AxisGridLine() AxisValueLabel { if let v = value.as(Double.self) { Text("\(Int(v))") .font(.caption2) } } } } .chartYAxisLabel(metric.label, position: .leading) } }