Skip to content

feat(plotly): add per-chart locale support#6428

Merged
masenf merged 10 commits into
reflex-dev:mainfrom
BABTUNA:feat-6101-plotly-locale
Jun 23, 2026
Merged

feat(plotly): add per-chart locale support#6428
masenf merged 10 commits into
reflex-dev:mainfrom
BABTUNA:feat-6101-plotly-locale

Conversation

@BABTUNA

@BABTUNA BABTUNA commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Description

Adds first-pass Plotly locale support on
x.plotly and plotly dist variants via a new locale prop.

What changed:

  • Added locale prop to Plotly.
  • Added plotly.js-locales@3.5.0 dependency/import.
  • Added locale helpers that resolve locale data and merge it into config (locale + locales) at render time.
  • Kept locale handling internal to config (the raw locale prop is excluded from direct component props).
  • Added unit coverage for both
    x.plotly(...) and
    x.plotly.basic(...) locale flow.
  • Added docs section showing localized usage.
  • Updated pyi_hashes.json for packages/reflex-components-plotly/src/reflex_components_plotly/plotly.pyi.

Validation:

  • uv run --no-sync ruff check packages/reflex-components-plotly/src/reflex_components_plotly/plotly.py tests/units/components/graphing/test_plotly.py
  • uv run --no-sync pytest tests/units/components/graphing/test_plotly.py -q
  • uv run --no-sync pytest tests/units/components/graphing -q

Closes #6101

@BABTUNA BABTUNA requested review from a team and Alek99 as code owners April 30, 2026 17:01
@codspeed-hq

codspeed-hq Bot commented Apr 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 26 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing BABTUNA:feat-6101-plotly-locale (dbf10d2) with main (474f5b6)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@greptile-apps

greptile-apps Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds per-chart locale support to rx.plotly (and all dist variants) via a new locale prop. The locale prop is excluded from direct React props and instead wrapped into the Plotly config at render time using JS helper functions, following the conditional-import pattern from moment.py.

  • New locale: Var[str] prop on the Plotly base class; excluded from direct props via _exclude_props; emits plotly.js-locales@3.5.0 import and JS locale helpers (_rxResolvePlotlyLocaleData, _rxGetPlotlyLocaleConfig) only when the prop is set, keeping zero cost for charts that don't use locale.
  • _render wraps the effective config through _rxGetPlotlyLocaleConfig, resolving locale data from the bundled locale dictionary and merging it with any user-supplied config (including state-driven configs).
  • Unit tests verify the render shape and the helper name appears in the config expression; integration tests (Playwright) confirm modebar tooltips are localized and that state-driven configs are preserved when a locale is merged.

Confidence Score: 5/5

Safe to merge — the locale prop is correctly gated, zero-cost for charts without it, and the render path handles both static and state-driven configs without regressions.

The conditional import and custom-code pattern mirrors moment.py correctly. The Reflex framework's _iter_parent_classes_with_method calls every distinct add_imports override in the MRO chain independently, so the plotlyLocales import is automatically included for all dist variants when locale is set — no super() calls required. _render correctly overwrites the config prop with the locale-wrapped expression, and locale is properly excluded from direct React props. Unit and integration tests cover the expected render shape and end-to-end localization behaviour.

No files require special attention.

Important Files Changed

Filename Overview
packages/reflex-components-plotly/src/reflex_components_plotly/plotly.py Core implementation: adds conditional locale import and helpers; _render correctly wraps config; _exclude_props updated; dist-variant subclasses do not need to call super().add_imports() — the Reflex framework invokes each unique add_imports in the MRO chain independently.
tests/units/components/graphing/test_plotly.py Adds unit tests for locale render output for both rx.plotly and rx.plotly.basic; verifies _rxGetPlotlyLocaleConfig in config prop and that locale is excluded from direct props.
tests/integration/tests_playwright/test_plotly.py New integration test: verifies localized modebar titles for de/fr locales and that locale merges cleanly with a state-driven config without dropping config options.
docs/library/graphing/other-charts/plotly.md Adds a short Locale Configuration section with a runnable demo exec example and a note about mixing locale= with config=.
pyi_hashes.json Updated .pyi hash for the plotly package to reflect the new locale prop.

Reviews (4): Last reviewed commit: "add integration test for plotly charts w..." | Re-trigger Greptile

Comment thread packages/reflex-components-plotly/src/reflex_components_plotly/plotly.py Outdated
BABTUNA added 3 commits May 8, 2026 19:39
…t subclasses

- Gate plotly.js-locales import behind locale prop (follows moment.py pattern)
- Gate locale helper custom code behind locale prop
- Fix all dist-variant subclasses to inherit parent imports via super()
- Update pyi_hashes.json for regenerated plotly.pyi
Comment thread packages/reflex-components-plotly/src/reflex_components_plotly/plotly.py Outdated
BABTUNA and others added 3 commits May 24, 2026 00:57
…classes

The add_imports interface already merges imports from parent classes,
so calling super().add_imports() explicitly is unnecessary. Subclasses
now just return their own additions.
masenf
masenf previously approved these changes Jun 23, 2026
@masenf masenf merged commit 1224c43 into reflex-dev:main Jun 23, 2026
107 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support locale config for rx.plotly

2 participants