| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
When floating-point arithmetic produces a tick value that is slightly off its true position (e.g. -8.88e-16 instead of 0), the default formatter is immune because it adds an internal rounding epsilon before rendering. Custom d3 formats specified via tickformat (such as '~r') don't go through that path and expose the raw number, which can produce labels like '−0.0000000000000000888178' for a tick that should read '0'. Fix by snapping v to the nearest ideal tick position (tick0 + n*dtick) before passing it to the user's formatter, using a relative threshold of 1e-9 of dtick so only genuine floating-point noise is removed. Fixes plotly#7765
|
Thanks for the PR! You and two others submitted fixes for the issue and I ended up combining some of your code into #7901 and merging that PR. As such, I'm going to close this one. Thanks for your contribution! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #7765
What's wrong
When floating-point arithmetic leaves a tick value slightly off its true grid position — for example -8.88e-16 instead of 0 — the result depends on which formatter is used. The built-in formatter is safe because it adds an internal rounding epsilon and then rounds to the computed number of significant digits. But when a user sets tickformat (e.g. '~r', '.4f') the value is passed straight to d3-format, which faithfully renders the raw float:
The fix
Before delegating to the user's formatter, snap v to the nearest ideal tick position tick0 + n * dtick. The tolerance is 1e-9 × dtick, which is well below any deliberate non-zero tick value but comfortably above the floating-point noise that accumulates over a handful of dtick additions.
The snap is only applied to non-hover labels (hover already independently recalculates its own rounding) and only when both tick0 and dtick are numeric (so date and log axes are unaffected).
Changes