Skip to content

stack invalid values as NaN#2390

Merged
mbostock merged 5 commits intomainfrom
fil/stack-nan
Apr 1, 2026
Merged

stack invalid values as NaN#2390
mbostock merged 5 commits intomainfrom
fil/stack-nan

Conversation

@Fil
Copy link
Copy Markdown
Contributor

@Fil Fil commented Mar 19, 2026

We have originally stacked invalid values as 0 height segments (where X1[i] == X2[i] is the current height of the stack). But I think they should be ignored instead (X1[i] = X2[i] = NaN). This feels more principled.

Pros:

  • cleaner information (an invalid value is kept throughout)
  • allows to draw interrupted stacked lines

Con:

  • gaps appear when an area "suddenly disappears" instead of vanishing in a continuous way (but this is "wrong", and can be solved by mapping NaNs to zeroes if the user wants, so it's not removing any feature).
before after
before after

blocks #2133

@Fil Fil requested a review from mbostock March 19, 2026 11:52
@Fil Fil mentioned this pull request Mar 19, 2026
@mbostock
Copy link
Copy Markdown
Member

mbostock commented Apr 1, 2026

We can trace this design back to d3/d3-shape#52 (2015!) where d3.stack treats NaN lengths as zero, rather than propagating the NaN to the stacked extent.

I found another case where a zero was creeping in (the emptyFacet test, where the VALUE column is undefined), and simplified the logic.

@mbostock mbostock enabled auto-merge (squash) April 1, 2026 16:32
@mbostock mbostock merged commit f4a989c into main Apr 1, 2026
1 of 2 checks passed
@mbostock mbostock deleted the fil/stack-nan branch April 1, 2026 16:34
@mbostock
Copy link
Copy Markdown
Member

mbostock commented Apr 1, 2026

Previously: #2178 #2179.

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.

2 participants