fix: stale temperature points break sparkline instead of silently reusing last value (issue #31)#39
Merged
ShadyUnderLight merged 2 commits intomainfrom Apr 21, 2026
Conversation
added 2 commits
April 21, 2026 16:15
… silently reusing last value (issue #31) - MetricPoint gains isStale: Bool (default false) - appendHistory(): when temp is unavailable, append a stale point (keeps last known value for visual continuity but marks it stale) - SparklineView: stale points break the line — next non-stale point starts a fresh path.move; stale segments render grey + dashed - Value text also dims to grey while latest point is stale - New MetricPointTests covering isStale flag behavior
… normal, stale gaps render as grey ticks (PR #39 review fix) Previous implementation applied a single stroke style to the whole live path based on whether the latest point was stale — meaning a stale latest point would recolour the entire historical live segment grey+dashed. Fix: - buildLivePath: only non-stale points; stale boundaries call path.move - buildStalePath: stale points rendered as individual grey vertical ticks (no connecting line — signals a gap without falsely implying continuity) - Live segments keep threshold-based colour + solid line always - value text dims grey only when latest point is stale - buildLivePath / buildStalePath promoted to fileprivate for test access Also adds SparklineViewTests covering: - latestPointIsStale correctly true/false per last point flag - stale points segregated at data level, not mixed into live values - repeated stale points all flagged correctly - all-stale history → no live points in live path - live continuity broken by stale boundary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复内容
根因:appendHistory() 在温度读取失败时复用上一帧温度值,导致 sparkline 把 unavailable/stale 数据误显示为实时连续曲线。
方案(采用 issue 建议的 Option 1/2 结合):
SystemModels.swift: MetricPoint 新增 isStale: Bool(默认 false)
MonitorViewModel.swift: 温度不可用时追加 stale point(保留上帧值用于视觉连续性,但标记为 stale)
SparklineView.swift: stale 点打断线条;stale 段渲染为灰色 + 虚线;最新值为 stale 时数值文字变灰
MetricPointTests.swift: 新增 4 个 isStale 行为测试
视觉行为变化:
swift build && swift test 通过
待 review / merge