fix(power): 完善电池卡片的共同供电判定、功率图标与预估续航
按适配器和电池的实际贡献判定共同供电,以双图标和双色柱展示两路功率。同步三语预估续航文案,在仅外接供电时隐藏估时行。
This commit is contained in:
@@ -69,6 +69,10 @@ import SwiftUI
|
||||
sample.date = sample.date.addingTimeInterval(2)
|
||||
sample.battery?.flow = BatteryPowerFlow(connected: true, externalSupply: true, battery: PowerReading(watts: 34.8))
|
||||
history.append(sample)
|
||||
sample.date.addTimeInterval(2)
|
||||
sample.battery?.flow = BatteryPowerFlow(connected: true, externalSupply: true,
|
||||
battery: PowerReading(watts: -8), input: PowerReading(watts: 12))
|
||||
history.append(sample)
|
||||
}
|
||||
host.rootView = AnyView(PowerResourceCard(snapshot: sample, samples: history.samples, sleepIntervals: history.sleepIntervals,
|
||||
chartInterval: 2, chartBoundaries: [], chartIntervals: history.samples.map(\.expectedInterval)))
|
||||
@@ -81,8 +85,9 @@ import SwiftUI
|
||||
let bars = plot.layoutData.bars
|
||||
precondition(plot.bounds.height >= 24 && plot.bounds.maxY < host.bounds.height)
|
||||
if state == .present {
|
||||
precondition(bars.map(\.charge) == [0.77, 0.77, 0.77])
|
||||
precondition(bars.map(\.state) == [.external, .battery, .charging])
|
||||
precondition(bars.map(\.charge) == [0.77, 0.77, 0.77, 0.77])
|
||||
precondition(bars.map(\.state) == [.external, .battery, .charging, .combined])
|
||||
precondition(bars.last?.batteryFraction == 0.4)
|
||||
for bar in bars { precondition(plot.layoutData.hit(at: bar.x) == .sample(bar.index)) }
|
||||
} else { precondition(bars.isEmpty) }
|
||||
}
|
||||
@@ -161,6 +166,13 @@ import SwiftUI
|
||||
snapshot.battery = BatteryMetrics(charge: charge, flow: flow)
|
||||
history.append(snapshot)
|
||||
}
|
||||
let joint = BatteryPowerFlow(connected: true, externalSupply: true, battery: PowerReading(watts: -10),
|
||||
input: PowerReading(watts: 10))
|
||||
for _ in 0..<3 {
|
||||
snapshot.date.addTimeInterval(2)
|
||||
snapshot.battery = BatteryMetrics(charge: 1, flow: joint)
|
||||
history.append(snapshot)
|
||||
}
|
||||
let plot = BatteryHistoryPlot(frame: CGRect(x: 0, y: 0, width: 590, height: 51))
|
||||
let layout = BatteryHistoryLayout(samples: history.samples, sleeps: [], width: plot.bounds.width)
|
||||
plot.layoutData = layout
|
||||
@@ -175,6 +187,12 @@ import SwiftUI
|
||||
precondition((0.1...0.4).contains(alpha(bars[i].x, 16)))
|
||||
precondition((0.1...0.4).contains(alpha(bars[i].x, 34)))
|
||||
}
|
||||
let jointX = Int(bars[5].x * CGFloat(bitmap.pixelsWide) / plot.bounds.width)
|
||||
let jointPixels = [10, 30].map { y in
|
||||
bitmap.colorAt(x: jointX, y: y * bitmap.pixelsHigh / Int(plot.bounds.height))!.usingColorSpace(.sRGB)!
|
||||
}
|
||||
precondition(jointPixels.contains { $0.blueComponent > $0.greenComponent } &&
|
||||
jointPixels.contains { $0.greenComponent > $0.blueComponent })
|
||||
let half = [alpha(bars[1].x, 16), alpha(bars[1].x, 34)].sorted()
|
||||
precondition((0.1...0.4).contains(half[0]) && half[1] > 0.95)
|
||||
precondition(alpha(bars[2].x, 16) > 0.95 && alpha(bars[2].x, 34) > 0.95)
|
||||
|
||||
Reference in New Issue
Block a user