Skip to content

fix: handle empty data array in HeaderViz sparkline - #92

Open
oliviabrn wants to merge 1 commit into
OpenNSWM-Lab:mainfrom
oliviabrn:fix/header-viz-empty-data
Open

fix: handle empty data array in HeaderViz sparkline#92
oliviabrn wants to merge 1 commit into
OpenNSWM-Lab:mainfrom
oliviabrn:fix/header-viz-empty-data

Conversation

@oliviabrn

Copy link
Copy Markdown

Background

The HeaderViz component renders small inline SVGs (sparklines, mini bars, donuts, metric capsules) in page headers. The renderSparkline function computes step = width / (points.length - 1), which produces Infinity when the data array has exactly one element, leading to invalid SVG path coordinates.

Changes

Added an early return guard at the top of renderSparkline:

if (points.length < 2) return null

A sparkline needs at least two points to draw a line segment. The existing defaultData.length === 0 check 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

  • No functional change for arrays with 2+ elements.
  • renderMiniBars with a single value still renders a valid single bar.
  • The component already returns null for empty arrays.

Verified by reviewing the diff and confirming the math: with points.length === 1, step would be 120 / 0 = Infinity, and x = 0 * Infinity = NaN, producing invalid SVG path data.

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