-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
feat: custom d3 number locale #20075
Conversation
Codecov Report
@@ Coverage Diff @@
## master #20075 +/- ##
=======================================
Coverage 68.02% 68.03%
=======================================
Files 1936 1937 +1
Lines 74929 74943 +14
Branches 8141 8141
=======================================
+ Hits 50974 50987 +13
Misses 21870 21870
- Partials 2085 2086 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
This is very cool. Would be great to just set D3_FORMAT and pass that in to the docker image. |
Tables with different currencies are crying aside and waiting for the merge |
Great feature! Hope to see it merged soon |
Is there a way to bring this issue to the notice of reviewers? |
Are there plans to merge or include in 3.0 release? |
Waiting for this merge. |
I'm sorry for repeated nudge, but this is a really helpful feature. Waiting for this PR to be merged.. |
Please, we really need this feature! |
Would also love if this get reviewed and merged! |
@ebaratte would you be able to rebase this PR to fix the conflicts? |
I rebased the PR, we should be good to go. |
d12cff2
to
ec9d938
Compare
6b1b2c5
to
bbfff77
Compare
@justinpark @eschutho @kgabryje @villebro any updates? |
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 know that Superset is badly lacking in this space, but the main issue I have with this approach is the fact that it assumes the deployment as a whole speaks one single locale. As we start to prepare for making Superset more localizable (see e.g. a WIP PR of mine that adds timezone support to the chart data API: #23511), it would be nice if we could start making gradual progress towards having user or chart specific locales. Let's say we want to have one chart that shows euros, and another that shows US dollars. This would not be possible with this setting.
Having said that, I think this approach is good to cover use cases where the entire deployment wants to "speak" only one specific locale, as long as we leave open the door for making this overridable per user/chart. And based on my review this doesn't paint us into any corner, so I think this looks good. Thoughts @ebaratte @Pedrolrbr @kgabryje @rusackas ?
superset/config.py
Outdated
# "currency": ["$", ""] # - currency prefix/suffix strings (e.g., ["$", ""]) | ||
# } | ||
# https://github.com/d3/d3-format/blob/main/README.md#formatLocale | ||
D3_FORMAT: Dict[str, Any] = {} |
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.
nit: as TypedDict
is now a default thing in our currently supported Python versions, I'd prefer to create a D3Format(TypedDict)
for this.
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.
Sure, I updated the type definition
@@ -150,6 +151,7 @@ export interface CommonBootstrapData { | |||
extra_sequential_color_schemes: SequentialSchemeConfig[]; | |||
theme_overrides: JsonObject; | |||
menu_data: MenuData; | |||
d3_format: Partial<FormatLocaleDefinition>; |
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.
Do we really need Partial
here? It appears that the added dict
in config.py
defines all properties of FormatLocaleDefinition
. If not, let's make sure the type in config.py
reflects the partialness (this could be done by adding total=False
to the Python class that's extending TypedDict
).
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 think we do; the way the code is set up, a user can specify a subset of the formatting options in config.py
(total=False
in the type definition).
The default values are set in the front (D3FormatConfig.ts
, and setD3Format()
in NumberFormatterRegistry.ts:52
)
0446aea
to
606bbf1
Compare
This is indeed the general idea of this PR: set default values for the whole instance. This is especially relevant for the currency, since there is no proper way at the moment to change the default currency, and displaying an incorrect currency makes the charts incorrect - whereas number formatting is more of a cosmetic issue. Obviously, it assumes that all the data is in a single currency. It shouldn't prevent local overrides, like:
|
Ok you don't need to convince me more @ebaratte 🙂 Looks good to go to me, but there appears to be some frontend UTs that are failing. Please take a look so we can get this in 👍 |
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.
LGTM once the tests are passing.
Rebased to fix the tests (#23805) |
Yay! Can't wait to test this out!! |
Hoping to test this on an ephemeral build, but then I can't wait to click the Merge button on this!!!! 🚀 |
/testenv up |
Sorry for all the noise on the thread, folks! I'm trying to troubleshoot the ephemeral environment builds, so it needs a little kicking ;) |
@rusackas Ephemeral environment spinning up at http://54.200.4.245:8080. Credentials are |
Had a nice long chat with @mistercrunch about this approach and a couple other approaches to improving currency handling in Superset. At the end of the day, I think all three have their place. Expect some more proposals and/or PRs in the future. In the meantime, this looks ready to go. Thanks for the PR!!!! Hitting the merge button! |
Ephemeral environment shutdown and build artifacts deleted. |
Just cross-linking the alternative designs for future reference (somehow Github doesn't place links from Discussion threads for issue mentions into the issue log automatically ...) |
@phifa
|
Does it work on version 2.1.0 ? Nothing changes for me. |
No. This PR is not part of 2.1 This PR is only available in the master branch. |
SUMMARY
This PR is an attempt to provide a way of customising the format of the numbers and currency displayed in superset frontend.
It is linked to (at least) issues #3972, #18938, #11328, #8913
Please also look at PR #17796, which provides a different approach to the same issue.
Design choice:
LANGUAGES
config key: the user can use different parameters for the frontend language and number formattingBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before
After:
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION