feat(ui): 趋势图跳过无值节点并接续有效数据

This commit is contained in:
2026-11-07 15:04:06 +08:00
parent 050ee30f56
commit 7f3f573e7c
16 changed files with 70 additions and 16 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ struct MiniTrendChart: View {
run.removeAll(keepingCapacity: true)
}
for (index, value) in values.enumerated() {
guard let value, value.isFinite else { appendRun(); continue }
guard let value, value.isFinite else { continue }
let x = size.width * CGFloat(index + MetricHistory.capacity - values.count) / CGFloat(MetricHistory.capacity - 1)
run.append(CGPoint(x: x, y: 2 + (size.height - 4) * (1 - min(1, max(0, value)))))
}
+2 -1
View File
@@ -17,8 +17,9 @@ nonisolated enum PanelCurveGeometry {
var run: [Sample] = []
func flush() { if !run.isEmpty { result.append(run); run.removeAll(keepingCapacity: true) } }
for index in dates.indices {
guard index < values.count, let value = values[index], value.isFinite else { flush(); continue }
if index > 0 && (boundaryDates.contains(dates[index]) || dates[index].timeIntervalSince(dates[index - 1]) > allowedGap(at: index, intervals: intervals, fallback: maximumGap) || dates[index] <= dates[index - 1]) { flush() }
// Missing values do not create vertices, but their timestamps can still carry a real break.
guard index < values.count, let value = values[index], value.isFinite else { continue }
run.append(Sample(date: dates[index], value: value))
}
flush()
+1 -1
View File
@@ -8,7 +8,7 @@ enum TrendValueFormat {
case watts
}
/// Bounded, timestamp-based static curves. Gaps remain gaps; no per-sample animation task.
/// Static curves skip missing vertices, retaining timestamps and explicit sampling breaks.
struct PanelTrendChart: View {
let dates: [Date]
let first: [Double?]