Skip to content

fix NaN ticks crashing #1335

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

Merged
merged 3 commits into from
Mar 15, 2023
Merged

fix NaN ticks crashing #1335

merged 3 commits into from
Mar 15, 2023

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Mar 14, 2023

Guard against formatDefault returning undefined (it always returns a string except when the value is NaN)

Fixes #1334

related to #493

…string except when the value is NaN)

Closes #1334

related to #493
@Fil Fil requested a review from mbostock March 14, 2023 11:56
Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. I’m a little surprised (I had forgotten) that the format functions can return undefined. I wonder if it wouldn’t be better to have them return the empty string so that callers can rely on them always returning a string? It looks like this would be acceptable for our usage and it would obviate a need for a workaround here.

I’m also a little surprised that we format invalid dates as “Invalid Date” when we format NaN as undefined (equivalent to the empty string). Maybe those should be more consistent, too? But that’s a separate issue.

Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I experimented more with changing the format functions to return the empty string instead of undefined for the edge cases, and I changed my mind: I think it’s nice to retain the type safety of undefined in these cases. For example, our default filtering removes null and undefined, but not the empty string.

I incorporated the ?? style suggestion.

@mbostock mbostock merged commit c489290 into main Mar 15, 2023
@mbostock mbostock deleted the fil/fix-1334 branch March 15, 2023 02:41
chaichontat pushed a commit to chaichontat/plot that referenced this pull request Jan 14, 2024
* Guard against formatDefault returning undefined (it always returns a string except when the value is NaN)

Closes observablehq#1334

related to observablehq#493

* coalesce null to empty string

* DRY

---------

Co-authored-by: Mike Bostock <[email protected]>
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.

the default axis can crash on NaN ticks
2 participants