| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
Fixes tick label formatting in numFormat for very small numbers where String(v) returns exponential notation, preventing invalid/truncated tick strings.
Changes:
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| var adjustedTickRound = tickRound + exponentVal; | ||
| if(dp) { | ||
| if(adjustedTickRound < 0) { | ||
| mantissa = mantissa.slice(0, dp - 1); | ||
| } else { | ||
| mantissa = mantissa.slice(0, dp + adjustedTickRound).replace(/\.?0+$/, ''); | ||
| } |
| } else { | ||
| mantissa = mantissa.slice(0, dp + adjustedTickRound).replace(/\.?0+$/, ''); | ||
| } | ||
| } |
| var vStr = String(v); | ||
| var ep = vStr.indexOf('e'); | ||
| if(ep >= 0) { | ||
| var mantissa = vStr.slice(0, ep); | ||
| var exponentStr = vStr.slice(ep); | ||
| var dp = mantissa.indexOf('.') + 1; | ||
| var exponentVal = parseInt(exponentStr.slice(1), 10); | ||
| var adjustedTickRound = tickRound + exponentVal; | ||
| if(dp) { | ||
| if(adjustedTickRound < 0) { | ||
| mantissa = mantissa.slice(0, dp - 1); | ||
| } else { | ||
| mantissa = mantissa.slice(0, dp + adjustedTickRound).replace(/\.?0+$/, ''); | ||
| } | ||
| } | ||
| v = mantissa + exponentStr; | ||
| } else { | ||
| v = vStr; | ||
| var dp = v.indexOf('.') + 1; | ||
| if(dp) v = v.slice(0, dp + tickRound).replace(/\.?0+$/, ''); | ||
| } |
| v = String(v); | ||
| var dp = v.indexOf('.') + 1; | ||
| if(dp) v = v.slice(0, dp + tickRound).replace(/\.?0+$/, ''); | ||
| var vStr = String(v); | ||
| var ep = vStr.indexOf('e'); | ||
| if(ep >= 0) { | ||
| var mantissa = vStr.slice(0, ep); | ||
| var exponentStr = vStr.slice(ep); | ||
| var dp = mantissa.indexOf('.') + 1; | ||
| var exponentVal = parseInt(exponentStr.slice(1), 10); | ||
| var adjustedTickRound = tickRound + exponentVal; | ||
| if(dp) { | ||
| if(adjustedTickRound < 0) { | ||
| mantissa = mantissa.slice(0, dp - 1); | ||
| } else { | ||
| mantissa = mantissa.slice(0, dp + adjustedTickRound).replace(/\.?0+$/, ''); | ||
| } | ||
| } | ||
| v = mantissa + exponentStr; | ||
| } else { | ||
| v = vStr; | ||
| var dp = v.indexOf('.') + 1; | ||
| if(dp) v = v.slice(0, dp + tickRound).replace(/\.?0+$/, ''); | ||
| } |
There was a problem hiding this comment.
What do you think of replacing most of this with a call to toFixed? The exponent portion should get added further down on line 2240 (in your branch).
Sorry, something went wrong.
|
@camdecoster Applied! Replaced the custom mantissa slicing with a clean oFixed call. |
Sorry, something went wrong.
|
There was some funkiness with adding the rounding increment, so I made a few changes. Now the tests are passing! Speaking of which, could you please add some tests that check this new approach? Also, could you please add a draftlog? |
Sorry, something went wrong.
…otation and add draftlog
|
Hi @camdecoster, I've added the tests for this approach in numformat_test.js and added the draftlog as requested! All CI checks are passing successfully. Let me know if there's anything else needed. |
Sorry, something went wrong.
|
Friendly nudge @camdecoster! As everything is fully updated and all CI checks are passing, could you please take another look and approve this so we can merge? Thank you! |
Sorry, something went wrong.
|
I'm taking a look today. |
Sorry, something went wrong.
There was a problem hiding this comment.
FYI, some of the obvious issues that this PR addresses are now managed by the changes in #7901. That being said, this change is still useful. Thanks for your contribution!
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
What this PR does
This PR fixes a bug in src/plots/cartesian/axes.js where formatting very small numbers could result in invalid tick strings (e.g. "-9.381779999999999e-") when String(v) produces exponential notation but the numFormat logic slices the string indiscriminately.
Fix details
When exponential notation is present, the logic now separates the mantissa from the exponent, applies precision formatting to the mantissa, and re-attaches the exponent string, avoiding string truncation that removes the exponential component.
Tested against locally failing reproductions and verified using test-jasmine to ensure no existing suites are broken.