feat(ui): 实现全卡堆叠趋势与单页资源进程布局

This commit is contained in:
2026-11-15 17:59:52 +08:00
parent 469766892d
commit 99e558625b
37 changed files with 579 additions and 195 deletions
+32
View File
@@ -0,0 +1,32 @@
import Foundation
/// Additive components retain their raw values; only render boundaries are cumulative.
nonisolated enum StackedSeries {
struct Band {
var lower: [Double?]
var upper: [Double?]
}
static func bands(_ components: [[Double?]], count: Int, limit: Double? = nil) -> [Band] {
var result = components.map { _ in Band(lower: Array(repeating: nil, count: count), upper: Array(repeating: nil, count: count)) }
guard !components.isEmpty else { return result }
for point in 0..<count {
var values: [Double] = []
for component in components {
guard component.indices.contains(point), let value = component[point], value.isFinite, value >= 0 else { break }
values.append(value)
}
guard values.count == components.count else { continue }
let total = values.reduce(0, +)
guard total.isFinite else { continue }
if let limit, limit.isFinite, limit > 0, total > limit + max(1, limit) * 1e-12 { continue }
var lower = 0.0
for (series, value) in values.enumerated() {
result[series].lower[point] = lower
lower += value
result[series].upper[point] = lower
}
}
return result
}
}