feat(menubar): 用分色进度柱展示电量、供电与睡眠历史
记录系统睡眠和唤醒区间,保留真实采样空档。电量柱按固定间距从右侧滑入,以蓝色、绿色和橙黄色分别标记外接电源、电池和睡眠,支持悬浮查看历史。
This commit is contained in:
@@ -3,6 +3,7 @@ import SwiftUI
|
||||
struct PowerResourceCard: View {
|
||||
let snapshot: MetricsSnapshot
|
||||
let samples: [TrendSample]
|
||||
let sleepIntervals: [DateInterval]
|
||||
let chartInterval: TimeInterval
|
||||
let chartBoundaries: Set<Date>
|
||||
let chartIntervals: [TimeInterval]
|
||||
@@ -70,22 +71,14 @@ struct PowerResourceCard: View {
|
||||
value: MetricFormat.percent(snapshot.battery?.charge),
|
||||
status: snapshot.battery.map { label($0.flow.state) },
|
||||
warningText: snapshot.battery.map { Text(verbatim: details($0.flow)) },
|
||||
chartPlacement: .background,
|
||||
chart: {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date),
|
||||
first: samples.map(\.battery),
|
||||
color: Color("MetricBattery"), fixedScale: 1, firstValueFormat: .percent,
|
||||
sampleTooltip: { index in
|
||||
let flow = samples[index].powerFlow ?? BatteryPowerFlow()
|
||||
return AnyView(VStack(alignment: .leading, spacing: 2) {
|
||||
Text(verbatim: MetricFormat.percent(samples[index].battery) + " · " + label(flow.state)).bold()
|
||||
Text(verbatim: details(flow)).monospacedDigit()
|
||||
})
|
||||
},
|
||||
firstLabel: "metric.battery", expectedInterval: chartInterval,
|
||||
boundaryDates: chartBoundaries, intervals: chartIntervals
|
||||
)
|
||||
BatteryHistoryChart(samples: samples, sleeps: sleepIntervals) { sample in
|
||||
let flow = sample.powerFlow ?? BatteryPowerFlow()
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(verbatim: MetricFormat.percent(sample.battery) + " · " + label(flow.state)).bold()
|
||||
Text(verbatim: details(flow)).monospacedDigit()
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
InlineMetric("battery.powerShort", formatted(snapshot.battery?.flow.battery, signed: true))
|
||||
|
||||
Reference in New Issue
Block a user