Bug description

How can I define custom number formats via config.py?

Like this formats? AVAILABLE_NUMERIC_FORMATS = { "db (no decimals)": ",.0f db", "db (2 decimals)": ",.2f db", "kg (1 decimal)": ",.1f kg", "Ft (SI notation)": ".2s Ft", "Ft (2 decimals)": ",.2f Ft", "Ft (no decimals)": ",.0f Ft", "nap (2 decimals)": ",.2f nap", }

Also tried with D3 but now working: D3_FORMAT = { "decimal": ",", "thousands": ".", "grouping": [3], "currency": ["", " Ft"], },{ "decimal": ",", "thousands": ".", "grouping": [3], "currency": ["", " db"], }

I tried but could not find possibility in the doc.

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • [x] I have searched Superset docs and Slack and didn't find a solution to my problem.
  • [x] I have searched the GitHub issue tracker and didn't find a similar bug report.
  • [x] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.

Comment From: dosubot[bot]

I couldn't find specific information on defining custom number formats via config.py in the Superset repository. However, Superset does integrate D3 formatting for numbers using the createD3NumberFormatter function. This involves specifying a formatString in the configuration object, which is used as the ID for the formatter and determines the formatting style using D3's format function [1].

For custom number formats, you might want to explore using the NumberFormatterRegistry in Superset, which allows you to register and retrieve custom formatters. You can create a formatter with a valid D3 format string and handle invalid format strings by displaying an error message and setting isInvalid to true [2].

If you are trying to set locale-specific formats, you can customize locale settings using the locale property in the formatter configuration. This includes settings for decimal, thousands, grouping, and currency symbols [3].

For more detailed examples, you can refer to the tests and examples in the Superset codebase, such as those found in createD3NumberFormatter.test.ts and NumberFormat.stories.tsx [4][5].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

Comment From: rusackas

@ebaratte added this feature, and may be able to spot the issue here and/or provide additional clarity. Here's the PR for reference. If either of you want to add some additional documentation (in code comments or as a PR to the docs site), that would be awesome.

Comment From: rusackas

Moving this to a Discussion since it's a config question rather than a bug, in my opinion. :)