Skip to content

fix NaN ticks crashing - #1335

Merged
mbostock merged 3 commits into
mainfrom
fil/fix-1334
Mar 15, 2023
Merged

mbostock merged 3 commits into
mainfrom
fil/fix-1334

Conversation

@Fil

@Fil Fil commented Mar 14, 2023

Copy link
Copy Markdown
Contributor

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

@mbostock mbostock left a comment

Copy link
Copy Markdown
Member

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.

Comment thread src/marks/text.js Resolved

@mbostock mbostock left a comment

Copy link
Copy Markdown
Member

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 <mbostock@gmail.com>
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