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

Custom D3 datetime formatting not showing with adaptive datetime option #31790

Open
3 tasks done
ampil opened this issue Jan 10, 2025 · 1 comment
Open
3 tasks done

Custom D3 datetime formatting not showing with adaptive datetime option #31790

ampil opened this issue Jan 10, 2025 · 1 comment
Labels
viz:charts Namespace | Anything related to viz types

Comments

@ampil
Copy link

ampil commented Jan 10, 2025

Bug description

The new PR introduced custom D3 datetime formatting.

However, it works partially - when datetime format is forced to %b, %B for example.
When the datetime is set to Adaptive, the custom datetime format ignored reverting back month names to English.

How to reproduce the bug:
Add a custom D3 Time format to superset_config.py:

D3_TIME_FORMAT = {
  "dateTime": "%d.%m.%Y %H:%M:%S",
  "date": "%d.%m.%Y",
  "time": "%H:%M:%S",
  "periods": ["AM", "PM"],
  "days": ["Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота", "Воскресенье"],
  "shortDays": ["Пон", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс"],
  "months": ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
  "shortMonths": ["Янв", "Фев", "Мар", "Апр", "Май", "Июн", "Июл", "Авг", "Сен", "Окт", "Ноя", "Дек"]
}

Create a virtual dataset with some data (PostgreSQL syntax):

select startdate::date as startdate
      , floor(random() * 100) + 1 AS random_integer
from generate_series('2024-05-25', now(), '1 day'::interval) as startdate  
order by startdate desc;

Create a line chart with start_date on the X-axis, random_integer on the Y-axis:
image

Change X-axis datetime format to %B, note the changes:
image

Screenshots/recordings

Another example related to the same behaviour:

The custom D3 datetime format shows up when a certain datetime format applied, for example %B:
image
image

But in case an adaptive formatting applied on the X axis, the E3 formatting is reverting back to defaults (English):
image
image

Superset version

4.1.1

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • 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.
@dosubot dosubot bot added the viz:charts Namespace | Anything related to viz types label Jan 10, 2025
Copy link

dosubot bot commented Jan 10, 2025

The issue you're experiencing with the 'adaptive' datetime formatting option reverting to English month names instead of using your custom D3 datetime format is likely due to how the 'adaptive' option is implemented in Superset. The 'adaptive' option, when set, uses a dynamic formatter based on the data's granularity and does not automatically apply custom D3 formats specified in superset_config.py for localization [1][2].

To address this, you might need to ensure that the locale settings are correctly applied when using the 'adaptive' option. The createSmartDateFormatter function in the codebase supports a locale parameter, which can be used to provide non-English month and day names [3]. However, it seems that this locale parameter might not be automatically linked to the custom D3 formats defined in superset_config.py.

A potential workaround could be to explicitly set the locale in the frontend code where the formatter is applied, ensuring that your custom month and day names are used. This might require modifying the Superset codebase to pass the locale information from your configuration to the formatter.

If this approach is not feasible, consider using a specific D3 format instead of 'adaptive' to ensure your custom settings are applied.

To continue talking to Dosu, mention @dosu.


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
viz:charts Namespace | Anything related to viz types
Projects
None yet
Development

No branches or pull requests

1 participant