fix: handle empty data array in HeaderViz sparkline - #92
Open
oliviabrn wants to merge 1 commit into
Open
Conversation
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.
Background
The
HeaderVizcomponent renders small inline SVGs (sparklines, mini bars, donuts, metric capsules) in page headers. TherenderSparklinefunction computesstep = width / (points.length - 1), which producesInfinitywhen the data array has exactly one element, leading to invalid SVG path coordinates.Changes
Added an early return guard at the top of
renderSparkline:A sparkline needs at least two points to draw a line segment. The existing
defaultData.length === 0check at line 171 already handles the empty case, but it did not cover single-element arrays. The other render functions (renderMiniBars,renderDonut,renderMetricCapsules) work fine with a single data point, so they do not need this guard.Notes
renderMiniBarswith a single value still renders a valid single bar.nullfor empty arrays.Verified by reviewing the diff and confirming the math: with
points.length === 1,stepwould be120 / 0 = Infinity, andx = 0 * Infinity = NaN, producing invalid SVG path data.