-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
fix: change number format to original value to "~g" #9608
Conversation
15f5b93
to
bf028c6
Compare
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.
I'm not 100% convinced that ~f
does the same thing as
after reading the d3-format docs. Specifically i see this line:
The type
(none) is also supported as shorthand for
~g
(with a default precision of 12 instead of 6)
Should we use ~g
instead of ~f
here?
Originally it uses " ", which do give the original value, but will not work when the `getNumberFormatter` in `superset-ui/number-format` is called for the second time. Because the format will successfully register as "" [1], but cannot be obtained again via `registry.get()`[2]. [1]: https://github.com/apache-superset/superset-ui/blob/44ad062dd02d080362dac28782c0327cc9fa3445/packages/superset-ui-number-format/src/NumberFormatterRegistry.ts#L30 [2]: https://github.com/apache-superset/superset-ui/blob/dc804b7a707e0cb8c29fc129bfff2c9aa143fd62/packages/superset-ui-core/src/models/RegistryWithDefaultKey.ts#L36
bf028c6
to
3d33904
Compare
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.
hmm weird. thanks for making the change though!
Originally it uses " ", which do give the original value, but will not work when the `getNumberFormatter` in `superset-ui/number-format` is called for the second time. Because the format will successfully register as "" [1], but cannot be obtained again via `registry.get()`[2]. [1]: https://github.com/apache-superset/superset-ui/blob/44ad062dd02d080362dac28782c0327cc9fa3445/packages/superset-ui-number-format/src/NumberFormatterRegistry.ts#L30 [2]: https://github.com/apache-superset/superset-ui/blob/dc804b7a707e0cb8c29fc129bfff2c9aa143fd62/packages/superset-ui-core/src/models/RegistryWithDefaultKey.ts#L36
CATEGORY
SUMMARY
#9562 adds number formatters for original value and integers. This PR changes number formatter for original value from
" "
(a space character) to~g
(decimal or exponential notation without trailing zeros). The original formatter" "
is a valid d3 format and does return the original value as expected, but cannot be used as a registry key forsuperset-ui/number-format
.This is because the registry automatically trims the registry key while creating a formatter, but when obtaining a formatter it returns
undefined
for an empty string""
.This is problematic when users changes the formatters back and forth in Explore view, resulting in JS errors.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
TEST PLAN
ADDITIONAL INFORMATION
REVIEWERS
@etr2460 @kristw @graceguo-supercat