Skip to content

fix(series): non-finite values poison the axis domain and leak NaN into paths - #8

Closed
p32929 wants to merge 2 commits into
corvudev:mainfrom
p32929:fix/non-finite-values
Closed

p32929 wants to merge 2 commits into
corvudev:mainfrom
p32929:fix/non-finite-values

Conversation

@p32929

@p32929 p32929 commented Sep 20, 2026

Copy link
Copy Markdown

Fixes #6.

The bug

Rendering two <Line> series where the second one has holes (the dataKey is missing on some
entries) produces NaN in the generated d attribute — and not only at the hole: every point on
that axis becomes NaN
, so the whole chart disappears and the console fills with SVG errors.

Why

Two separate places let a non-finite value through.

1. lib/createSeries.ts — the axis domain is computed with Math.min/Math.max over the raw series.

const min = Math.min(...data, ...stackValues)
...
max = max ?? Math.max(...data)

accessData() returns undefined for an entry that does not have the key, and
Math.min(1, undefined) is NaN. So the axis registers {min: NaN, max: NaN}, scaleLinear
is built on a NaN domain in createPoints.ts, and every point it maps — including the
points of the other, complete series sharing that axis — comes back NaN. That is the part
that makes it look like the library cannot draw holes at all.

2. lib/utils.ts — pointDefined accepts NaN.

const pointDefined = (point: [number, number]) =>
  typeof point[0] === 'number' && typeof point[1] === 'number'

typeof NaN === 'number', so the gap-splitting logic in shapes/Curve.tsx — which is otherwise
completely correct and already supports connectNulls — never sees the hole, keeps the point in
the current segment, and hands NaN straight to d3's line().

The fix

  • pointDefined checks Number.isFinite instead of typeof, so a missing point actually starts
    a new segment (or is dropped under connectNulls), which is what Curve.tsx already intends.
  • createSeries filters non-finite values out of the values it feeds to Math.min/Math.max, and
    the stacked accumulator skips them too, so one series with holes can no longer poison the axis
    domain for every series on it.

No API change, no new option — connectNulls keeps its documented meaning and now actually works.

Reproducing

@stregouet's minimal repro is at https://github.com/stregouet/test-solidcharts — delete
data.value2 at one index and both lines vanish on main; with this patch the first line renders
normally and the second draws as two segments around the gap (or one continuous line with
connectNulls).

@p32929 p32929 closed this by deleting the head repository Sep 21, 2026
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.

[Bug]: Cannot draw multiple lines with empty point

1 participant