Skip to content
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

Merged
merged 1 commit into from Apr 22, 2020

Conversation

ktmud
Copy link
Member

@ktmud ktmud commented Apr 22, 2020

CATEGORY

  • Bug Fix

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 for superset-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.

image

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TEST PLAN

  1. Go to line chart
  2. Change number formatters back and forth between "Original value" and others
  3. It shouldn't throw JS errors when you hover on the chart for tooltips.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

@etr2460 @kristw @graceguo-supercat

Copy link
Member

@etr2460 etr2460 left a 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?

@ktmud
Copy link
Member Author

ktmud commented Apr 22, 2020

Oops, missed that in the document. But they seem to produce identical results, though:

image

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
@ktmud ktmud changed the title fix: change number format to original value to "~f" fix: change number format to original value to "~g" Apr 22, 2020
Copy link
Member

@etr2460 etr2460 left a 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!

@etr2460 etr2460 merged commit 7b33d54 into apache:master Apr 22, 2020
etr2460 pushed a commit to airbnb/superset-fork that referenced this pull request Apr 22, 2020
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
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.37.0 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XS 🚢 0.37.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants