|
|
@@ -38,7 +38,7 @@ struct LiveActivityChartView: View {
|
|
|
|
|
|
let isOverrideActive = additionalState.isOverrideActive == true
|
|
|
let isTempTargetActive = additionalState.isTempTargetActive == true
|
|
|
- let hasForecast = !additionalState.minForecast.isEmpty || !additionalState.forecastLines.isEmpty
|
|
|
+ let hasForecast = !additionalState.minForecast.isEmpty
|
|
|
|
|
|
let calendar = Calendar.current
|
|
|
let now = Date()
|
|
|
@@ -47,7 +47,7 @@ struct LiveActivityChartView: View {
|
|
|
let endDate: Date = {
|
|
|
let baseEnd = calendar.date(byAdding: .minute, value: isWatchOS ? 5 : 0, to: now) ?? now
|
|
|
guard hasForecast, let anchorDate = state.date else { return baseEnd }
|
|
|
- let predictionEnd = anchorDate.addingTimeInterval(TimeInterval(150 * 60)) // 2.5h from determination
|
|
|
+ let predictionEnd = anchorDate.addingTimeInterval(TimeInterval(additionalState.minForecast.count * 300))
|
|
|
return max(baseEnd, predictionEnd)
|
|
|
}()
|
|
|
|
|
|
@@ -94,11 +94,7 @@ struct LiveActivityChartView: View {
|
|
|
}
|
|
|
|
|
|
if hasForecast, let anchorDate = state.date {
|
|
|
- if additionalState.forecastDisplayType == "lines" {
|
|
|
- drawForecastLines(anchorDate: anchorDate, isMgdL: isMgdL)
|
|
|
- } else {
|
|
|
- drawForecastCone(anchorDate: anchorDate, isMgdL: isMgdL, maxValue: maxValue)
|
|
|
- }
|
|
|
+ drawForecastCone(anchorDate: anchorDate, isMgdL: isMgdL, maxValue: maxValue)
|
|
|
}
|
|
|
|
|
|
drawChart(yAxisRuleMarkMin: yAxisRuleMarkMin, yAxisRuleMarkMax: yAxisRuleMarkMax)
|
|
|
@@ -201,38 +197,7 @@ struct LiveActivityChartView: View {
|
|
|
yEnd: .value("Max", coneData[i].yMax)
|
|
|
)
|
|
|
.foregroundStyle(Color.blue.opacity(0.5))
|
|
|
- .interpolationMethod(.catmullRom)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private func drawForecastLines(anchorDate: Date, isMgdL: Bool) -> some ChartContent {
|
|
|
- // Colors match the main app's chartForegroundStyleScale
|
|
|
- let colorMap: [String: Color] = [
|
|
|
- "iob": Color(red: 0.118, green: 0.588, blue: 0.988),
|
|
|
- "cob": Color.orange,
|
|
|
- "uam": Color(red: 0.820, green: 0.169, blue: 0.969),
|
|
|
- "zt": Color(red: 0.443, green: 0.380, blue: 0.937)
|
|
|
- ]
|
|
|
-
|
|
|
- // Flatten lines into a single array to avoid nested ForEach in ChartContentBuilder
|
|
|
- let points: [(series: String, date: Date, value: Decimal)] = additionalState.forecastLines.flatMap { line in
|
|
|
- line.values.enumerated().map { index, value in
|
|
|
- let displayValue = isMgdL ? Decimal(value) : Decimal(value).asMmolL
|
|
|
- return (series: line.type, date: timeForIndex(index, anchorDate: anchorDate), value: displayValue)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- let indices = Array(0 ..< points.count)
|
|
|
- return ForEach(indices, id: \.self) { i in
|
|
|
- let point = points[i]
|
|
|
- LineMark(
|
|
|
- x: .value("Time", point.date),
|
|
|
- y: .value("Value", point.value),
|
|
|
- series: .value("Type", point.series)
|
|
|
- )
|
|
|
- .foregroundStyle(colorMap[point.series] ?? Color.gray)
|
|
|
- .lineStyle(.init(lineWidth: 1.5))
|
|
|
- .interpolationMethod(.catmullRom)
|
|
|
+ .interpolationMethod(.linear)
|
|
|
}
|
|
|
}
|
|
|
|