-
Notifications
You must be signed in to change notification settings - Fork 272
Add SMART_NUMBER formatter and make it default #109
Conversation
Codecov Report
@@ Coverage Diff @@
## master #109 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 72 73 +1
Lines 861 888 +27
Branches 195 204 +9
=====================================
+ Hits 861 888 +27
Continue to review full report at Codecov.
|
We should add a note to |
} = {}, | ||
) { | ||
const { description, signed = false, id, label } = config; | ||
const siFormatter = d3Format(`.3~s`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could move these outside the function so they aren't created every call? looks like they don't ever change so no reason not to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solid change! one suggestion 💬
aa477da
to
4be2807
Compare
There were the following issues with this Pull Request
You may need to change the commit messages to comply with the repository contributing guidelines. 🤖 This comment was generated by commitlint[bot]. Please report issues here. Happy coding! |
BREAKING CHANGE: NumberFormat.xxx are renamed
4be2807
to
e31d54d
Compare
Motivation
From apache/superset#6916 and past encounters with number formatting, Superset's default
D3
's SI formatter works ok most of the time but have some too scientific outputs which confuses general users such asxxxG
(G = Giga
) instead ofB
which people associate with billions and are more familiar with.1,000,000,000 => '1G'
P.S. Luckily, millions and Mega have the same
M
abbreviation.micro (m)
which can be confused withm
for minutes when the users are unaware of the context.0.01 => '10m'
3
. This cause unnecessary rounding for small numbers.123.45 => '123'
Superset users therefore often have to define custom formatting or in the billion case, have to tolerate it.
Changes
This PR addresses the issues above and provide more humanized outputs for these edge cases, so the default number formatter should work most of the time out-of-the-box. It will reduce the amount of custom formatting need and improve user experience.
1,000,000,000 => '1B'
0.01 => '0.01'
123.45 => '123.45'
💔 Breaking Changes
NumberFormats
changing_CHANGE
to_SIGNED
.SMART_NUMBER
instead ofD3
.3~s
.🏆 Enhancements
createSmartNumberFormatter
.