fix(power): 完善电池卡片的共同供电判定、功率图标与预估续航
按适配器和电池的实际贡献判定共同供电,以双图标和双色柱展示两路功率。同步三语预估续航文案,在仅外接供电时隐藏估时行。
This commit is contained in:
@@ -61,7 +61,7 @@ SystemSampler actor 持有差分基线。网络采样按接口名关联前后两
|
|||||||
|
|
||||||
ResourceCard 通过 NativeContentHost 使用固定尺寸的独立 NSHostingView,传递字体、颜色、语言及外观环境;更新沿用挂载身份,卸载清空子宿主内容。CPU、GPU 和内存采用整卡背景图,卡片顶边对应 100% 或物理内存总量,底边对应零。存储、网络与无电池整机功率图使用详情下方的剩余高度。辅助信息主要为 10pt / 16pt 行高,内存和存储详情通过 ViewThatFits 按信息组换行,默认卡片仍为 176pt 高。统一 16pt 圆角、10pt 前景内边距和静态轻阴影,图表锚点和提示在同一宿主内处理;不显示常驻图例、数值坐标轴、网格或起止时间。
|
ResourceCard 通过 NativeContentHost 使用固定尺寸的独立 NSHostingView,传递字体、颜色、语言及外观环境;更新沿用挂载身份,卸载清空子宿主内容。CPU、GPU 和内存采用整卡背景图,卡片顶边对应 100% 或物理内存总量,底边对应零。存储、网络与无电池整机功率图使用详情下方的剩余高度。辅助信息主要为 10pt / 16pt 行高,内存和存储详情通过 ViewThatFits 按信息组换行,默认卡片仍为 176pt 高。统一 16pt 圆角、10pt 前景内边距和静态轻阴影,图表锚点和提示在同一宿主内处理;不显示常驻图例、数值坐标轴、网格或起止时间。
|
||||||
|
|
||||||
StackedSeries 仅在渲染时构建累计上下边界:CPU 自下而上为系统 / 用户,内存为应用 / 联动 / 压缩。GPU 同轴绘制总占用、渲染器、分块器三条独立曲线,仅总占用填色。标题后的胶囊显示驱动报告的核心数,正文显示两个阶段读数。任一必要分量缺失或无效时不构造部分总量,原始历史不变。NativePanelCurve 按连续段在匹配的上下边界间闭合面积,保留真实断点;悬浮使用缓存累计边界定位,而提示读取原始分量。有内置电池时,SystemSampler 持有 BatteryMonitor 的采样标记,快照和历史保存 BatteryPowerFlow(供电状态、输入、电池及系统瓦数和读数来源)。BatteryHistoryChart 在详情下方以固定柱距从右向左滚动。一次连续采样移动一格,绘图区左侧多绘一格用于自然移出。停采间隔占独立空档,按配对事件的真实起止在空档中标出睡眠。供电分段来自样本的 powerFlow。绘制与悬浮共用布局,悬浮、暂停和减弱动态效果时直接显示最终位置。可见详情按面板节奏通过签名 XPC 读取固定 B0AP 电池功率,失败独立退避并回退到电池报告。App 订阅 kIOPSNotifyPowerSource;面板可见且采样启用时立即重采,并在最多一秒的调度间隔后复读一次,再使用设置的周期。仅在 IOPowerSources 确认无内置电池时,前台详情轮次通过固定只读 XPC 请求 AppleSMC PSTR,快照和历史独立保存整机瓦数。请求最多一个在途、2 秒超时,不可用退避 60–600 秒,不用旧值填充历史。存储 / 网络通过 PanelCurveProjection.split 在自绘图区顶向下 60% 位置绘制零轴,读取 / 上传向上、写入 / 下载向下,两侧各使用绘图区高度 30% 的振幅并共享自动速率尺度,峰值不映射到卡片顶边。原始速率仍为正值,提示、标记与面积采用同一投影,保留缺失与真实断点。内存的已用三层包含匿名应用 / 系统进程、联动和压缩器物理内存;缓存 / Swap 口径见监控文档,不再显示重复容量进度条。
|
StackedSeries 仅在渲染时构建累计上下边界:CPU 自下而上为系统 / 用户,内存为应用 / 联动 / 压缩。GPU 同轴绘制总占用、渲染器、分块器三条独立曲线,仅总占用填色。标题后的胶囊显示驱动报告的核心数,正文显示两个阶段读数。任一必要分量缺失或无效时不构造部分总量,原始历史不变。NativePanelCurve 按连续段在匹配的上下边界间闭合面积,保留真实断点;悬浮使用缓存累计边界定位,而提示读取原始分量。有内置电池时,SystemSampler 持有 BatteryMonitor 的采样标记,快照和历史保存 BatteryPowerFlow(供电状态、输入、电池及系统瓦数和读数来源)。BatteryHistoryChart 在详情下方以固定柱距从右向左滚动。一次连续采样移动一格,绘图区左侧多绘一格用于自然移出。停采间隔占独立空档,按配对事件的真实起止在空档中标出睡眠。供电分段来自样本的 powerFlow。共同供电时保留同一组遥测中的两路供给值,前台 B0AP 复核放电方向,卡片与历史图共用该组数据计算蓝绿占比。绘制与悬浮共用布局,悬浮、暂停和减弱动态效果时直接显示最终位置。可见详情按面板节奏通过签名 XPC 读取固定 B0AP 电池功率,失败独立退避并回退到电池报告。App 订阅 kIOPSNotifyPowerSource;面板可见且采样启用时立即重采,并在最多一秒的调度间隔后复读一次,再使用设置的周期。仅在 IOPowerSources 确认无内置电池时,前台详情轮次通过固定只读 XPC 请求 AppleSMC PSTR,快照和历史独立保存整机瓦数。请求最多一个在途、2 秒超时,不可用退避 60–600 秒,不用旧值填充历史。存储 / 网络通过 PanelCurveProjection.split 在自绘图区顶向下 60% 位置绘制零轴,读取 / 上传向上、写入 / 下载向下,两侧各使用绘图区高度 30% 的振幅并共享自动速率尺度,峰值不映射到卡片顶边。原始速率仍为正值,提示、标记与面积采用同一投影,保留缺失与真实断点。内存的已用三层包含匿名应用 / 系统进程、联动和压缩器物理内存;缓存 / Swap 口径见监控文档,不再显示重复容量进度条。
|
||||||
|
|
||||||
MetricText 用等宽数字直接显示当前读数。连续追加时 NativePanelCurve 在已有 curves 图层进行 0.35 秒水平变换,历史满窗时绘制一个出界旧点;不逐帧重建路径。悬浮时对齐最终位置,暂停、减弱动态效果与断点不启动滚动。风扇是唯一持续动效:FanRotor 将 SF Symbol 绘制到独立图像子图层,固定中心锚点和位置,使用原生 Core Animation 旋转子图层,AppKit 宿主图层保持不变,按历史 RPM 档位映射 90 / 180 / 300 / 450°/s,切档保留相位;零 / 无效 / 缺失值、系统减弱动态效果、暂停、隐藏、遮挡、睡眠或卸载时停止。没有新增帧计时器。样式与异常状态见 [UI 设计规范](ui-design-standard.md)。
|
MetricText 用等宽数字直接显示当前读数。连续追加时 NativePanelCurve 在已有 curves 图层进行 0.35 秒水平变换,历史满窗时绘制一个出界旧点;不逐帧重建路径。悬浮时对齐最终位置,暂停、减弱动态效果与断点不启动滚动。风扇是唯一持续动效:FanRotor 将 SF Symbol 绘制到独立图像子图层,固定中心锚点和位置,使用原生 Core Animation 旋转子图层,AppKit 宿主图层保持不变,按历史 RPM 档位映射 90 / 180 / 300 / 450°/s,切档保留相位;零 / 无效 / 缺失值、系统减弱动态效果、暂停、隐藏、遮挡、睡眠或卸载时停止。没有新增帧计时器。样式与异常状态见 [UI 设计规范](ui-design-standard.md)。
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
## 实现与验证
|
## 实现与验证
|
||||||
|
|
||||||
已接入 MetricsStore、MetricHistory 和三语电池卡片。BatteryHistoryLayout 按采样顺序从右缘排柱,普通连续更新向左平移一格。短历史左侧留空,长间隔压缩为独立空档,睡眠按实际起止在空档内定位。电源状态用蓝色和插头、闪电或加号,电池用绿色,睡眠用等距橙黄色柱和月亮。每根柱子单独绘制实色电量和半透明剩余轨道,底部图标按状态分组。保留电量缺测时已知的供电状态。睡眠期间单独显示起止时间。
|
已接入 MetricsStore、MetricHistory 和三语电池卡片。BatteryHistoryLayout 按采样顺序从右缘排柱,普通连续更新向左平移一格。短历史左侧留空,长间隔压缩为独立空档,睡眠按实际起止在空档内定位。电源状态用蓝色和插头或闪电,共同供电使用插头、电池双图标与蓝绿分段柱,电池用绿色,睡眠用等距橙黄色柱和月亮。每根柱子单独绘制实色电量和半透明剩余轨道,底部图标按状态分组。保留电量缺测时已知的供电状态。睡眠期间单独显示起止时间。
|
||||||
|
|
||||||
[实际卡片示例](designs/battery-history/power-states.png)使用模拟读数,从左到右依次为接电、电池供电、睡眠、电池供电、充电、接电。
|
[实际卡片示例](designs/battery-history/power-states.png)使用模拟读数,从左到右依次为接电、电池供电、睡眠、电池供电、充电、接电。
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 27 KiB |
+2
-2
@@ -20,7 +20,7 @@ CPU / GPU 的零值与 100% 分别映射到卡片底边和顶边,内存卡片
|
|||||||
| 存储容量 | `DiskMonitor`,URL volume resource values | 主卡片为主目录所在卷;卷列表仅本地且非隐藏挂载卷。APFS 卷共享容器空间,不应直接累加 |
|
| 存储容量 | `DiskMonitor`,URL volume resource values | 主卡片为主目录所在卷;卷列表仅本地且非隐藏挂载卷。APFS 卷共享容器空间,不应直接累加 |
|
||||||
| 存储 IO | `DiskIOMonitor`,IOBlockStorageDriver 累计字节 | 物理块设备读写速率,非主卷文件 IO;设备集合变化、计数回退、首次读取均重建基线 |
|
| 存储 IO | `DiskIOMonitor`,IOBlockStorageDriver 累计字节 | 物理块设备读写速率,非主卷文件 IO;设备集合变化、计数回退、首次读取均重建基线 |
|
||||||
| SMART | `DiskHealthMonitor` → XPC → `diskutil info -plist` | 主目录所在卷关联报告中的寿命和通电时间;剩余寿命 = 100 − PERCENTAGE_USED(下限 0),通电小时要求高位为 0,多物理存储拒绝合并;不代表所有卷或磁盘 |
|
| SMART | `DiskHealthMonitor` → XPC → `diskutil info -plist` | 主目录所在卷关联报告中的寿命和通电时间;剩余寿命 = 100 − PERCENTAGE_USED(下限 0),通电小时要求高位为 0,多物理存储拒绝合并;不代表所有卷或磁盘 |
|
||||||
| 电池 | `BatteryMonitor`,IOPowerSources 与 AppleSmartBattery | 电池净功率正充负放,可见时优先经 XPC 读取 B0AP(si32,小端毫瓦),不支持时读取 PowerTelemetryData.BatteryPower,回退到电池端电压 × 带符号电流,同次输入和负载的差值标 ≈。适配器实际输入与报告能力分列;无内置电池、读取失败分别处理 |
|
| 电池 | `BatteryMonitor`,IOPowerSources 与 AppleSmartBattery | 电池净功率正充负放,可见时优先经 XPC 读取 B0AP(si32,小端毫瓦),不支持时读取 PowerTelemetryData.BatteryPower,回退到电池端电压 × 带符号电流,同次输入和负载的差值标 ≈。共同供电要求两路各至少 0.5 W,按同组遥测的实际输入和放电计算占比。三项直读时,功率平衡残差容许 1 W 或负载的 10%,取较大者。阈值为应用判断口径。适配器实际输入与报告能力分列;无内置电池、读取失败分别处理 |
|
||||||
| 无电池整机功率 | 签名 XPC 只读 AppleSMC 固定键 PSTR | 传感器即时整机功率 W,不是插座侧计量;字段口径可对照 [Stats 传感器表](https://github.com/exelban/stats/blob/master/Modules/Sensors/values.swift)。不支持或读取失败显示不可用,不用电池或进程功率替代 |
|
| 无电池整机功率 | 签名 XPC 只读 AppleSMC 固定键 PSTR | 传感器即时整机功率 W,不是插座侧计量;字段口径可对照 [Stats 传感器表](https://github.com/exelban/stats/blob/master/Modules/Sensors/values.swift)。不支持或读取失败显示不可用,不用电池或进程功率替代 |
|
||||||
| 电池健康 | `SystemBatteryHealthMonitor`,`system_profiler SPPowerDataType -json` | 使用系统报告的最大容量百分比,不用当前充电容量推算 |
|
| 电池健康 | `SystemBatteryHealthMonitor`,`system_profiler SPPowerDataType -json` | 使用系统报告的最大容量百分比,不用当前充电容量推算 |
|
||||||
| 网络 | `NetworkMonitor`,`NET_RT_IFLIST2` 64 位计数与 `getifaddrs` | 累计收发计数不属于应用会话流量;速率按实际经过时间差分,回退或接口身份 / 地址变化时重建基线;计数缓冲在采样器内复用,容量不足时扩容,仅解析本轮实际返回字节;本地地址保持系统 numeric formatter(含 scope),每轮共用地址缓冲、每接口最终排序一次 |
|
| 网络 | `NetworkMonitor`,`NET_RT_IFLIST2` 64 位计数与 `getifaddrs` | 累计收发计数不属于应用会话流量;速率按实际经过时间差分,回退或接口身份 / 地址变化时重建基线;计数缓冲在采样器内复用,容量不足时扩容,仅解析本轮实际返回字节;本地地址保持系统 numeric formatter(含 scope),每轮共用地址缓冲、每接口最终排序一次 |
|
||||||
@@ -41,7 +41,7 @@ CPU / GPU 的零值与 100% 分别映射到卡片底边和顶边,内存卡片
|
|||||||
- GPU Renderer / Tiler 是活动阶段指标,可能重叠,不能相加成为总占用。GPU 核心数不代表逐核计数;目前没有独立逐核 GPU 占用。
|
- GPU Renderer / Tiler 是活动阶段指标,可能重叠,不能相加成为总占用。GPU 核心数不代表逐核计数;目前没有独立逐核 GPU 占用。
|
||||||
- 网络“全部”仅汇总 active 且名称以 `en` 开头的接口,避免物理链路与 `utun` 双计。接口选择仍可查看其他活动接口;这个规则不等于所有设备和隧道的通用流量归因。
|
- 网络“全部”仅汇总 active 且名称以 `en` 开头的接口,避免物理链路与 `utun` 双计。接口选择仍可查看其他活动接口;这个规则不等于所有设备和隧道的通用流量归因。
|
||||||
- 进程 CPU 以一个逻辑核满载为 100%,多线程可超过 100%,不能直接与整机 CPU 百分比比较。首次进程采样没有差分值;功率列使用独立 CPU 能量计数差分,不能将进程 CPU 百分比当成耗电。
|
- 进程 CPU 以一个逻辑核满载为 100%,多线程可超过 100%,不能直接与整机 CPU 百分比比较。首次进程采样没有差分值;功率列使用独立 CPU 能量计数差分,不能将进程 CPU 百分比当成耗电。
|
||||||
- 电池卡片在系统报告充电时显示距充满的估时,电池供电时显示剩余续航。外接供电且未充电时显示不适用,系统未提供有效估时则显示相应提示。
|
- 电池卡片在系统报告充电时显示距充满的估时,放电或共同供电时显示预估续航。仅外接供电时隐藏整行估时,系统未提供有效估时则显示相应提示。
|
||||||
|
|
||||||
## 采样与缓存周期
|
## 采样与缓存周期
|
||||||
|
|
||||||
|
|||||||
@@ -54,3 +54,11 @@ IOPowerSources 提供电源状态与适配器信息入口;IORegistry 遥测字
|
|||||||
充入 6 W、插电补放、纯电池放电、供电切换与缺测使用独立 Swift 样本检查;无电池分支使用挂载的生产卡片检查。真实拔插、充电、共同供电及无电池机型仍待对应硬件状态验证。
|
充入 6 W、插电补放、纯电池放电、供电切换与缺测使用独立 Swift 样本检查;无电池分支使用挂载的生产卡片检查。真实拔插、充电、共同供电及无电池机型仍待对应硬件状态验证。
|
||||||
|
|
||||||
用户拔电实测后恢复了大号电量百分比及背景电量曲线,净功率回到详情行。面板可见时,插拔通知触发一次立即采样和一次短间隔复读。签名应用在这台已拔电的 Mac 上实际显示 77% 和 −13.4 W;连续六个前台样本都从 B0AP 读到放电瓦数。通知调度和缓存滞后以回归用例验证,尚未测量从物理拔插到首次更新的端到端时间。
|
用户拔电实测后恢复了大号电量百分比及背景电量曲线,净功率回到详情行。面板可见时,插拔通知触发一次立即采样和一次短间隔复读。签名应用在这台已拔电的 Mac 上实际显示 77% 和 −13.4 W;连续六个前台样本都从 B0AP 读到放电瓦数。通知调度和缓存滞后以回归用例验证,尚未测量从物理拔插到首次更新的端到端时间。
|
||||||
|
|
||||||
|
## 共同供电修订
|
||||||
|
|
||||||
|
1. 在 Core 核对同一组遥测的输入与电池放电,按两路实际供给计算占比,隔离前台 B0AP 与控制器不同时间窗。两路分别达到 0.5 W 才认作共同供电。缺少可靠证据时只显示已知状态。
|
||||||
|
2. MenuBar 在卡片和历史按同一状态显示双图标与两路功率,柱高保持电量含义。接电放电时尝试电池报告的剩余时间。
|
||||||
|
3. 用本机微量输入和可重复的双源样本验证方向、差值、过期数据、历史、紧凑卡片与三语;打包独立测试 ZIP。兼容只有电量或缺少部分传感器的设备。
|
||||||
|
|
||||||
|
在本机打开签名 Debug 面板采得连续五个样本,适配器输入 0.085 W、B0AP 显示电池放电,均判为电池供电。另一次读取获得电池报告的剩余 389 分钟。实际双源负载用模拟数据验证:适配器 12 W、电池输出 8 W 时,190pt 宽卡片展示两路瓦数和双图标,实色柱段的电池占比为 40%。见[模拟样本的实际卡片](designs/battery-history/joint-supply.png)。放电时优先使用有效的系统剩余时间,缺测时回退至新鲜的电池组 AvgTimeToEmpty,过滤 65535 未知值。[Smart Battery 规范](https://sbs-forum.org/specs/sbdata10.pdf)
|
||||||
|
|||||||
+1
-1
@@ -43,7 +43,7 @@ python3 tools/check.py --list
|
|||||||
| NativeMetricDrawingChecks(--gui) | 实际曲线 / 堆叠色带、带符号瓦数零线与两端悬浮点、双向速率面积和零轴、方向 / 悬浮 / 断点及累计边界定位、单点无虚构填充、隐藏序列隔离、缺失点接续与真实断点、悬浮缓存、滚动时间域变换、悬浮停止动画、断点、无渐变 / 遮罩、卸载 |
|
| NativeMetricDrawingChecks(--gui) | 实际曲线 / 堆叠色带、带符号瓦数零线与两端悬浮点、双向速率面积和零轴、方向 / 悬浮 / 断点及累计边界定位、单点无虚构填充、隐藏序列隔离、缺失点接续与真实断点、悬浮缓存、滚动时间域变换、悬浮停止动画、断点、无渐变 / 遮罩、卸载 |
|
||||||
| FanRotorChecks(--gui) | 独立图层多角度 / 多尺寸旋转中心不漂移,原生旋转动画时长、无效 / 零 / 缺失、非活动 / 减弱动态效果及卸载停转 |
|
| FanRotorChecks(--gui) | 独立图层多角度 / 多尺寸旋转中心不漂移,原生旋转动画时长、无效 / 零 / 缺失、非活动 / 减弱动态效果及卸载停转 |
|
||||||
| ReleaseUpdateChecks | 稳定标签的数字版本、同版 ZIP 构建号、自动偏好、取消与并发请求合并、手动重试和恢复 |
|
| ReleaseUpdateChecks | 稳定标签的数字版本、同版 ZIP 构建号、自动偏好、取消与并发请求合并、手动重试和恢复 |
|
||||||
| ResourceCardChecks(--gui) | 生产卡片与曲线真实挂载,190 / 205⅓ / 400pt、浅深色及三语下的整卡背景图区、存储与网络的独立图区及文字换行边界、10pt 三语内存 / 存储详情在固定卡片内的边界、电量柱的固定间距、右缘追加、已满窗口移出、原生图层平移和供电分组、睡眠区间与普通停采的悬浮命中、缺少电量时保留供电状态,以及无电池时的功率曲线、卸载;比较 AppKit 实际尺寸,允许分数点窗口尺寸取整 |
|
| ResourceCardChecks(--gui) | 生产卡片与曲线真实挂载,190 / 205⅓ / 400pt、浅深色及三语下的整卡背景图区、存储与网络的独立图区及文字换行边界、10pt 三语内存 / 存储详情在固定卡片内的边界、电量柱的固定间距、右缘追加、已满窗口移出、原生图层平移和供电分组、共同供电柱的蓝绿分色、睡眠区间与普通停采的悬浮命中、缺少电量时保留供电状态,以及无电池时的功率曲线、卸载;比较 AppKit 实际尺寸,允许分数点窗口尺寸取整 |
|
||||||
| ProcessSectionChecks(--gui) | 生产进程区域固定 176pt,三语 / 浅深色及 340 / 628pt 下移除说明行后表格占满剩余高度且无横向滚动条 |
|
| ProcessSectionChecks(--gui) | 生产进程区域固定 176pt,三语 / 浅深色及 340 / 628pt 下移除说明行后表格占满剩余高度且无横向滚动条 |
|
||||||
| NativeContentHostChecks(--gui) | 小数末位增减后直接显示最终读数、更新帧与稳定帧像素一致、父环境继承、挂载身份、有限尺寸和卸载 |
|
| NativeContentHostChecks(--gui) | 小数末位增减后直接显示最终读数、更新帧与稳定帧像素一致、父环境继承、挂载身份、有限尺寸和卸载 |
|
||||||
| NativeProcessTableChecks(--gui) | 原生虚拟表格、原地更新、身份选择、六列窄宽度适配、隐藏路径列但真实菜单复制路径、排序 / 列序 / 复制 / 三语列头、合成 Esc 投递 |
|
| NativeProcessTableChecks(--gui) | 原生虚拟表格、原地更新、身份选择、六列窄宽度适配、隐藏路径列但真实菜单复制路径、排序 / 列序 / 复制 / 三语列头、合成 Esc 投递 |
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
## 曲线与悬浮
|
## 曲线与悬浮
|
||||||
|
|
||||||
- 不显示常驻图例、数值坐标轴、网格、起止时间与独立图框。背景曲线线宽 1.4,填充为同色静态实色透明度:浅色 12%、深色 16%;不使用渐变层或遮罩层,连续追加时仅移动已有曲线图层。
|
- 不显示常驻图例、数值坐标轴、网格、起止时间与独立图框。背景曲线线宽 1.4,填充为同色静态实色透明度:浅色 12%、深色 16%;不使用渐变层或遮罩层,连续追加时仅移动已有曲线图层。
|
||||||
- CPU 自下而上堆叠系统态 / 用户态;内存堆叠应用 / 联动 / 压缩,顶边为物理总量、空余为可用空间;GPU 总利用率、Renderer、Tiler 共用百分比轴但各自绘制,只有总利用率填充面积。每根电池柱都是独立的圆角进度条,实色从底部向上表示电量,余量使用同色半透明轨道,柱间留空。绿柱和电池图标表示电池供电或放电,蓝柱配插头、闪电或加号分别表示外接供电、充电或共同供电。未知来源为灰色。电量柱保持固定间距,最新值从右缘进入。睡眠区间使用等距橙黄色柱和月亮,柱高沿用入睡前一笔电量,缺少该读数时用短柱标记,普通停采留白。窄段省略图标,悬浮可读出对应状态。存储和网络采用上下双向曲线:自顶向下 60% 为零轴(细线),向上读取 / 上传、向下写入 / 下载,两侧各有绘图区高度 30% 的振幅,共用自动速率尺度,峰值不触及卡片顶边。
|
- CPU 自下而上堆叠系统态 / 用户态;内存堆叠应用 / 联动 / 压缩,顶边为物理总量、空余为可用空间;GPU 总利用率、Renderer、Tiler 共用百分比轴但各自绘制,只有总利用率填充面积。每根电池柱都是独立的圆角进度条,实色从底部向上表示电量,余量使用同色半透明轨道,柱间留空。绿柱和电池图标表示电池供电或放电,蓝柱配插头或闪电分别表示外接供电或充电。共同供电时显示蓝色插头与绿色电池,两路瓦数分别列出,实色柱段按适配器和电池的供电占比分色。未知来源为灰色。电量柱保持固定间距,最新值从右缘进入。睡眠区间使用等距橙黄色柱和月亮,柱高沿用入睡前一笔电量,缺少该读数时用短柱标记,普通停采留白。窄段省略图标,悬浮可读出对应状态。存储和网络采用上下双向曲线:自顶向下 60% 为零轴(细线),向上读取 / 上传、向下写入 / 下载,两侧各有绘图区高度 30% 的振幅,共用自动速率尺度,峰值不触及卡片顶边。
|
||||||
- 百分比固定 0–100%;内存固定当前物理总量;速率保留既有自动范围及延迟缩小策略,不为视觉任意改变振幅。
|
- 百分比固定 0–100%;内存固定当前物理总量;速率保留既有自动范围及延迟缩小策略,不为视觉任意改变振幅。
|
||||||
- 时间使用真实采样日期;有效 0 保留,nil / 非有限数值不补值。沿用既有缺失节点接续与显式断点 / 长空档策略。堆叠缺少任一必要分量时不构造部分总量;面积在匹配上下边界之间按每个连续段分别闭合,不能填过暂停空档。
|
- 时间使用真实采样日期;有效 0 保留,nil / 非有限数值不补值。沿用既有缺失节点接续与显式断点 / 长空档策略。堆叠缺少任一必要分量时不构造部分总量;面积在匹配上下边界之间按每个连续段分别闭合,不能填过暂停空档。
|
||||||
- 单点历史仅显示真实点,不绘制虚构面积。全缺失无曲线和填充。
|
- 单点历史仅显示真实点,不绘制虚构面积。全缺失无曲线和填充。
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
| CPU | 总占用、温度 / 高温状态、左对齐用户 / 系统;核型横向分组、每核独立单元,数值通过悬浮和辅助功能提供;禁止把核数画成亮灯计数 |
|
| CPU | 总占用、温度 / 高温状态、左对齐用户 / 系统;核型横向分组、每核独立单元,数值通过悬浮和辅助功能提供;禁止把核数画成亮灯计数 |
|
||||||
| GPU | 总占用、温度,GPU 标题后紧跟实际核心数胶囊,带曲线色标的渲染器 / 分块器读数、旋转风扇图标与转速或等待状态 |
|
| GPU | 总占用、温度,GPU 标题后紧跟实际核心数胶囊,带曲线色标的渲染器 / 分块器读数、旋转风扇图标与转速或等待状态 |
|
||||||
| 内存 | 已用 / 总量 GiB、压力标签;应用 / 联动 / 压缩单行及可用量,移除重复容量条;占用率、缓存和 Swap 保留在压力提示中 |
|
| 内存 | 已用 / 总量 GiB、压力标签;应用 / 联动 / 压缩单行及可用量,移除重复容量条;占用率、缓存和 Swap 保留在压力提示中 |
|
||||||
| 电池 | 主读数为电量百分比,详情为带符号的电池瓦数,电源状态在标题右侧;悬浮查看该时刻的适配器输入、报告能力、电池及负载,差值标 ≈;保留健康 / 循环与估时;确认无内置电池时切换为整机即时 W 与独立趋势;传感器缺失显示不可用,电池读取失败不触发切换 |
|
| 电池 | 主读数为电量百分比,详情用绿色电池图标标识带符号的电池瓦数,共同供电时以蓝色插头和绿色电池分别标识两路输出,电源状态在标题右侧;悬浮查看该时刻的适配器输入、报告能力、电池及负载,差值标 ≈;保留健康 / 循环与估时;确认无内置电池时切换为整机即时 W 与独立趋势;传感器缺失显示不可用,电池读取失败不触发切换 |
|
||||||
| 存储 | 已用 / 总量 GB;本地卷入口在标题右侧;可用、读写、寿命 / 通电依次左对齐;保留卷弹出层与口径说明 |
|
| 存储 | 已用 / 总量 GB;本地卷入口在标题右侧;可用、读写、寿命 / 通电依次左对齐;保留卷弹出层与口径说明 |
|
||||||
| 网络 | 黑白主数值与着色方向箭头;单行累计收发;标题右侧接口与路径状态;两行公网 / 本地 IP 及全文提示 / 选择 / 复制 |
|
| 网络 | 黑白主数值与着色方向箭头;单行累计收发;标题右侧接口与路径状态;两行公网 / 本地 IP 及全文提示 / 选择 / 复制 |
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,44 @@ nonisolated struct BatteryPowerFlow: Sendable {
|
|||||||
var load: PowerReading?
|
var load: PowerReading?
|
||||||
var adapterCapacity: Double?
|
var adapterCapacity: Double?
|
||||||
|
|
||||||
|
struct JointSupply: Sendable {
|
||||||
|
let adapter: PowerReading
|
||||||
|
let discharge: PowerReading
|
||||||
|
var batteryFraction: Double { discharge.watts / (adapter.watts + discharge.watts) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Classification floor in watts, separate from the resolution of the displayed readings.
|
||||||
|
private static let minimumContribution = 0.5
|
||||||
|
private(set) var registryJointSupply: JointSupply?
|
||||||
|
|
||||||
|
var jointSupply: JointSupply? {
|
||||||
|
guard connected == true, let battery,
|
||||||
|
battery.watts <= -Self.minimumContribution else { return nil }
|
||||||
|
if battery.source == .smc { return registryJointSupply }
|
||||||
|
guard let input, input.watts >= Self.minimumContribution else { return nil }
|
||||||
|
// IOPS reports a single primary source. Override its battery-only indication
|
||||||
|
// only if all three direct telemetry channels independently support the split.
|
||||||
|
if externalSupply == false &&
|
||||||
|
(input.source != .telemetry || battery.source != .telemetry || load?.source != .telemetry) { return nil }
|
||||||
|
let discharge: PowerReading
|
||||||
|
if battery.source == .telemetry || battery.source == .balance {
|
||||||
|
discharge = PowerReading(watts: -battery.watts, source: battery.source)
|
||||||
|
} else if let load, load.source == .telemetry, input.source == .telemetry {
|
||||||
|
discharge = PowerReading(watts: load.watts - input.watts, source: .balance)
|
||||||
|
} else { return nil }
|
||||||
|
guard discharge.watts >= Self.minimumContribution else { return nil }
|
||||||
|
if let load, load.source == .telemetry, input.source == .telemetry {
|
||||||
|
// Reject conflicting measured channels rather than normalize an unexplained excess.
|
||||||
|
let residual = abs(input.watts + discharge.watts - load.watts)
|
||||||
|
guard residual <= max(1, 0.1 * load.watts) else { return nil }
|
||||||
|
}
|
||||||
|
return JointSupply(adapter: input, discharge: discharge)
|
||||||
|
}
|
||||||
|
|
||||||
mutating func applyBatterySensor(_ watts: Double) {
|
mutating func applyBatterySensor(_ watts: Double) {
|
||||||
// The gauge may still report the last charging sample just after unplugging.
|
// The gauge may still report the last charging sample just after unplugging.
|
||||||
guard watts <= 0 || (externalSupply != false && connected != false) else { return }
|
guard watts <= 0 || (externalSupply != false && connected != false) else { return }
|
||||||
|
if battery?.source != .smc { registryJointSupply = jointSupply }
|
||||||
battery = PowerReading(watts: watts, source: .smc)
|
battery = PowerReading(watts: watts, source: .smc)
|
||||||
// Estimates made from older registry measurements no longer share a sampling window.
|
// Estimates made from older registry measurements no longer share a sampling window.
|
||||||
if load?.source == .balance { load = nil }
|
if load?.source == .balance { load = nil }
|
||||||
@@ -37,8 +72,12 @@ nonisolated struct BatteryPowerFlow: Sendable {
|
|||||||
let threshold = battery.source == .balance ? 0.5 : 0.05
|
let threshold = battery.source == .balance ? 0.5 : 0.05
|
||||||
if battery.watts >= threshold { return .charging }
|
if battery.watts >= threshold { return .charging }
|
||||||
if battery.watts <= -threshold {
|
if battery.watts <= -threshold {
|
||||||
if connected == true, let input, input.source != .balance, input.watts >= 0.05 { return .combined }
|
if jointSupply != nil { return .combined }
|
||||||
if connected == false || externalSupply == false || input?.watts == 0 { return .battery }
|
if connected == false || externalSupply == false { return .battery }
|
||||||
|
if let input, input.source != .balance {
|
||||||
|
if input.watts < Self.minimumContribution { return .battery }
|
||||||
|
if battery.watts > -Self.minimumContribution { return .external }
|
||||||
|
}
|
||||||
return .discharging
|
return .discharging
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,15 @@ import IOKit.ps
|
|||||||
nonisolated struct BatteryMetrics: Sendable {
|
nonisolated struct BatteryMetrics: Sendable {
|
||||||
let charge: Double?
|
let charge: Double?
|
||||||
var flow = BatteryPowerFlow()
|
var flow = BatteryPowerFlow()
|
||||||
var minutesRemaining: Int?
|
var minutesToFull: Int?
|
||||||
|
var minutesToEmpty: Int?
|
||||||
|
var minutesRemaining: Int? {
|
||||||
|
switch flow.state {
|
||||||
|
case .charging: minutesToFull
|
||||||
|
case .battery, .discharging, .combined: minutesToEmpty
|
||||||
|
case .external, .unknown: nil
|
||||||
|
}
|
||||||
|
}
|
||||||
var cycles: Int?
|
var cycles: Int?
|
||||||
var health: Double?
|
var health: Double?
|
||||||
}
|
}
|
||||||
@@ -19,7 +27,11 @@ nonisolated struct BatteryMonitor {
|
|||||||
mutating func accepts(_ next: [NSNumber?], at now: Date, invalidate: Bool) -> Bool {
|
mutating func accepts(_ next: [NSNumber?], at now: Date, invalidate: Bool) -> Bool {
|
||||||
if next != stamp { updated = now; stamp = next }
|
if next != stamp { updated = now; stamp = next }
|
||||||
else if invalidate { updated = .distantPast }
|
else if invalidate { updated = .distantPast }
|
||||||
return (0...120).contains(now.timeIntervalSince(updated))
|
return isFresh(at: now)
|
||||||
|
}
|
||||||
|
|
||||||
|
func isFresh(at now: Date) -> Bool {
|
||||||
|
(0...120).contains(now.timeIntervalSince(updated))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +54,7 @@ nonisolated struct BatteryMonitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func positiveMinutes(_ value: Int?) -> Int? {
|
static func positiveMinutes(_ value: Int?) -> Int? {
|
||||||
value.flatMap { $0 > 0 ? $0 : nil }
|
value.flatMap { (1..<65535).contains($0) ? $0 : nil }
|
||||||
}
|
}
|
||||||
|
|
||||||
static func estimatedMinutes(charging: Bool, externalPower: Bool, sourceMinutes: Int?, systemSeconds: Double) -> Int? {
|
static func estimatedMinutes(charging: Bool, externalPower: Bool, sourceMinutes: Int?, systemSeconds: Double) -> Int? {
|
||||||
@@ -77,14 +89,15 @@ nonisolated struct BatteryMonitor {
|
|||||||
let state = item[kIOPSPowerSourceStateKey] as? String
|
let state = item[kIOPSPowerSourceStateKey] as? String
|
||||||
let supply: Bool? = state == kIOPSACPowerValue ? true : state == kIOPSBatteryPowerValue ? false : nil
|
let supply: Bool? = state == kIOPSACPowerValue ? true : state == kIOPSBatteryPowerValue ? false : nil
|
||||||
let charging = item[kIOPSIsChargingKey] as? Bool
|
let charging = item[kIOPSIsChargingKey] as? Bool
|
||||||
let minutes = charging == true ? item[kIOPSTimeToFullChargeKey] as? Int : item[kIOPSTimeToEmptyKey] as? Int
|
let flow = powerFlow(properties, externalSupply: supply, charging: charging)
|
||||||
var estimate: Int?
|
let systemMinutes = Self.estimatedMinutes(charging: false, externalPower: supply != false,
|
||||||
if let supply, let charging {
|
sourceMinutes: item[kIOPSTimeToEmptyKey] as? Int, systemSeconds: IOPSGetTimeRemainingEstimate())
|
||||||
estimate = Self.estimatedMinutes(charging: charging, externalPower: supply, sourceMinutes: minutes,
|
let now = Date()
|
||||||
systemSeconds: IOPSGetTimeRemainingEstimate())
|
let recentPack = Self.packIsRecent(properties, at: now)
|
||||||
}
|
let packMinutes = recentPack && packStamp.isFresh(at: now) ? Self.positiveMinutes(properties["AvgTimeToEmpty"] as? Int) : nil
|
||||||
return BatteryMetrics(charge: charge, flow: powerFlow(properties, externalSupply: supply, charging: charging),
|
return BatteryMetrics(charge: charge, flow: flow,
|
||||||
minutesRemaining: estimate,
|
minutesToFull: charging == true ? Self.positiveMinutes(item[kIOPSTimeToFullChargeKey] as? Int) : nil,
|
||||||
|
minutesToEmpty: systemMinutes ?? packMinutes,
|
||||||
cycles: (properties["CycleCount"] as? Int).flatMap { $0 >= 0 ? $0 : nil })
|
cycles: (properties["CycleCount"] as? Int).flatMap { $0 >= 0 ? $0 : nil })
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -106,6 +119,10 @@ nonisolated struct BatteryMonitor {
|
|||||||
return input?.source == .telemetry ? input?.watts : nil
|
return input?.source == .telemetry ? input?.watts : nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static func packIsRecent(_ properties: [String: Any], at now: Date) -> Bool {
|
||||||
|
scalar(properties["UpdateTime"]).map { (0...120).contains(now.timeIntervalSince1970 - $0) } ?? true
|
||||||
|
}
|
||||||
|
|
||||||
private static func scalar(_ raw: Any?) -> Double? {
|
private static func scalar(_ raw: Any?) -> Double? {
|
||||||
guard let number = raw as? NSNumber, CFGetTypeID(number) != CFBooleanGetTypeID(),
|
guard let number = raw as? NSNumber, CFGetTypeID(number) != CFBooleanGetTypeID(),
|
||||||
number.doubleValue.isFinite else { return nil }
|
number.doubleValue.isFinite else { return nil }
|
||||||
@@ -141,8 +158,7 @@ nonisolated struct BatteryMonitor {
|
|||||||
|
|
||||||
// IORegistry can observe physical disconnection before IOPowerSources catches up.
|
// IORegistry can observe physical disconnection before IOPowerSources catches up.
|
||||||
if connected == false { flow.externalSupply = false; flow.charging = false }
|
if connected == false { flow.externalSupply = false; flow.charging = false }
|
||||||
let packDate = Self.scalar(properties["UpdateTime"])
|
let recent = Self.packIsRecent(properties, at: now)
|
||||||
let recent = packDate.map { (0...120).contains(now.timeIntervalSince1970 - $0) } ?? true
|
|
||||||
let voltage = properties["Voltage"] ?? pack["Voltage"] ?? pack["AppleRawBatteryVoltage"]
|
let voltage = properties["Voltage"] ?? pack["Voltage"] ?? pack["AppleRawBatteryVoltage"]
|
||||||
let instant = properties["InstantAmperage"] ?? pack["InstantAmperage"]
|
let instant = properties["InstantAmperage"] ?? pack["InstantAmperage"]
|
||||||
let average = properties["Amperage"] ?? pack["Amperage"]
|
let average = properties["Amperage"] ?? pack["Amperage"]
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ struct BatteryHistoryLayout {
|
|||||||
let range: ClosedRange<CGFloat>
|
let range: ClosedRange<CGFloat>
|
||||||
let charge: Double?
|
let charge: Double?
|
||||||
let joinsPrevious: Bool
|
let joinsPrevious: Bool
|
||||||
|
let batteryFraction: Double?
|
||||||
let state: BatteryPowerFlow.State
|
let state: BatteryPowerFlow.State
|
||||||
}
|
}
|
||||||
struct SleepBand {
|
struct SleepBand {
|
||||||
@@ -50,7 +51,8 @@ struct BatteryHistoryLayout {
|
|||||||
let charge = sample.battery.flatMap { (0...1).contains($0) ? $0 : nil }
|
let charge = sample.battery.flatMap { (0...1).contains($0) ? $0 : nil }
|
||||||
if charge != nil || sample.powerFlow != nil {
|
if charge != nil || sample.powerFlow != nil {
|
||||||
bars.append(Bar(index: i, x: (left + right) / 2, range: left...right,
|
bars.append(Bar(index: i, x: (left + right) / 2, range: left...right,
|
||||||
charge: charge, joinsPrevious: continuous, state: sample.powerFlow?.state ?? .unknown))
|
charge: charge, joinsPrevious: continuous, batteryFraction: sample.powerFlow?.jointSupply?.batteryFraction,
|
||||||
|
state: sample.powerFlow?.state ?? .unknown))
|
||||||
}
|
}
|
||||||
guard let previous, elapsed > 0, left > -pitch else { break }
|
guard let previous, elapsed > 0, left > -pitch else { break }
|
||||||
right = left
|
right = left
|
||||||
@@ -134,8 +136,7 @@ private extension BatteryPowerFlow.State {
|
|||||||
switch self {
|
switch self {
|
||||||
case .battery, .discharging: (NSColor(named: "MetricBattery") ?? .systemGreen, "battery.50percent")
|
case .battery, .discharging: (NSColor(named: "MetricBattery") ?? .systemGreen, "battery.50percent")
|
||||||
case .charging: (NSColor(named: "BatteryExternal") ?? .systemBlue, "bolt.fill")
|
case .charging: (NSColor(named: "BatteryExternal") ?? .systemBlue, "bolt.fill")
|
||||||
case .external: (NSColor(named: "BatteryExternal") ?? .systemBlue, "powerplug.fill")
|
case .external, .combined: (NSColor(named: "BatteryExternal") ?? .systemBlue, "powerplug.fill")
|
||||||
case .combined: (NSColor(named: "BatteryExternal") ?? .systemBlue, "plus.circle.fill")
|
|
||||||
case .unknown: (.secondaryLabelColor, "questionmark")
|
case .unknown: (.secondaryLabelColor, "questionmark")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,10 +213,20 @@ final class BatteryHistoryPlot: NSView {
|
|||||||
}
|
}
|
||||||
let range = bar.range.lowerBound...bars[end].range.upperBound
|
let range = bar.range.lowerBound...bars[end].range.upperBound
|
||||||
let style = bar.state.style
|
let style = bar.state.style
|
||||||
drawSymbol(style.symbol, color: style.color, in: range)
|
if bar.state == .combined {
|
||||||
|
let left = max(range.lowerBound, 0), right = min(range.upperBound, layoutData.width)
|
||||||
|
if right - left >= 12 {
|
||||||
|
let mid = (left + right) / 2
|
||||||
|
drawSymbol(style.symbol, color: style.color, in: left...mid, minimumWidth: 6)
|
||||||
|
drawSymbol("battery.50percent", color: NSColor(named: "MetricBattery") ?? .systemGreen,
|
||||||
|
in: mid...right, minimumWidth: 6)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
drawSymbol(style.symbol, color: style.color, in: range)
|
||||||
|
}
|
||||||
for item in bars[start...end] {
|
for item in bars[start...end] {
|
||||||
column(at: item.x, width: columnWidth, height: item.charge.map { $0 * baseline },
|
column(at: item.x, width: columnWidth, height: item.charge.map { $0 * baseline },
|
||||||
baseline: baseline, color: style.color)
|
baseline: baseline, color: style.color, batteryFraction: item.batteryFraction)
|
||||||
}
|
}
|
||||||
start = end + 1
|
start = end + 1
|
||||||
}
|
}
|
||||||
@@ -238,7 +249,7 @@ final class BatteryHistoryPlot: NSView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func column(at x: CGFloat, width: CGFloat, height: CGFloat?, baseline: CGFloat, color: NSColor) {
|
private func column(at x: CGFloat, width: CGFloat, height: CGFloat?, baseline: CGFloat, color: NSColor, batteryFraction: Double? = nil) {
|
||||||
let track = CGRect(x: x - width / 2, y: 0, width: width, height: baseline)
|
let track = CGRect(x: x - width / 2, y: 0, width: width, height: baseline)
|
||||||
let radius = min(width, baseline) / 2
|
let radius = min(width, baseline) / 2
|
||||||
if (height ?? 0) < baseline {
|
if (height ?? 0) < baseline {
|
||||||
@@ -249,15 +260,24 @@ final class BatteryHistoryPlot: NSView {
|
|||||||
let fill = CGRect(x: track.minX, y: baseline - height, width: width, height: height)
|
let fill = CGRect(x: track.minX, y: baseline - height, width: width, height: height)
|
||||||
let fillRadius = min(radius, height / 2)
|
let fillRadius = min(radius, height / 2)
|
||||||
color.setFill()
|
color.setFill()
|
||||||
NSBezierPath(roundedRect: fill, xRadius: fillRadius, yRadius: fillRadius).fill()
|
let path = NSBezierPath(roundedRect: fill, xRadius: fillRadius, yRadius: fillRadius)
|
||||||
|
path.fill()
|
||||||
|
if let batteryFraction {
|
||||||
|
NSGraphicsContext.saveGraphicsState()
|
||||||
|
path.addClip()
|
||||||
|
(NSColor(named: "MetricBattery") ?? .systemGreen).setFill()
|
||||||
|
let greenHeight = height * batteryFraction
|
||||||
|
NSBezierPath(rect: CGRect(x: fill.minX, y: baseline - greenHeight, width: width, height: greenHeight)).fill()
|
||||||
|
NSGraphicsContext.restoreGraphicsState()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func drawSymbol(_ symbol: String, color: NSColor, in range: ClosedRange<CGFloat>) {
|
private func drawSymbol(_ symbol: String, color: NSColor, in range: ClosedRange<CGFloat>, minimumWidth: CGFloat = 13) {
|
||||||
let visibleLeft = max(0, range.lowerBound)
|
let visibleLeft = max(0, range.lowerBound)
|
||||||
let visibleWidth = min(layoutData.width, range.upperBound) - visibleLeft
|
let visibleWidth = min(layoutData.width, range.upperBound) - visibleLeft
|
||||||
guard visibleWidth >= 13, let image = NSImage(systemSymbolName: symbol, accessibilityDescription: nil)?
|
guard visibleWidth >= minimumWidth, let image = NSImage(systemSymbolName: symbol, accessibilityDescription: nil)?
|
||||||
.withSymbolConfiguration(.init(paletteColors: [color])) else { return }
|
.withSymbolConfiguration(.init(paletteColors: [color])) else { return }
|
||||||
let scale = min(11 / image.size.width, 9 / image.size.height)
|
let scale = min(min(11, visibleWidth) / image.size.width, 9 / image.size.height)
|
||||||
let size = CGSize(width: image.size.width * scale, height: image.size.height * scale)
|
let size = CGSize(width: image.size.width * scale, height: image.size.height * scale)
|
||||||
let icon = CGRect(x: visibleLeft + (visibleWidth - size.width) / 2,
|
let icon = CGRect(x: visibleLeft + (visibleWidth - size.width) / 2,
|
||||||
y: bounds.maxY - 5.5 - size.height / 2, width: size.width, height: size.height)
|
y: bounds.maxY - 5.5 - size.height / 2, width: size.width, height: size.height)
|
||||||
|
|||||||
@@ -27,17 +27,18 @@ struct PowerResourceCard: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func details(_ flow: BatteryPowerFlow) -> String {
|
private func details(_ flow: BatteryPowerFlow) -> String {
|
||||||
var rows: [(String, String)] = [
|
var rows: [(String, String)]
|
||||||
("battery.power", formatted(flow.battery, signed: true)),
|
if let joint = flow.jointSupply {
|
||||||
("power.load", formatted(flow.load))
|
let load = flow.load ?? PowerReading(watts: joint.adapter.watts + joint.discharge.watts, source: .balance)
|
||||||
]
|
rows = [("power.adapterContribution", formatted(joint.adapter)),
|
||||||
if flow.connected != false {
|
("power.batteryContribution", formatted(joint.discharge)),
|
||||||
rows.append(("power.input", formatted(flow.input)))
|
("power.load", formatted(load))]
|
||||||
rows.append(("power.capacity", MetricFormat.watts(flow.adapterCapacity)))
|
} else {
|
||||||
}
|
let batteryLabel = flow.battery?.source == .average ? "power.averageBattery" : "battery.power"
|
||||||
if flow.battery?.source == .average {
|
rows = [(batteryLabel, formatted(flow.battery, signed: true)), ("power.load", formatted(flow.load))]
|
||||||
rows[0].0 = "power.averageBattery"
|
if flow.connected != false { rows.append(("power.input", formatted(flow.input))) }
|
||||||
}
|
}
|
||||||
|
if flow.connected != false { rows.append(("power.capacity", MetricFormat.watts(flow.adapterCapacity))) }
|
||||||
return rows.map { AppLocalization.string($0.0, locale: locale) + " " + $0.1 }.joined(separator: "\n")
|
return rows.map { AppLocalization.string($0.0, locale: locale) + " " + $0.1 }.joined(separator: "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,9 +67,12 @@ struct PowerResourceCard: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var batteryPowerCard: some View {
|
private var batteryPowerCard: some View {
|
||||||
ResourceCard(
|
let joint = snapshot.battery?.flow.jointSupply
|
||||||
title: "metric.battery", symbol: "battery.100percent", color: Color("MetricBattery"),
|
return ResourceCard(
|
||||||
|
title: "metric.battery", symbol: joint == nil ? "battery.100percent" : "powerplug.fill",
|
||||||
|
color: Color(joint == nil ? "MetricBattery" : "BatteryExternal"),
|
||||||
value: MetricFormat.percent(snapshot.battery?.charge),
|
value: MetricFormat.percent(snapshot.battery?.charge),
|
||||||
|
companionIcon: joint == nil ? nil : ("battery.50percent", Color("MetricBattery")),
|
||||||
status: snapshot.battery.map { label($0.flow.state) },
|
status: snapshot.battery.map { label($0.flow.state) },
|
||||||
warningText: snapshot.battery.map { Text(verbatim: details($0.flow)) },
|
warningText: snapshot.battery.map { Text(verbatim: details($0.flow)) },
|
||||||
chart: {
|
chart: {
|
||||||
@@ -81,8 +85,17 @@ struct PowerResourceCard: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
InlineMetric("battery.powerShort", formatted(snapshot.battery?.flow.battery, signed: true))
|
if let joint {
|
||||||
|
HStack(spacing: 8) {
|
||||||
|
powerLabel(joint.adapter, symbol: "powerplug.fill", color: "BatteryExternal", title: "power.adapterContribution")
|
||||||
|
powerLabel(joint.discharge, symbol: "battery.50percent", color: "MetricBattery", title: "power.batteryContribution")
|
||||||
|
}
|
||||||
.frame(height: 16)
|
.frame(height: 16)
|
||||||
|
} else {
|
||||||
|
powerLabel(snapshot.battery?.flow.battery, signed: true, symbol: "battery.50percent",
|
||||||
|
color: "MetricBattery", title: "battery.power")
|
||||||
|
.frame(height: 16)
|
||||||
|
}
|
||||||
if let battery = snapshot.battery {
|
if let battery = snapshot.battery {
|
||||||
batteryDetails(battery)
|
batteryDetails(battery)
|
||||||
} else {
|
} else {
|
||||||
@@ -91,20 +104,33 @@ struct PowerResourceCard: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private func powerLabel(_ reading: PowerReading?, signed: Bool = false, symbol: String,
|
||||||
|
color: String, title: LocalizedStringKey) -> some View {
|
||||||
|
let value = formatted(reading, signed: signed)
|
||||||
|
return Label {
|
||||||
|
Text(verbatim: value).monospacedDigit()
|
||||||
|
} icon: {
|
||||||
|
Image(systemName: symbol).foregroundStyle(Color(color))
|
||||||
|
}
|
||||||
|
.accessibilityLabel(Text(title)).accessibilityValue(Text(verbatim: value))
|
||||||
|
.help(Text(title))
|
||||||
|
}
|
||||||
|
|
||||||
private func batteryDetails(_ battery: BatteryMetrics) -> some View {
|
private func batteryDetails(_ battery: BatteryMetrics) -> some View {
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
HStack(spacing: 8) {
|
HStack(spacing: 8) {
|
||||||
InlineMetric("battery.healthShort", MetricFormat.percent(battery.health))
|
InlineMetric("battery.healthShort", MetricFormat.percent(battery.health))
|
||||||
InlineMetric("battery.cyclesShort", battery.cycles.map(String.init) ?? "--")
|
InlineMetric("battery.cyclesShort", battery.cycles.map(String.init) ?? "--")
|
||||||
}
|
}
|
||||||
HStack(spacing: 4) {
|
if battery.flow.state != .external {
|
||||||
Text(battery.flow.charging == true ? "battery.timeToFull" : "battery.timeShort").foregroundStyle(.secondary)
|
HStack(spacing: 4) {
|
||||||
if let minutes = battery.minutesRemaining {
|
Text(battery.flow.state == .charging ? "battery.timeToFull" : "battery.timeEstimate")
|
||||||
Text("duration.minutes \(minutes)").monospacedDigit()
|
.foregroundStyle(.secondary)
|
||||||
} else if battery.flow.state == .external && battery.flow.charging != true {
|
if let minutes = battery.minutesRemaining {
|
||||||
Text("battery.notApplicableShort").help(Text("battery.timeNotApplicable"))
|
Text("duration.minutes \(minutes)").monospacedDigit()
|
||||||
} else {
|
} else {
|
||||||
Text("battery.timeUnknown")
|
Text("battery.timeUnknown")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,50 @@
|
|||||||
{
|
{
|
||||||
"sourceLanguage" : "en",
|
"sourceLanguage" : "en",
|
||||||
"strings" : {
|
"strings" : {
|
||||||
|
"power.adapterContribution": {
|
||||||
|
"localizations": {
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Adapter supply"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hans": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "适配器供电"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hant": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "轉接器供電"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"power.batteryContribution": {
|
||||||
|
"localizations": {
|
||||||
|
"en": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "Battery supply"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hans": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "电池供电"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hant": {
|
||||||
|
"stringUnit": {
|
||||||
|
"state": "translated",
|
||||||
|
"value": "電池供電"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"action.about": {
|
"action.about": {
|
||||||
"extractionState": "manual",
|
"extractionState": "manual",
|
||||||
"localizations": {
|
"localizations": {
|
||||||
@@ -648,28 +692,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"battery.timeShort" : {
|
|
||||||
"localizations": {
|
|
||||||
"en": {
|
|
||||||
"stringUnit": {
|
|
||||||
"state": "translated",
|
|
||||||
"value": "Time left"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hans": {
|
|
||||||
"stringUnit": {
|
|
||||||
"state": "translated",
|
|
||||||
"value": "剩余时间"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant": {
|
|
||||||
"stringUnit": {
|
|
||||||
"state": "translated",
|
|
||||||
"value": "剩餘時間"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"battery.timeToFull" : {
|
"battery.timeToFull" : {
|
||||||
"localizations": {
|
"localizations": {
|
||||||
"en": {
|
"en": {
|
||||||
@@ -692,28 +714,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"battery.powerShort" : {
|
|
||||||
"localizations": {
|
|
||||||
"en": {
|
|
||||||
"stringUnit": {
|
|
||||||
"state": "translated",
|
|
||||||
"value": "Power"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hans": {
|
|
||||||
"stringUnit": {
|
|
||||||
"state": "translated",
|
|
||||||
"value": "功率"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant": {
|
|
||||||
"stringUnit": {
|
|
||||||
"state": "translated",
|
|
||||||
"value": "功率"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"memory.appShort" : {
|
"memory.appShort" : {
|
||||||
"localizations": {
|
"localizations": {
|
||||||
"en": {
|
"en": {
|
||||||
@@ -824,28 +824,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"battery.notApplicableShort" : {
|
|
||||||
"localizations" : {
|
|
||||||
"en" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "N/A"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hans" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "不适用"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "不適用"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"panel.power" : {
|
"panel.power" : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
"zh-Hans" : {
|
"zh-Hans" : {
|
||||||
@@ -1704,41 +1682,19 @@
|
|||||||
"en" : {
|
"en" : {
|
||||||
"stringUnit" : {
|
"stringUnit" : {
|
||||||
"state" : "translated",
|
"state" : "translated",
|
||||||
"value" : "Battery life estimate"
|
"value" : "Estimated runtime"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"zh-Hans" : {
|
"zh-Hans" : {
|
||||||
"stringUnit" : {
|
"stringUnit" : {
|
||||||
"state" : "translated",
|
"state" : "translated",
|
||||||
"value" : "续航预估"
|
"value" : "预估续航"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"zh-Hant" : {
|
"zh-Hant" : {
|
||||||
"stringUnit" : {
|
"stringUnit" : {
|
||||||
"state" : "translated",
|
"state" : "translated",
|
||||||
"value" : "續航預估"
|
"value" : "預估續航"
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"battery.timeNotApplicable" : {
|
|
||||||
"localizations" : {
|
|
||||||
"en" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "Not applicable on AC"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hans" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "外接电源,不适用"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"zh-Hant" : {
|
|
||||||
"stringUnit" : {
|
|
||||||
"state" : "translated",
|
|
||||||
"value" : "外接電源,不適用"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ struct ResourceCard<Chart: View, Content: View>: View {
|
|||||||
let symbol: String
|
let symbol: String
|
||||||
let color: Color
|
let color: Color
|
||||||
let value: String
|
let value: String
|
||||||
|
var companionIcon: (symbol: String, color: Color)? = nil
|
||||||
var secondaryValue: String? = nil
|
var secondaryValue: String? = nil
|
||||||
var valueColor: Color? = nil
|
var valueColor: Color? = nil
|
||||||
var secondaryValueColor: Color? = nil
|
var secondaryValueColor: Color? = nil
|
||||||
@@ -90,7 +91,12 @@ struct ResourceCard<Chart: View, Content: View>: View {
|
|||||||
Label {
|
Label {
|
||||||
Text(title).foregroundStyle(statusWarning ? .red : .primary)
|
Text(title).foregroundStyle(statusWarning ? .red : .primary)
|
||||||
} icon: {
|
} icon: {
|
||||||
Image(systemName: symbol).foregroundStyle(statusWarning ? .red : color)
|
HStack(spacing: 1) {
|
||||||
|
Image(systemName: symbol).foregroundStyle(statusWarning ? .red : color)
|
||||||
|
if let companionIcon {
|
||||||
|
Image(systemName: companionIcon.symbol).foregroundStyle(companionIcon.color)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.font(.system(size: 11, weight: .semibold)).fixedSize()
|
.font(.system(size: 11, weight: .semibold)).fixedSize()
|
||||||
if let titleBadge {
|
if let titleBadge {
|
||||||
|
|||||||
@@ -17,6 +17,20 @@ import Foundation
|
|||||||
let combined = read(["BatteryPower": NSNumber(value: UInt64(bitPattern: -8000)), "SystemPowerIn": 30_000])
|
let combined = read(["BatteryPower": NSNumber(value: UInt64(bitPattern: -8000)), "SystemPowerIn": 30_000])
|
||||||
precondition(combined.battery?.watts == -8 && combined.state == .combined)
|
precondition(combined.battery?.watts == -8 && combined.state == .combined)
|
||||||
precondition(combined.load == PowerReading(watts: 38, source: .balance))
|
precondition(combined.load == PowerReading(watts: 38, source: .balance))
|
||||||
|
let standby = read(["BatteryPower": -4700, "SystemPowerIn": 100, "SystemLoad": 6300], extra: adapter)
|
||||||
|
precondition(standby.state == .battery && standby.input?.watts == 0.1 && standby.jointSupply == nil)
|
||||||
|
let tinyDischarge = read(["BatteryPower": -100, "SystemPowerIn": 6300, "SystemLoad": 6400])
|
||||||
|
precondition(tinyDischarge.state == .external && tinyDischarge.jointSupply == nil)
|
||||||
|
let contradictory = read(["BatteryPower": -4700, "SystemPowerIn": 6000, "SystemLoad": 6300])
|
||||||
|
precondition(contradictory.state == .discharging && contradictory.jointSupply == nil)
|
||||||
|
var primaryBattery = BatteryMonitor()
|
||||||
|
let withAssist = primaryBattery.powerFlow(["ExternalConnected": true, "PowerTelemetryData":
|
||||||
|
["SystemPowerIn": 12_000, "BatteryPower": -8000, "SystemLoad": 20_000]], externalSupply: false)
|
||||||
|
precondition(withAssist.state == .combined && withAssist.jointSupply?.batteryFraction == 0.4)
|
||||||
|
let estimatedInput = read(["BatteryPower": -8000, "SystemLoad": 38_000])
|
||||||
|
precondition(estimatedInput.jointSupply?.adapter == PowerReading(watts: 30, source: .balance))
|
||||||
|
let estimatedAssist = read(["SystemPowerIn": 30_000, "SystemLoad": 38_000])
|
||||||
|
precondition(estimatedAssist.jointSupply?.discharge == PowerReading(watts: 8, source: .balance))
|
||||||
let staleCharge = read(["BatteryPower": 6_000], extra: ["Voltage": 12_000, "InstantAmperage": 0, "IsCharging": false])
|
let staleCharge = read(["BatteryPower": 6_000], extra: ["Voltage": 12_000, "InstantAmperage": 0, "IsCharging": false])
|
||||||
precondition(staleCharge.battery?.watts == 0 && staleCharge.state == .external)
|
precondition(staleCharge.battery?.watts == 0 && staleCharge.state == .external)
|
||||||
let unknownWatts = read([:], extra: ["IsCharging": true])
|
let unknownWatts = read([:], extra: ["IsCharging": true])
|
||||||
@@ -65,6 +79,18 @@ import Foundation
|
|||||||
var joint = combined
|
var joint = combined
|
||||||
joint.applyBatterySensor(-10)
|
joint.applyBatterySensor(-10)
|
||||||
precondition(joint.battery?.watts == -10 && joint.state == .combined && joint.load == nil)
|
precondition(joint.battery?.watts == -10 && joint.state == .combined && joint.load == nil)
|
||||||
|
precondition(joint.jointSupply?.batteryFraction == 8.0 / 38 && joint.jointSupply?.discharge.watts == 8)
|
||||||
|
joint.applyBatterySensor(2)
|
||||||
|
precondition(joint.state == .charging && joint.jointSupply == nil)
|
||||||
|
var missingPair = read(["SystemPowerIn": 6000])
|
||||||
|
missingPair.applyBatterySensor(-5)
|
||||||
|
precondition(missingPair.state == .discharging && missingPair.jointSupply == nil)
|
||||||
|
var clock = BatteryMetrics(charge: 0.8, flow: combined, minutesToFull: 20, minutesToEmpty: 345)
|
||||||
|
precondition(clock.minutesRemaining == 345)
|
||||||
|
clock.flow = charging
|
||||||
|
precondition(clock.minutesRemaining == 20)
|
||||||
|
clock.flow = idle
|
||||||
|
precondition(clock.minutesRemaining == nil && BatteryMonitor.positiveMinutes(65535) == nil)
|
||||||
print("PASS: signed battery watts, adapter limits, joint supply, measured and derived values, stale telemetry")
|
print("PASS: signed battery watts, adapter limits, joint supply, measured and derived values, stale telemetry")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,10 @@ import SwiftUI
|
|||||||
sample.date = sample.date.addingTimeInterval(2)
|
sample.date = sample.date.addingTimeInterval(2)
|
||||||
sample.battery?.flow = BatteryPowerFlow(connected: true, externalSupply: true, battery: PowerReading(watts: 34.8))
|
sample.battery?.flow = BatteryPowerFlow(connected: true, externalSupply: true, battery: PowerReading(watts: 34.8))
|
||||||
history.append(sample)
|
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,
|
host.rootView = AnyView(PowerResourceCard(snapshot: sample, samples: history.samples, sleepIntervals: history.sleepIntervals,
|
||||||
chartInterval: 2, chartBoundaries: [], chartIntervals: history.samples.map(\.expectedInterval)))
|
chartInterval: 2, chartBoundaries: [], chartIntervals: history.samples.map(\.expectedInterval)))
|
||||||
@@ -81,8 +85,9 @@ import SwiftUI
|
|||||||
let bars = plot.layoutData.bars
|
let bars = plot.layoutData.bars
|
||||||
precondition(plot.bounds.height >= 24 && plot.bounds.maxY < host.bounds.height)
|
precondition(plot.bounds.height >= 24 && plot.bounds.maxY < host.bounds.height)
|
||||||
if state == .present {
|
if state == .present {
|
||||||
precondition(bars.map(\.charge) == [0.77, 0.77, 0.77])
|
precondition(bars.map(\.charge) == [0.77, 0.77, 0.77, 0.77])
|
||||||
precondition(bars.map(\.state) == [.external, .battery, .charging])
|
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)) }
|
for bar in bars { precondition(plot.layoutData.hit(at: bar.x) == .sample(bar.index)) }
|
||||||
} else { precondition(bars.isEmpty) }
|
} else { precondition(bars.isEmpty) }
|
||||||
}
|
}
|
||||||
@@ -161,6 +166,13 @@ import SwiftUI
|
|||||||
snapshot.battery = BatteryMetrics(charge: charge, flow: flow)
|
snapshot.battery = BatteryMetrics(charge: charge, flow: flow)
|
||||||
history.append(snapshot)
|
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 plot = BatteryHistoryPlot(frame: CGRect(x: 0, y: 0, width: 590, height: 51))
|
||||||
let layout = BatteryHistoryLayout(samples: history.samples, sleeps: [], width: plot.bounds.width)
|
let layout = BatteryHistoryLayout(samples: history.samples, sleeps: [], width: plot.bounds.width)
|
||||||
plot.layoutData = layout
|
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, 16)))
|
||||||
precondition((0.1...0.4).contains(alpha(bars[i].x, 34)))
|
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()
|
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((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)
|
precondition(alpha(bars[2].x, 16) > 0.95 && alpha(bars[2].x, 34) > 0.95)
|
||||||
|
|||||||
Reference in New Issue
Block a user