fix(plot): prevent crashes, hangs, and wrong-series rendering#27
Open
balloob wants to merge 1 commit into
Open
fix(plot): prevent crashes, hangs, and wrong-series rendering#27balloob wants to merge 1 commit into
balloob wants to merge 1 commit into
Conversation
Correctness and robustness fixes for the plot and diagram elements: - A1: pair each entity's segments with its own config so an entity with no valid data no longer shifts the config/segment mapping and renders another series in the wrong color/width/smooth style. - A2: clamp the y-axis tick spacing so the tick/grid/legend loops draw at most _MAX_Y_TICKS ticks. A single bogus sensor reading (huge value spread) could otherwise issue millions of draw calls and freeze the async event loop. - A3: return after the all-zero-bars guard in draw_diagram, avoiding a ZeroDivisionError from the height_factor division that followed. - A5: smooth a 3-point series through its middle point instead of collapsing it to a straight first-to-last line (boundary extension now runs at >= 3 points). - A10: document that plot low/high seed but do not pin the y-axis range. - B6: batch dotted grid lines into a single draw.point() call per line. - B8: precompute the Catmull-Rom basis weights once per smoothing call instead of recomputing them for every interpolated point. Adds regression tests for A1, A2, A3, and A5. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UVpLN4Rzdv7y3ud7QzutVJ
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Summary
Correctness and robustness fixes for the
plotanddiagramelements. These address pathological inputs that can crash the render or block the Home Assistant event loop, plus a couple of wrong-output bugs. Each fix is small and self-contained.Findings addressed
draw_plotskipped entities whose states were all invalid when buildingraw_data, then zippedraw_dataagainst the fullelement["data"]config list. Anunavailablefirst entity would shift the mapping, so a later series rendered with the wrong entity'scolor/width/smooth. Segments are now paired with their own config.min_vtomax_vbytick_every(default1). One bogus sensor reading (a counter, a glitch to2**32) makes the spread millions wide and each loop issues millions of draw calls, freezing the async loop. Tick spacing is now clamped so at most_MAX_Y_TICKS(100) ticks are drawn; reasonable configs are untouched.ZeroDivisionErrorindiagram. The all-bars-zero guard setctx.pos_ybut was missing areturn, so execution fell through toheight_factor = (height - offset_lines) / max_val. Added thereturn.smoothdropped the middle point. The Catmull-Rom boundary extension only ran forlen(points) > 3, so a 3-point series collapsed to a straight first→last line (the peak vanished). Boundary extension now runs at>= 3points.low/highseed but do not pin the y-axis range (data still auto-expands it).draw.point()once per pixel; now batched into a singledraw.point(seq)call per line.Tests
Adds regression tests for A1 (skipped-entity style leakage), A2 (huge spread renders without hanging), A3 (all-zero bars), and A5 (3-point smoothing keeps the middle). Full suite: no new failures (the pre-existing
tests/visual/*byte-snapshot failures under Pillow 12 are unrelated and addressed separately).🤖 Generated with Claude Code