feat(panel): 调整资源卡片读数布局并保留趋势平移
逐核显示 CPU 占用,在 GPU 标题展示核数并补充分项读数。无电池设备显示整机功率。 存储与网络将曲线排在详情下方,CPU、GPU、内存和电池保留整卡趋势。数值直接刷新,曲线随采样平滑平移。顶栏展示版本号,底栏调整开机时间和刷新间隔。
This commit is contained in:
@@ -10,14 +10,14 @@ import SwiftUI
|
||||
precondition(last > 0 && first - last <= 1)
|
||||
let columns = rows.max()!
|
||||
let cellWidth = (width - Double(columns - 1) * 3) / Double(columns)
|
||||
precondition(cellWidth >= 6, "Each real core needs its own visible meter cell")
|
||||
precondition(cellWidth >= 7, "Each real core needs its own visible meter cell")
|
||||
}
|
||||
}
|
||||
}
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 18, width: 430) == [18])
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 18, width: 280) == [18])
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 32, width: 430) == [32])
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 48, width: 430) == [48])
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 48, width: 430) == [24, 24])
|
||||
for count in [0, 1, 4, 8, 14, 18, 24, 32, 48, 128] {
|
||||
let kinds = Dictionary(uniqueKeysWithValues: (0..<count).map { ($0, $0 < count / 3 ? CPUCoreTopology.Kind.efficiency : .performance) })
|
||||
let groups = CPUCoreGrid.groups(count: count, kinds: kinds)
|
||||
@@ -37,11 +37,10 @@ import SwiftUI
|
||||
precondition(CPUCoreGridLayout.rowCounts(count: 128, width: width).reduce(0, +) == 128)
|
||||
}
|
||||
precondition(CPUCoreGrid.groups(count: 3, kinds: [0: .efficiency]).count == 2)
|
||||
precondition(SegmentedCoreBar.portions(0) == [0,0,0,0])
|
||||
precondition(SegmentedCoreBar.portions(0.125) == [0.5,0,0,0])
|
||||
precondition(SegmentedCoreBar.portions(0.5) == [1,1,0,0])
|
||||
precondition(SegmentedCoreBar.portions(1) == [1,1,1,1])
|
||||
for invalid: Double? in [nil,.nan,-1] { precondition(SegmentedCoreBar.portions(invalid) == [0,0,0,0]) }
|
||||
let m4 = CPUCoreGrid.groups(count: 14, kinds: Dictionary(uniqueKeysWithValues:
|
||||
(0..<14).map { ($0, $0 < 4 ? CPUCoreTopology.Kind.efficiency : .performance) }))
|
||||
let widths = CPUCoreGrid.groupWidths(groups: m4, width: 185)
|
||||
precondition(zip(m4, widths).map { CPUCoreGridLayout.rowCounts(count: $0.count, width: $1) } == [[4], [10]])
|
||||
print("PASS: compact per-core meters with intact identities and bounded wrapping at multiple widths/counts")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import SwiftUI
|
||||
styleMask: [.borderless], backing: .buffered, defer: false)
|
||||
window.isReleasedWhenClosed = false
|
||||
window.level = .floating
|
||||
let host = NSHostingView(rootView: Example(value: "128", probe: probe))
|
||||
let host = NSHostingView(rootView: Example(value: "12.8 W", probe: probe))
|
||||
host.sizingOptions = []
|
||||
window.contentView = host
|
||||
window.orderFrontRegardless()
|
||||
@@ -22,18 +22,18 @@ import SwiftUI
|
||||
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 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(settled) == pixels(after),
|
||||
"A sample must settle immediately without numeric rolling or a later animation frame")
|
||||
host.rootView = Example(value: "12.9 W", probe: probe)
|
||||
try? await Task.sleep(for: .milliseconds(40))
|
||||
let updated = pixels(bitmap(host))
|
||||
precondition(updated != pixels(before), "The next render must display the new reading")
|
||||
try? await Task.sleep(for: .milliseconds(500))
|
||||
precondition(updated == pixels(bitmap(host)), "Updated digits must be stationary")
|
||||
host.rootView = Example(value: "12.8 W", probe: probe)
|
||||
try? await Task.sleep(for: .milliseconds(40))
|
||||
precondition(pixels(bitmap(host)) == pixels(before), "A decrease must restore the original digits immediately")
|
||||
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, locale: "zh_CN")
|
||||
host.rootView = Example(value: "12.9 W", probe: probe, locale: "zh_CN")
|
||||
try? await Task.sleep(for: .milliseconds(100))
|
||||
precondition(probe.locale == "zh_CN")
|
||||
window.setContentSize(NSSize(width: 360, height: 100))
|
||||
@@ -44,7 +44,7 @@ import SwiftUI
|
||||
}
|
||||
let child = childHost(host)
|
||||
precondition(child?.bounds.size == host.bounds.size, "The parent must remain the sole frame owner")
|
||||
host.rootView = Example(value: "345", probe: probe, visible: false)
|
||||
host.rootView = Example(value: "12.9 W", probe: probe, visible: false)
|
||||
try? await Task.sleep(for: .milliseconds(150))
|
||||
precondition(probe.disappearances == 1)
|
||||
let releaseDeadline = ContinuousClock.now.advanced(by: .seconds(1))
|
||||
@@ -55,7 +55,7 @@ import SwiftUI
|
||||
window.orderOut(nil)
|
||||
window.contentView = nil
|
||||
window.close()
|
||||
print("PASS: static card host preserves immediate stable text, inherited font/style/locale, child state, resize and unmount")
|
||||
print("PASS: card host displays stationary updated digits and preserves inherited font/style/locale, child state, resize and unmount")
|
||||
fflush(stdout)
|
||||
NSApp.terminate(nil)
|
||||
}
|
||||
@@ -118,12 +118,12 @@ import SwiftUI
|
||||
}
|
||||
return data
|
||||
}
|
||||
private static func redPixels(_ bitmap: NSBitmapImageRep) -> Int {
|
||||
private static func redPixels(_ bitmap: NSBitmapImageRep, contrast: CGFloat = 0.2) -> Int {
|
||||
var count = 0
|
||||
for x in 0..<bitmap.pixelsWide {
|
||||
for y in 0..<bitmap.pixelsHigh {
|
||||
if let color = bitmap.colorAt(x: x, y: y)?.usingColorSpace(.deviceRGB),
|
||||
color.redComponent > color.greenComponent + 0.2 && color.redComponent > color.blueComponent + 0.2 {
|
||||
(color.redComponent - max(color.greenComponent, color.blueComponent)) * color.alphaComponent > contrast {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +95,20 @@ import QuartzCore
|
||||
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")
|
||||
var moving = NativePanelCurve.Input(frame: appended, colors: [.red], scales: [1], maximumGap: 5, animates: true)
|
||||
plot.configure(.init(frame: fullFrame, colors: [.red], scales: [1], maximumGap: 5))
|
||||
plot.configure(moving)
|
||||
let slide = plot.curves.animation(forKey: "trend.slide") as? CABasicAnimation
|
||||
let start = (slide?.fromValue as? NSValue)?.caTransform3DValue
|
||||
precondition(abs((start?.m41 ?? 0) - 280.0/59) < 0.001 && slide?.duration == 0.35)
|
||||
let movingBuilds = plot.pathBuildCount
|
||||
moving.hoveredIndex = 3
|
||||
plot.configure(moving)
|
||||
precondition(plot.curves.animationKeys()?.isEmpty != false && plot.pathBuildCount == movingBuilds)
|
||||
plot.configure(.init(frame: .init(dates: Array(appended.dates.dropFirst()) + [Date(timeIntervalSinceReferenceDate: 122)],
|
||||
series: appended.series, intervals: appended.intervals, boundaryDates: [Date(timeIntervalSinceReferenceDate: 122)]),
|
||||
colors: [.red], scales: [1], maximumGap: 5, animates: true))
|
||||
precondition(plot.curves.animationKeys()?.isEmpty != false, "Do not slide through a pause")
|
||||
// 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))
|
||||
@@ -163,7 +177,7 @@ import QuartzCore
|
||||
assertStatic(plot.layer!)
|
||||
plot.removeFromSuperview()
|
||||
window.orderOut(nil); window.close()
|
||||
print("PASS: bidirectional rate areas/zero axis/direction/hover/gaps, stacked component pixels and cumulative hover, static background lines/area pixels, no single-point fill, hidden-series isolation, immediate stable updates, no animation/material/gradient layers, real gaps, hover cache, palette growth, appearance, full history and unmount")
|
||||
print("PASS: bidirectional rate areas/zero axis/direction/hover/gaps, stacked component pixels and cumulative hover, static background lines/area pixels, no single-point fill, hidden-series isolation, reduced-motion stable updates, rolling transform and hover cancellation, real gaps, hover cache, palette growth, appearance, full history and unmount")
|
||||
fflush(stdout); NSApp.terminate(nil)
|
||||
}
|
||||
NSApp.run()
|
||||
|
||||
@@ -46,11 +46,11 @@ import CoreGraphics
|
||||
precondition(PanelLayout.columns(width: 648) == 3 && PanelLayout.columns(width: 620) == 3)
|
||||
precondition(PanelLayout.columns(width: 619) == 2 && PanelLayout.columns(width: 430) == 2 && PanelLayout.columns(width: 429) == 1)
|
||||
let tallerCPU = PanelLayout.cardHeights(coreRows: 6, fanCount: 2)
|
||||
precondition(PanelLayout.rowHeights(columns: 3, heights: tallerCPU) == [346, 346],
|
||||
precondition(PanelLayout.rowHeights(columns: 3, heights: tallerCPU) == [251, 251],
|
||||
"All resource rows must share the maximum structural card height")
|
||||
let moreFans = PanelLayout.cardHeights(coreRows: 1, fanCount: 10)
|
||||
precondition(moreFans[.gpu]! > compact[.gpu]! && moreFans[.storage] == compact[.storage])
|
||||
precondition(PanelLayout.rowHeights(columns: 3, heights: moreFans) == [232, 232])
|
||||
precondition(PanelLayout.rowHeights(columns: 3, heights: moreFans) == [248, 248])
|
||||
let noFans = PanelLayout.cardHeights(coreRows: 1, fanCount: 0)
|
||||
precondition(noFans[.gpu] == 176 && PanelLayout.rowHeights(columns: 3, heights: noFans) == [176, 176])
|
||||
precondition(PanelLayout.preferredHeight(width: 648, heights: noFans) == 630,
|
||||
@@ -64,7 +64,7 @@ import CoreGraphics
|
||||
precondition(requested.height == 732, "A hardware-driven height above the default must be preserved")
|
||||
precondition(PanelLayout.processHeight(heights: compact) == 176)
|
||||
precondition(PanelLayout.dashboardHeight(columns: 3, heights: compact) == 540)
|
||||
precondition(PanelLayout.processHeight(heights: tallerCPU) == 346)
|
||||
precondition(PanelLayout.processHeight(heights: tallerCPU) == 251)
|
||||
let input: [ProcessMetrics] = (0..<2000).map { (index: Int) -> ProcessMetrics in
|
||||
let id = ProcessIdentity(pid: Int32(index + 1), seconds: 1, microseconds: 0)
|
||||
let path: String? = index == 42 ? "/test/needle" : nil
|
||||
|
||||
@@ -27,32 +27,26 @@ import SwiftUI
|
||||
precondition(plots.count == 1)
|
||||
let plot = plots[0]
|
||||
precondition(abs(host.bounds.width - width) < 1, "AppKit may round fractional content sizes to a point")
|
||||
precondition(abs(plot.bounds.width - host.bounds.width) < 0.5 && abs(plot.bounds.height - host.bounds.height) < 0.5,
|
||||
"The background chart must occupy the full card width and height, without axes or plot insets")
|
||||
let graph = topRect(plot, in: host)
|
||||
precondition(abs(graph.minY) < 0.5 && abs(graph.maxY - host.bounds.height) < 0.5,
|
||||
"The background chart must end at the card bottom")
|
||||
let detail = topRect(probe.view!, in: host)
|
||||
precondition(detail.minY >= 0 && detail.maxY <= host.bounds.height && detail.width <= host.bounds.width - 20 + 0.5,
|
||||
"Foreground details must overlay the full-height graph within card bounds, including narrow/localized cards")
|
||||
precondition(abs(graph.width - host.bounds.width) < 0.5 && abs(graph.maxY - host.bounds.height) < 0.5)
|
||||
precondition(detail.maxY + 3 <= graph.minY && graph.height >= 32,
|
||||
"The plot must sit entirely below the text at every width and locale")
|
||||
precondition(plot.grid.isHidden && plot.input?.visibleSeriesCount == 1)
|
||||
let bitmap = host.bitmapImageRepForCachingDisplay(in: host.bounds)!
|
||||
host.cacheDisplay(in: host.bounds, to: bitmap)
|
||||
func sample(_ y: Double) -> [Double] {
|
||||
let c = bitmap.colorAt(x: bitmap.pixelsWide / 2, y: Int(y * Double(bitmap.pixelsHigh) / 176))!.usingColorSpace(.deviceRGB)!
|
||||
return [Double(c.redComponent), Double(c.greenComponent), Double(c.blueComponent)]
|
||||
}
|
||||
let base = sample(3)
|
||||
let covered = zip(sample(80), base).reduce(0.0) { $0 + abs($1.0 - $1.1) }
|
||||
let open = zip(sample(150), base).reduce(0.0) { $0 + abs($1.0 - $1.1) }
|
||||
precondition(open > 0.02 && abs(covered - open) < 0.01,
|
||||
"Charts must retain the same color under foreground details and bottom whitespace: \(covered), \(open)")
|
||||
for kind in 0...1 {
|
||||
host.rootView = AnyView(detailsFixture(kind: kind, probe: probe)
|
||||
.environment(\.locale, Locale(identifier: language))
|
||||
.environment(\.colorScheme, dark ? .dark : .light))
|
||||
try? await Task.sleep(for: .milliseconds(60)); host.layoutSubtreeIfNeeded()
|
||||
let details = topRect(probe.view!, in: host)
|
||||
let trend = descendants(host).compactMap { $0 as? NativePanelCurve.PlotView }.first!
|
||||
let plotRect = topRect(trend, in: host)
|
||||
if kind == 0 {
|
||||
precondition(plotRect == host.bounds, "Physical memory capacity must map to the top of the card")
|
||||
} else {
|
||||
precondition(plotRect.height >= 24 && plotRect.minY >= details.maxY + 3,
|
||||
"Storage details must leave a separate usable plot")
|
||||
}
|
||||
precondition(details.maxY <= host.bounds.height - 10 + 0.5 && details.width <= host.bounds.width - 20 + 0.5,
|
||||
"Larger production details must fit the unchanged card: \(kind), \(language), \(width), \(details)")
|
||||
}
|
||||
@@ -60,11 +54,32 @@ import SwiftUI
|
||||
}
|
||||
}
|
||||
}
|
||||
// Mount the production branch with a desktop, a missing sensor and a failed battery read.
|
||||
for state: BatteryAvailability in [.absent, .failed, .present, .unknown] {
|
||||
var sample = MetricsSnapshot()
|
||||
sample.batteryState = state
|
||||
sample.systemPower = state == .absent ? 32.5 : nil
|
||||
if state == .present { sample.battery = BatteryMetrics(charge: 0.8, charging: false, externalPower: true, power: 0) }
|
||||
var history = MetricHistory()
|
||||
history.append(sample)
|
||||
sample.date = sample.date.addingTimeInterval(2); sample.systemPower = nil
|
||||
history.append(sample)
|
||||
host.rootView = AnyView(PowerResourceCard(snapshot: sample, samples: history.samples,
|
||||
chartInterval: 2, chartBoundaries: [], chartIntervals: [2,2]))
|
||||
try? await Task.sleep(for: .milliseconds(80)); host.layoutSubtreeIfNeeded()
|
||||
let plot = descendants(host).compactMap { $0 as? NativePanelCurve.PlotView }.first!
|
||||
let first = plot.input?.frame.series.first
|
||||
switch state {
|
||||
case .absent: precondition(first == [32.5, nil] && plot.input?.scales.first == 32.5)
|
||||
case .present: precondition(first == [0.8, 0.8] && plot.input?.scales.first == 1 && topRect(plot, in: host) == host.bounds)
|
||||
default: precondition(first == [nil, nil] && plot.input?.scales.first == 1)
|
||||
}
|
||||
}
|
||||
host.rootView = AnyView(EmptyView())
|
||||
try? await Task.sleep(for: .milliseconds(100))
|
||||
precondition(descendants(host).allSatisfy { !($0 is NativePanelCurve.PlotView) })
|
||||
window.orderOut(nil); window.contentView = nil; window.close()
|
||||
print("PASS: production card geometry at 190/205⅓/400pt, light/dark, three languages, full-height chart without foreground dimming, larger localized memory/storage detail bounds, unmount")
|
||||
print("PASS: production card geometry at 190/205⅓/400pt, light/dark, three languages, separate plot below text, localized memory/storage details, unmount")
|
||||
NSApp.terminate(nil)
|
||||
}
|
||||
NSApp.run()
|
||||
@@ -90,7 +105,7 @@ import SwiftUI
|
||||
health: .init(remainingLife: 0.98, powerOnHours: 99999),
|
||||
io: .init(read: 999_900_000_000, written: 999_900_000_000)))
|
||||
return ResourceCard(title: kind == 0 ? "metric.memory" : "metric.disk", symbol: "memorychip", color: .blue,
|
||||
value: "26.0 / 48 GiB", chart: { Color.clear }) {
|
||||
value: "26.0 / 48 GiB", chartPlacement: kind == 0 ? .background : .belowDetails, chart: { PanelTrendChart(dates: [Date()], first: [0.5], color: .blue) }) {
|
||||
details.background(DetailMarker(probe: probe).allowsHitTesting(false))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user