perf(ui): 移除监控动效并精简原生图表绘制
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import Foundation
|
||||
|
||||
@main struct AppearancePreferencesChecks {
|
||||
@MainActor static func main() {
|
||||
let suite = "kymo.appearance." + UUID().uuidString
|
||||
let defaults = UserDefaults(suiteName: suite)!
|
||||
defer { defaults.removePersistentDomain(forName: suite) }
|
||||
defaults.set(true, forKey: "appearance.reduceMotion")
|
||||
let sampling = SamplingPreferences(defaults: defaults)
|
||||
let appearance = AppearancePreferences(defaults: defaults)
|
||||
precondition(appearance.appearance == .system && !sampling.backgroundEnabled)
|
||||
appearance.appearance = .dark
|
||||
precondition(AppearancePreferences(defaults: defaults).appearance == .dark)
|
||||
precondition(!sampling.backgroundEnabled && sampling.panelMilliseconds == 2000)
|
||||
sampling.backgroundEnabled = true
|
||||
sampling.backgroundMilliseconds = 5000
|
||||
appearance.appearance = .light
|
||||
precondition(sampling.backgroundEnabled && sampling.backgroundMilliseconds == 5000)
|
||||
precondition(defaults.bool(forKey: "appearance.reduceMotion"), "Obsolete motion keys must be ignored, not overwritten")
|
||||
defaults.set("invalid", forKey: "appearance")
|
||||
precondition(AppearancePreferences(defaults: defaults).appearance == .system)
|
||||
print("PASS: appearance persistence/fallback, independent sampling and preservation of obsolete motion preferences")
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
@main struct MotionPreferencesChecks {
|
||||
@MainActor static func main() {
|
||||
let suite = "kymo.motion." + UUID().uuidString
|
||||
let defaults = UserDefaults(suiteName: suite)!
|
||||
defer { defaults.removePersistentDomain(forName: suite) }
|
||||
let sampling = SamplingPreferences(defaults: defaults)
|
||||
let appearance = AppearancePreferences(defaults: defaults)
|
||||
precondition(!appearance.reduceMotion && !sampling.backgroundEnabled)
|
||||
let interval = sampling.backgroundMilliseconds
|
||||
appearance.reduceMotion = true
|
||||
precondition(AppearancePreferences(defaults: defaults).reduceMotion)
|
||||
precondition(!sampling.backgroundEnabled && sampling.backgroundMilliseconds == interval)
|
||||
sampling.backgroundEnabled = true; sampling.backgroundMilliseconds = 5_000
|
||||
appearance.reduceMotion = false
|
||||
precondition(sampling.backgroundEnabled && sampling.backgroundMilliseconds == 5_000)
|
||||
precondition(!AppearancePreferences(defaults: defaults).reduceMotion)
|
||||
for value in ["YES" as Any, 1 as Any] {
|
||||
defaults.set(value, forKey: "appearance.reduceMotion")
|
||||
precondition(!AppearancePreferences(defaults: defaults).reduceMotion, "Invalid persisted types must retain the default")
|
||||
}
|
||||
let previousArguments = defaults.volatileDomain(forName: UserDefaults.argumentDomain)
|
||||
defaults.setVolatileDomain(["appearance.reduceMotion": "YES"], forName: UserDefaults.argumentDomain)
|
||||
precondition(AppearancePreferences(defaults: defaults).reduceMotion, "Launch overrides must be honored without writing persistent settings")
|
||||
defaults.setVolatileDomain(previousArguments, forName: UserDefaults.argumentDomain)
|
||||
for reduced in [false, true] {
|
||||
for system in [false, true] {
|
||||
for visible in [false, true] {
|
||||
for paused in [false, true] {
|
||||
for sleeping in [false, true] {
|
||||
let value = MetricMotionPolicy.enabled(reduced: reduced, systemReduced: system, visible: visible, paused: paused, sleeping: sleeping)
|
||||
precondition(value == (!reduced && !system && visible && !paused && !sleeping))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
print("PASS: default high-motion preference, persistence/type safety, independent background controls and system/visibility/pause/sleep policy")
|
||||
}
|
||||
}
|
||||
@@ -19,23 +19,23 @@ import SwiftUI
|
||||
let ideal = host.fittingSize
|
||||
precondition(ideal.width.isFinite && ideal.height.isFinite, "Unconstrained fitting must stay finite")
|
||||
let before = bitmap(host)
|
||||
precondition(probe.appearances == 1 && probe.animates && probe.locale == "en_US" && probe.font == .system(size: 22, weight: .medium))
|
||||
precondition(probe.appearances == 1 && probe.locale == "en_US" && probe.font == .system(size: 22, weight: .medium))
|
||||
precondition(redPixels(before) > 30, "Foreground style must cross the native boundary")
|
||||
let originalLifetime = ObjectIdentifier(probe.lifetime!)
|
||||
host.rootView = Example(value: "345", probe: probe)
|
||||
try? await Task.sleep(for: .milliseconds(140))
|
||||
let middle = bitmap(host)
|
||||
let settled = bitmap(host)
|
||||
try? await Task.sleep(for: .milliseconds(600))
|
||||
let after = bitmap(host)
|
||||
precondition(before.bitmapData != nil && after.bitmapData != nil)
|
||||
precondition(pixels(before) != pixels(after), "Changed values must reach the retained child host")
|
||||
precondition(pixels(middle) != pixels(before) && pixels(middle) != pixels(after),
|
||||
"The system numeric transition must still have an intermediate frame")
|
||||
precondition(pixels(settled) == pixels(after),
|
||||
"A sample must settle immediately without numeric rolling or a later animation frame")
|
||||
precondition(probe.appearances == 1 && probe.lifetime.map(ObjectIdentifier.init) == originalLifetime,
|
||||
"Sampling must update mounted content, not remount it")
|
||||
host.rootView = Example(value: "345", probe: probe, reduced: true, locale: "zh_CN")
|
||||
host.rootView = Example(value: "345", probe: probe, locale: "zh_CN")
|
||||
try? await Task.sleep(for: .milliseconds(100))
|
||||
precondition(!probe.animates && probe.locale == "zh_CN")
|
||||
precondition(probe.locale == "zh_CN")
|
||||
window.setContentSize(NSSize(width: 360, height: 100))
|
||||
try? await Task.sleep(for: .milliseconds(100))
|
||||
@MainActor func childHost(_ view: NSView) -> NSHostingView<AnyView>? {
|
||||
@@ -55,7 +55,7 @@ import SwiftUI
|
||||
window.orderOut(nil)
|
||||
window.contentView = nil
|
||||
window.close()
|
||||
print("PASS: card host preserves system numeric intermediate frames, inherited font/style/locale/motion, child state, resize and unmount")
|
||||
print("PASS: static card host preserves immediate stable text, inherited font/style/locale, child state, resize and unmount")
|
||||
fflush(stdout)
|
||||
NSApp.terminate(nil)
|
||||
}
|
||||
@@ -66,7 +66,6 @@ import SwiftUI
|
||||
@MainActor private final class Probe {
|
||||
var appearances = 0
|
||||
var disappearances = 0
|
||||
var animates = false
|
||||
var locale = ""
|
||||
var font: Font?
|
||||
weak var lifetime: Lifetime?
|
||||
@@ -74,7 +73,6 @@ import SwiftUI
|
||||
private struct Example: View {
|
||||
let value: String
|
||||
let probe: Probe
|
||||
var reduced = false
|
||||
var locale = "en_US"
|
||||
var visible = true
|
||||
var body: some View {
|
||||
@@ -84,29 +82,26 @@ import SwiftUI
|
||||
.font(.system(size: 22, weight: .medium))
|
||||
.foregroundStyle(.red)
|
||||
.environment(\.locale, Locale(identifier: locale))
|
||||
.environment(\.metricAnimationsEnabled, !reduced)
|
||||
}
|
||||
}
|
||||
private struct Content: View {
|
||||
let value: String
|
||||
let probe: Probe
|
||||
@Environment(\.metricAnimationsEnabled) private var animates
|
||||
@Environment(\.locale) private var locale
|
||||
@Environment(\.font) private var font
|
||||
@State private var lifetime = Lifetime()
|
||||
var body: some View {
|
||||
AnimatedMetricText(value: value)
|
||||
MetricText(value: value)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.onAppear {
|
||||
probe.appearances += 1; probe.lifetime = lifetime
|
||||
recordEnvironment()
|
||||
}
|
||||
.onDisappear { probe.disappearances += 1 }
|
||||
.onChange(of: animates) { recordEnvironment() }
|
||||
.onChange(of: locale) { recordEnvironment() }
|
||||
}
|
||||
private func recordEnvironment() {
|
||||
probe.animates = animates; probe.locale = locale.identifier; probe.font = font
|
||||
probe.locale = locale.identifier; probe.font = font
|
||||
}
|
||||
}
|
||||
@MainActor private static func bitmap(_ view: NSView) -> NSBitmapImageRep {
|
||||
|
||||
@@ -43,107 +43,60 @@ import QuartzCore
|
||||
ring.configure(NativeMetricRing.Input(value: 1, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2))
|
||||
let full = redPixels(bitmap(ring), opaque: true)
|
||||
precondition(quarter > 0 && full > quarter * 2, "Ring fraction must change the rendered arc")
|
||||
// Actual native compositor transitions finish and remove their animation objects.
|
||||
var moving = continuous
|
||||
let extendedDates = dates + [Date(timeIntervalSinceReferenceDate: 8)]
|
||||
moving = NativePanelCurve.Input(frame: PanelCurveFrame(dates: extendedDates, series: [[0.8,0.8,0.8,0.8,0.5]],
|
||||
intervals: [2,2,2,2,2], boundaryDates: []), colors: [.red], scales: [1], maximumGap: 5, animates: true)
|
||||
plot.configure(continuous); plot.configure(moving)
|
||||
precondition(plot.isAnimating)
|
||||
let builds = plot.pathBuildCount
|
||||
precondition(plot.grid.animationKeys() == nil, "The grid must stay stationary")
|
||||
let movement = plot.curves.animation(forKey: MetricMotion.key) as! CAKeyframeAnimation
|
||||
precondition(movement.keyPath == "transform" && movement.values?.count == 61)
|
||||
precondition(plot.curves.animation(forKey: kCATransition) == nil, "A moving curve must not be replaced with a fade")
|
||||
let middle = (movement.values![30] as! NSValue).caTransform3DValue
|
||||
let oldDomain = PanelCurveFrame.domain(previousBegin: nil, previousEnd: nil, begin: dates.first!, end: dates.last!, progress: 1)
|
||||
let newDomain = PanelCurveFrame.domain(previousBegin: nil, previousEnd: nil, begin: extendedDates.first!, end: extendedDates.last!, progress: 1)
|
||||
let expected = PanelCurveFrame.horizontalTransform(from: oldDomain, to: newDomain, progress: 0.5, width: 280)
|
||||
precondition(abs(middle.m11 - expected.scale) < 0.0001 && abs(middle.m41 - expected.translation) < 0.0001)
|
||||
// Sampling updates are final immediately, and hover keeps cached curve geometry.
|
||||
let nextDates = dates + [Date(timeIntervalSinceReferenceDate: 8)]
|
||||
let next = NativePanelCurve.Input(frame: PanelCurveFrame(dates: nextDates,
|
||||
series: [[0.8,0.8,0.8,0.8,0.5]], intervals: [2,2,2,2,2], boundaryDates: []),
|
||||
colors: [.red], scales: [1], maximumGap: 5)
|
||||
plot.configure(continuous)
|
||||
let previousBuilds = plot.pathBuildCount
|
||||
plot.configure(next)
|
||||
precondition(plot.pathBuildCount == previousBuilds + 1 && plot.input?.frame == next.frame)
|
||||
let sampled = bitmap(plot)
|
||||
try? await Task.sleep(for: .milliseconds(180))
|
||||
precondition(plot.pathBuildCount == builds, "Animation frames must not rebuild curve geometry")
|
||||
var duringHover = moving; duringHover.hoveredIndex = 2
|
||||
plot.configure(duringHover)
|
||||
precondition(plot.pathBuildCount == builds && plot.isAnimating, "Hover must not rebuild or restart movement")
|
||||
try? await Task.sleep(for: .milliseconds(320))
|
||||
precondition(!plot.isAnimating && plot.drawingFrame == moving.frame)
|
||||
var appended = moving
|
||||
appended = NativePanelCurve.Input(frame: PanelCurveFrame(dates: extendedDates + [Date(timeIntervalSinceReferenceDate: 10)],
|
||||
series: [[0.8,0.8,0.8,0.8,0.5,0.2]], intervals: [2,2,2,2,2,2], boundaryDates: []), colors: [.red], scales: [1], maximumGap: 5, animates: true)
|
||||
plot.configure(appended); precondition(plot.isAnimating)
|
||||
appended.animates = false; plot.configure(appended)
|
||||
precondition(!plot.isAnimating && plot.drawingFrame == appended.frame)
|
||||
let beforeGap = appended
|
||||
appended = NativePanelCurve.Input(frame: PanelCurveFrame(dates: appended.frame.dates + [Date(timeIntervalSinceReferenceDate: 30)],
|
||||
series: [[0.8,0.8,0.8,0.8,0.5,0.2,0.7]], intervals: [2,2,2,2,2,2,2], boundaryDates: []), colors: [.red], scales: [1], maximumGap: 5, animates: true)
|
||||
plot.configure(appended); precondition(!plot.isAnimating, "Do not animate across real gaps")
|
||||
plot.configure(moving)
|
||||
var attached = beforeGap; attached.animates = true
|
||||
plot.configure(attached); precondition(plot.isAnimating)
|
||||
plot.removeFromSuperview(); precondition(!plot.isAnimating)
|
||||
root.addSubview(plot)
|
||||
precondition(plot.pathBuildCount == previousBuilds + 1)
|
||||
precondition(pixels(sampled) == pixels(bitmap(plot)), "A sampled curve must not move between updates")
|
||||
var hover = next; hover.hoveredIndex = 2
|
||||
plot.configure(hover)
|
||||
precondition(plot.pathBuildCount == previousBuilds + 1, "Hover must not rebuild curve geometry")
|
||||
let fullDates = (0..<60).map { Date(timeIntervalSinceReferenceDate: Double($0 * 2)) }
|
||||
let fullFrame = PanelCurveFrame(dates: fullDates, series: [Array(repeating: 0.8, count: 60)], intervals: Array(repeating: 2, count: 60), boundaryDates: [])
|
||||
let nextFrame = PanelCurveFrame(dates: Array(fullDates.dropFirst()) + [Date(timeIntervalSinceReferenceDate: 120)],
|
||||
series: [Array(repeating: 0.8, count: 59) + [0.5]], intervals: Array(repeating: 2, count: 60), boundaryDates: [])
|
||||
plot.configure(.init(frame: fullFrame, colors: [.red], scales: [1], maximumGap: 5, animates: true))
|
||||
plot.configure(.init(frame: nextFrame, colors: [.red], scales: [1], maximumGap: 5, animates: true))
|
||||
precondition(plot.isAnimating && plot.drawingFrame?.dates.count == 61)
|
||||
let initialTransform = ((plot.curves.animation(forKey: MetricMotion.key) as! CAKeyframeAnimation).values!.first as! NSValue).caTransform3DValue
|
||||
CATransaction.begin(); CATransaction.setDisableActions(true)
|
||||
plot.curves.transform = initialTransform
|
||||
CATransaction.commit()
|
||||
precondition(redPixels(bitmap(plot), from: 0, to: 0.01) > 0, "Outgoing fill must cover the left edge while scrolling")
|
||||
CATransaction.begin(); CATransaction.setDisableActions(true); plot.curves.transform = CATransform3DIdentity; CATransaction.commit()
|
||||
plot.configure(.init(frame: nextFrame, colors: [.red], scales: [1], maximumGap: 5))
|
||||
precondition(!plot.isAnimating && plot.drawingFrame?.dates.count == 60)
|
||||
plot.removeFromSuperview()
|
||||
ring.configure(NativeMetricRing.Input(value: 0, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2, animates: true))
|
||||
precondition(ring.isAnimating)
|
||||
let arcAnimation = ring.arc.animation(forKey: MetricMotion.key) as! CABasicAnimation
|
||||
precondition(arcAnimation.keyPath == "strokeEnd" && (arcAnimation.fromValue as! Double) == 1 && (arcAnimation.toValue as! Double) == 0)
|
||||
precondition(ring.arc.animation(forKey: kCATransition) == nil)
|
||||
try? await Task.sleep(for: .milliseconds(150))
|
||||
let intermediate = ring.displayedValue
|
||||
precondition(intermediate > 0 && intermediate < 1, "Ring must show intermediate arc lengths")
|
||||
try? await Task.sleep(for: .milliseconds(350))
|
||||
precondition(!ring.isAnimating && ring.displayedValue == 0)
|
||||
ring.configure(NativeMetricRing.Input(value: 0.8, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2, animates: true))
|
||||
precondition(ring.isAnimating)
|
||||
ring.configure(NativeMetricRing.Input(value: 0.8, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2))
|
||||
precondition(!ring.isAnimating && ring.displayedValue == 0.8)
|
||||
ring.configure(NativeMetricRing.Input(value: 0.2, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2, animates: true))
|
||||
ring.removeFromSuperview(); precondition(!ring.isAnimating && ring.displayedValue == 0.2)
|
||||
// Shared cleanup must not stop a different motion or a newer replacement.
|
||||
let firstMotion = MetricMotion(), secondMotion = MetricMotion()
|
||||
let firstLayer = CALayer(), secondLayer = CALayer()
|
||||
root.wantsLayer = true
|
||||
for target in [firstLayer, secondLayer] {
|
||||
target.frame = CGRect(x: 10, y: 10, width: 20, height: 20)
|
||||
target.backgroundColor = NSColor.red.cgColor
|
||||
root.layer?.addSublayer(target)
|
||||
}
|
||||
func makeMovement() -> CABasicAnimation {
|
||||
let animation = CABasicAnimation(keyPath: "position.x")
|
||||
animation.fromValue = 0; animation.toValue = 10
|
||||
return animation
|
||||
}
|
||||
firstMotion.start(on: firstLayer, animation: makeMovement())
|
||||
secondMotion.start(on: secondLayer, animation: makeMovement())
|
||||
let fullFrame = PanelCurveFrame(dates: fullDates, series: [Array(repeating: 0.8, count: 60)],
|
||||
intervals: Array(repeating: 2, count: 60), boundaryDates: [])
|
||||
plot.configure(.init(frame: fullFrame, colors: [.red], scales: [1], maximumGap: 5))
|
||||
let appended = PanelCurveFrame(dates: Array(fullDates.dropFirst()) + [Date(timeIntervalSinceReferenceDate: 120)],
|
||||
series: [Array(repeating: 0.8, count: 59) + [0.5]], intervals: fullFrame.intervals, boundaryDates: [])
|
||||
plot.configure(.init(frame: appended, colors: [.red], scales: [1], maximumGap: 5))
|
||||
precondition(plot.input?.frame.dates.count == 60, "Static history must not retain an outgoing animation point")
|
||||
ring.configure(.init(value: 0.25, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2))
|
||||
precondition(ring.arc.strokeEnd == 0.25, "The arc must immediately show the new value")
|
||||
let updated = bitmap(ring)
|
||||
try? await Task.sleep(for: .milliseconds(180))
|
||||
firstMotion.stop()
|
||||
secondMotion.start(on: secondLayer, animation: makeMovement())
|
||||
try? await Task.sleep(for: .milliseconds(210))
|
||||
precondition(!firstMotion.isRunning && secondMotion.isRunning,
|
||||
"An old batch deadline must not remove a restarted animation")
|
||||
try? await Task.sleep(for: .milliseconds(250))
|
||||
precondition(!secondMotion.isRunning, "The replacement must also finish and release its animation")
|
||||
precondition(pixels(updated) == pixels(bitmap(ring)), "A sampled ring must not interpolate later")
|
||||
// Adding a series with an unchanged palette must color the new layer too.
|
||||
plot.configure(.init(frame: PanelCurveFrame(dates: dates, series: [[nil,nil,nil,nil], [0.5,0.5,0.5,0.5]],
|
||||
intervals: [2,2,2,2], boundaryDates: []), colors: [.red], scales: [1], maximumGap: 5))
|
||||
precondition(redPixels(bitmap(plot), from: 0.4, to: 0.6) > 10)
|
||||
assertStatic(plot.layer!)
|
||||
assertStatic(ring.layer!)
|
||||
plot.removeFromSuperview(); ring.removeFromSuperview()
|
||||
window.orderOut(nil); window.close()
|
||||
print("PASS: native curve pixels, real gaps, missing series, hover, appearance, duplicate-input invalidation zero/quarter/full ring pixels and finite transitions/gap/policy/unmount cancellation")
|
||||
print("PASS: static curve/ring pixels, immediate stable updates, no animation/material/gradient layers, real gaps, hover cache, palette growth, appearance, full history and unmount")
|
||||
fflush(stdout); NSApp.terminate(nil)
|
||||
}
|
||||
NSApp.run()
|
||||
}
|
||||
@MainActor private static func assertStatic(_ layer: CALayer) {
|
||||
precondition(layer.animationKeys()?.isEmpty != false)
|
||||
precondition(!(layer is CAGradientLayer) && layer.mask == nil && layer.filters?.isEmpty != false)
|
||||
for child in layer.sublayers ?? [] { assertStatic(child) }
|
||||
}
|
||||
private static func pixels(_ bitmap: NSBitmapImageRep) -> Data {
|
||||
var data = Data()
|
||||
for row in 0..<bitmap.pixelsHigh {
|
||||
data.append(bitmap.bitmapData!.advanced(by: row * bitmap.bytesPerRow), count: bitmap.pixelsWide * bitmap.bitsPerPixel / 8)
|
||||
}
|
||||
return data
|
||||
}
|
||||
@MainActor private static func bitmap(_ view: NSView) -> NSBitmapImageRep {
|
||||
view.layoutSubtreeIfNeeded(); view.displayIfNeeded()
|
||||
let result = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: Int(view.bounds.width * 2), pixelsHigh: Int(view.bounds.height * 2),
|
||||
|
||||
@@ -15,7 +15,7 @@ import AppKit
|
||||
NSAppearance(named: appearance)!.performAsCurrentDrawingAppearance {
|
||||
for name in ["PanelBackground", "PanelCard", "PanelTooltip", "MetricCPU", "MetricGPU", "MetricMemory", "MetricNetwork", "MetricDisk", "MetricBattery", "SeriesUser", "SeriesSystem", "SeriesUpload"] {
|
||||
guard let color = NSColor(named: NSColor.Name(name), bundle: bundle)?.usingColorSpace(.sRGB) else { fatalError("Missing color: \(name)") }
|
||||
precondition(abs(color.alphaComponent - (name == "PanelTooltip" ? 0.97 : 1)) < 0.005, "Unexpected alpha \(name)")
|
||||
precondition(abs(color.alphaComponent - 1) < 0.005, "Unexpected alpha \(name)")
|
||||
if name.hasPrefix("Metric") || name.hasPrefix("Series") {
|
||||
let card = NSColor(named: "PanelCard", bundle: bundle)!.usingColorSpace(.sRGB)!
|
||||
let a = luminance(color), b = luminance(card)
|
||||
|
||||
@@ -3,10 +3,6 @@ import Foundation
|
||||
@main struct PanelCurveChecks {
|
||||
static func main() {
|
||||
let dates = (0..<60).map { Date(timeIntervalSinceReferenceDate: Double($0 * 2)) }
|
||||
precondition(PanelCurveGeometry.isAppend(from: Array(dates.prefix(2)), to: Array(dates.prefix(3))))
|
||||
precondition(PanelCurveGeometry.isAppend(from: dates, to: Array(dates.dropFirst()) + [dates.last!.addingTimeInterval(2)]))
|
||||
precondition(!PanelCurveGeometry.isAppend(from: dates, to: Array(dates.dropFirst()) + [dates.last!.addingTimeInterval(8)]))
|
||||
precondition(!PanelCurveGeometry.isAppend(from: dates, to: dates))
|
||||
let runs = PanelCurveGeometry.runs(dates: Array(dates.prefix(6)), values: [0, 0.5, nil, .nan, 0.8, 1])
|
||||
precondition(runs.count == 2 && runs[0].count == 2 && runs[1].count == 2)
|
||||
precondition(PanelCurveGeometry.runs(dates: [dates[0], dates[4]], values: [0.3, 0.5]).count == 2)
|
||||
@@ -15,37 +11,16 @@ import Foundation
|
||||
let slow = [Date(timeIntervalSinceReferenceDate: 0), Date(timeIntervalSinceReferenceDate: 1800), Date(timeIntervalSinceReferenceDate: 3600)]
|
||||
precondition(PanelCurveGeometry.runs(dates: slow, values: [0.1, 0.2, 0.3], maximumGap: 3600).count == 1)
|
||||
precondition(PanelCurveGeometry.runs(dates: slow, values: [0.1, 0.2, 0.3], maximumGap: 3600, boundaryDates: [slow[1]]).count == 2)
|
||||
precondition(PanelCurveGeometry.isAppend(from: Array(slow.prefix(2)), to: slow, maximumGap: 3600))
|
||||
precondition(PanelCurveGeometry.runs(dates: slow, values: [0.1, 0.2, 0.3], maximumGap: 5, intervals: [1800, 1800, 0.5]).count == 1)
|
||||
precondition(PanelCurveGeometry.runs(dates: slow, values: [0.1, 0.2, 0.3], maximumGap: 5, boundaryDates: [slow[2]], intervals: [1800, 1800, 0.5]).count == 2)
|
||||
let old = PanelCurveFrame(dates: dates, series: [Array(repeating: 0.3, count: 60), []], intervals: Array(repeating: 2, count: 60), boundaryDates: [])
|
||||
let next = PanelCurveFrame(dates: Array(dates.dropFirst()) + [dates.last!.addingTimeInterval(2)], series: [Array(repeating: 0.3, count: 59) + [0.4], []], intervals: Array(repeating: 2, count: 60), boundaryDates: [])
|
||||
let transition = PanelCurveFrame.transition(from: old, to: next)
|
||||
precondition(transition.dates.count == 61 && transition.dates.first == old.dates.first)
|
||||
precondition(transition.series[0].first! == 0.3 && transition.series[0].last! == 0.4 && transition.series[1].isEmpty)
|
||||
precondition(Array(transition.series[0].prefix(60)) == old.series[0])
|
||||
for progress in [0.0, 0.25, 0.5, 0.75, 1.0] {
|
||||
let domain = PanelCurveFrame.domain(previousBegin: old.dates.first, previousEnd: old.dates.last,
|
||||
begin: next.dates.first!, end: next.dates.last!, progress: progress)
|
||||
let left = domain.position(transition.dates[0]), right = domain.position(transition.dates[1])
|
||||
precondition(left <= 0 && right >= 0, "Outgoing segment must cover the left boundary throughout the animation")
|
||||
if progress == 0 { precondition(abs(left) < 0.000001 && abs(domain.position(old.dates.last!) - 1) < 0.000001) }
|
||||
if progress == 1 { precondition(abs(right) < 0.000001 && abs(domain.position(next.dates.last!) - 1) < 0.000001) }
|
||||
}
|
||||
// The compositor mapping must equal the original interpolated time-domain formula.
|
||||
for previous in [PanelCurveFrame.Domain(begin: 0, end: 4), .init(begin: 0, end: 118), .init(begin: 2, end: 119.3)] {
|
||||
for target in [PanelCurveFrame.Domain(begin: 0, end: 6), .init(begin: 2, end: 120), .init(begin: 4.4, end: 121.8)] {
|
||||
for p in [0.0, 0.25, 0.5, 0.75, 1] {
|
||||
let map = PanelCurveFrame.horizontalTransform(from: previous, to: target, progress: p, width: 350)
|
||||
let interpolated = PanelCurveFrame.Domain(begin: previous.begin * (1-p) + target.begin * p,
|
||||
end: previous.end * (1-p) + target.end * p)
|
||||
for t in [0.0, 2, 60, 120] {
|
||||
let date = Date(timeIntervalSinceReferenceDate: t)
|
||||
precondition(abs(target.position(date) * 350 * map.scale + map.translation - interpolated.position(date) * 350) < 0.00001)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
print("PASS: timestamp append/full history, pause/reset, missing/nonfinite data, short series, cadence continuity, pause boundaries and 61-point left-edge animation geometry")
|
||||
let frame = PanelCurveFrame(dates: dates, series: [Array(repeating: 0.3, count: 60)], intervals: Array(repeating: 2, count: 60), boundaryDates: [])
|
||||
precondition(frame.dates.count == 60)
|
||||
let domain = PanelCurveFrame.domain(begin: dates.first!, end: dates.last!)
|
||||
precondition(domain.position(dates.first!) == 0 && domain.position(dates.last!) == 1)
|
||||
let irregular = PanelCurveFrame.domain(begin: dates[1], end: dates[5])
|
||||
precondition(abs(irregular.position(dates[2]) - 0.25) < 0.000001)
|
||||
let single = PanelCurveFrame.domain(begin: dates[0], end: dates[0])
|
||||
precondition(single.position(dates[0]) == 1)
|
||||
print("PASS: static timestamp domain, bounded history, missing/nonfinite data, short series, cadence continuity and real pause boundaries")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,8 @@ import SwiftUI
|
||||
Task { @MainActor in
|
||||
var visible = false
|
||||
var settingsRequests = 0
|
||||
var reducedMotion = true
|
||||
let controller = MenuPanelController(installStatusItem: false, visibility: { visible = $0 },
|
||||
openSettings: { settingsRequests += 1 }, reducedMotion: { reducedMotion }) { _ in
|
||||
openSettings: { settingsRequests += 1 }) { _ in
|
||||
IntervalControl(milliseconds: .constant(1000))
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
@@ -75,9 +74,8 @@ import SwiftUI
|
||||
precondition(controller.panel.level == .normal)
|
||||
controller.dismissForOutsideInteraction()
|
||||
precondition(!controller.panel.isVisible)
|
||||
reducedMotion = false
|
||||
controller.show()
|
||||
precondition(controller.panel.animationBehavior == (NSWorkspace.shared.accessibilityDisplayShouldReduceMotion ? .none : .default))
|
||||
precondition(controller.panel.animationBehavior == .none && !controller.panel.hasShadow)
|
||||
controller.presentation.isPinned = true
|
||||
controller.shutdown()
|
||||
precondition(!controller.presentation.isPinned && !visible)
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
@main struct TrendScrollChecks {
|
||||
static func main() {
|
||||
precondition(!TrendScroll.isAppend(from: [], to: [0.2]))
|
||||
precondition(TrendScroll.isAppend(from: [0.2, nil], to: [0.2, nil, 0.4]))
|
||||
precondition(!TrendScroll.isAppend(from: [0.2], to: [0.4, 0.5]))
|
||||
let full: [Double?] = (0..<MetricHistory.capacity).map { Double($0) / 100 }
|
||||
precondition(TrendScroll.isAppend(from: full, to: Array(full.dropFirst()) + [nil]))
|
||||
for count in [3, MetricHistory.capacity + 1] {
|
||||
let start = TrendScroll.position(index: count - 2, count: count, progress: 0, scrolling: true)
|
||||
let end = TrendScroll.position(index: count - 1, count: count, progress: 1, scrolling: true)
|
||||
precondition(abs(start - 1) < 0.000001 && abs(end - 1) < 0.000001)
|
||||
let middle = TrendScroll.position(index: count - 2, count: count, progress: 0.5, scrolling: true)
|
||||
precondition(middle < start && abs(start - middle - 0.5 / 59) < 0.000001)
|
||||
}
|
||||
precondition(TrendScroll.position(index: 0, count: 61, progress: 1, scrolling: true) < 0)
|
||||
print("PASS: append detection, missing samples, partial/full history scroll geometry")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user