fix(charts): 修复浮窗层级并平滑切频与曲线移出
This commit is contained in:
@@ -14,6 +14,7 @@ nonisolated struct TrendSample: Sendable {
|
||||
var cpuUser: Double?
|
||||
var cpuSystem: Double?
|
||||
var breakBefore = false
|
||||
var expectedInterval: TimeInterval = 2
|
||||
}
|
||||
|
||||
/// Bounded sampling history; no timer or UI visibility dependence.
|
||||
@@ -22,18 +23,18 @@ nonisolated struct MetricHistory: Sendable {
|
||||
private(set) var samples: [TrendSample] = []
|
||||
private(set) var interfaces: [String: [InterfaceTrendSample]] = [:]
|
||||
|
||||
mutating func append(_ snapshot: MetricsSnapshot, breakBefore: Bool = false) {
|
||||
mutating func append(_ snapshot: MetricsSnapshot, breakBefore: Bool = false, expectedInterval: TimeInterval = 2) {
|
||||
samples.append(TrendSample(date: snapshot.date, cpu: snapshot.cpu?.usage,
|
||||
gpu: snapshot.gpuUsage, memory: snapshot.memory?.usage,
|
||||
download: snapshot.downloadRate, disk: snapshot.disk?.usage,
|
||||
battery: snapshot.battery?.charge, upload: snapshot.uploadRate,
|
||||
read: snapshot.diskIO?.read, write: snapshot.diskIO?.written,
|
||||
cpuUser: snapshot.cpu?.user, cpuSystem: snapshot.cpu?.system, breakBefore: breakBefore))
|
||||
cpuUser: snapshot.cpu?.user, cpuSystem: snapshot.cpu?.system, breakBefore: breakBefore, expectedInterval: expectedInterval))
|
||||
let current = snapshot.network ?? []
|
||||
let keys = Set(current.map(\.identity))
|
||||
interfaces = interfaces.filter { keys.contains($0.key) }
|
||||
for item in current {
|
||||
interfaces[item.identity, default: []].append(InterfaceTrendSample(date: snapshot.date, download: item.download, upload: item.upload))
|
||||
interfaces[item.identity, default: []].append(InterfaceTrendSample(date: snapshot.date, download: item.download, upload: item.upload, expectedInterval: expectedInterval))
|
||||
if interfaces[item.identity, default: []].count > Self.capacity { interfaces[item.identity]?.removeFirst() }
|
||||
}
|
||||
if samples.count > Self.capacity { samples.removeFirst(samples.count - Self.capacity) }
|
||||
@@ -44,4 +45,5 @@ nonisolated struct InterfaceTrendSample: Sendable {
|
||||
let date: Date
|
||||
let download: Double?
|
||||
let upload: Double?
|
||||
var expectedInterval: TimeInterval = 2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user