feat(menubar): 支持固定居中面板与独立刷新频率及图表浮层
This commit is contained in:
@@ -6,20 +6,20 @@ nonisolated enum PanelCurveGeometry {
|
||||
let value: Double
|
||||
}
|
||||
|
||||
static func isAppend(from old: [Date], to new: [Date]) -> Bool {
|
||||
static func isAppend(from old: [Date], to new: [Date], maximumGap: TimeInterval = 5) -> Bool {
|
||||
guard old.count > 1, let previous = old.last, let next = new.last,
|
||||
next > previous, next.timeIntervalSince(previous) <= 5 else { return false }
|
||||
next > previous, next.timeIntervalSince(previous) <= maximumGap else { return false }
|
||||
if new.count == old.count + 1 { return Array(new.dropLast()) == old }
|
||||
return new.count == old.count && Array(old.dropFirst()) == Array(new.dropLast())
|
||||
}
|
||||
|
||||
static func runs(dates: [Date], values: [Double?]) -> [[Sample]] {
|
||||
static func runs(dates: [Date], values: [Double?], maximumGap: TimeInterval = 5, boundaryDates: Set<Date> = []) -> [[Sample]] {
|
||||
var result: [[Sample]] = []
|
||||
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 && (dates[index].timeIntervalSince(dates[index - 1]) > 5 || dates[index] <= dates[index - 1]) { flush() }
|
||||
if index > 0 && (boundaryDates.contains(dates[index]) || dates[index].timeIntervalSince(dates[index - 1]) > maximumGap || dates[index] <= dates[index - 1]) { flush() }
|
||||
run.append(Sample(date: dates[index], value: value))
|
||||
}
|
||||
flush()
|
||||
|
||||
Reference in New Issue
Block a user