Skip to content

fix: stale temperature points break sparkline instead of silently reusing last value (issue #31)#39

Merged
ShadyUnderLight merged 2 commits intomainfrom
fix/issue31-temperature-stale-display
Apr 21, 2026
Merged

fix: stale temperature points break sparkline instead of silently reusing last value (issue #31)#39
ShadyUnderLight merged 2 commits intomainfrom
fix/issue31-temperature-stale-display

Conversation

@ShadyUnderLight
Copy link
Copy Markdown
Owner

修复内容

根因: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

LMZ 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
@ShadyUnderLight ShadyUnderLight merged commit 07462ac into main Apr 21, 2026
2 checks passed
@ShadyUnderLight ShadyUnderLight deleted the fix/issue31-temperature-stale-display branch April 21, 2026 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant