Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null percent plots as zero #2072

Closed
yurivish opened this issue Jun 7, 2024 · 1 comment · Fixed by #2073
Closed

Null percent plots as zero #2072

yurivish opened this issue Jun 7, 2024 · 1 comment · Fixed by #2073
Assignees
Labels
bug Something isn’t working

Comments

@yurivish
Copy link
Contributor

yurivish commented Jun 7, 2024

Plotting data with nulls normally causes those data points to be omitted from the plot. But if you use a percent channel option, it will plot them at zero.

https://observablehq.com/@yurivish/null-percent

I'm not entirely sure this is a bug but the behavior does seem quite surprising.

@mbostock mbostock added the bug Something isn’t working label Jun 7, 2024
@mbostock
Copy link
Member

mbostock commented Jun 7, 2024

Yep that’s a bug. The percent transform is currently (x) => x * 100 but I agree it should preserve nulls or coerce them to NaN rather than zero. As a workaround, you can represent values as NaN or undefined instead of null and it will work, or could set the transform option explicitly to something like (x) => x == null ? NaN : x * 100.

Plot.dot(time, { x: time, y: value }).plot({ y: { percent: true, transform: (x) => x == null ? NaN : x * 100 } })

@mbostock mbostock self-assigned this Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants