ENG-10444: Add high-level theme presets to the declarative API#114
Open
FarhanAliRaza wants to merge 6 commits into
Open
ENG-10444: Add high-level theme presets to the declarative API#114FarhanAliRaza wants to merge 6 commits into
FarhanAliRaza wants to merge 6 commits into
Conversation
xy.theme() gains preset/color_scheme/palette/accent/contrast on top of the existing token escape hatches. Presets resolve Python-side into the implemented --chart-* vocabulary and a default mark palette threaded through Figure, so browser, standalone HTML, SVG, native PNG, and Chromium exports all agree by construction. color_scheme="system" ships both variants (dom.style + dom.styleDark) and the client swaps them on prefers-color-scheme; browser-free exports deterministically use light. Unknown names fail with actionable errors; xy.theme_presets() and xy.theme_palettes() cover discovery. Includes docs, a preset gallery page, and catalog/precedence/wire/export tests.
Merging this PR will not alter performance
Comparing Footnotes
|
…high-level-themes-to-the-declarative-xy-api
masenf
reviewed
Jul 20, 2026
Scheme-pinned presets set the figure background inline but left --chart-bg, --chart-legend-bg, and --chart-modebar-bg inheritable, so a host page defining those tokens per color mode (the docs styling surface and app-level chart style both do) repainted a pinned chart's plot rect and legend/modebar chips to the page's mode — dark plot areas inside pinned-light cards and unreadable legend text. Every preset variant now pins all three surfaces with the engine's own scheme defaults (plot rect transparent so the figure background shows through), which changes nothing outside token-setting hosts. The SVG exporter treats fully transparent background paints as omitted so exports don't gain dead transparent rects.
Greptile SummaryThis PR adds high-level theme presets to the declarative chart API. The main changes are:
Confidence Score: 5/5No blocking issue was identified. Accent alpha handling preserves accepted eight-digit colors, and no separate issue qualifies for a comment.
What T-Rex did
Important Files Changed
Reviews (2): Last reviewed commit: "fix(themes): honor accent alpha instead ..." | Re-trigger Greptile |
…high-level-themes-to-the-declarative-xy-api # Conflicts: # examples/demo-advance.ipynb # python/xy/_svg.py
_normalize_accent advertised #rrggbbaa in its error message and accepted it, then truncated to the opaque base — so accent="#8b5cf680" rendered selection, zoom, focus, and modebar-active at full opacity. The solid tokens now keep the caller's alpha; the faint fills still derive from the opaque base so appending the fixed fill alpha stays a valid 8-digit hex.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Summary
Adds an ergonomic high-level theming layer to
xy.theme()while keeping the existing token-based escape hatches and export behavior intact:Design
python/xy/_themes.py: immutable preset catalog + resolver). Presets emit only the implemented--chart-*token vocabulary plus rootbackground, and a default mark palette threaded throughFigure.default_paletteinto mark building — so browser, standalone HTML, Python SVG, native PNG, and Chromium export all agree by construction. No new JS token vocabulary.color_scheme="system"ships both variants on the wire (dom.stylelight +dom.styleDark); the render client swaps them on the existingprefers-color-schemelistener. Browser-free exports (SVG, native PNG) and headless Chromium deterministically use the light variant — passcolor_scheme="dark"to export dark. Documented.docs/styling/themes-and-tokens.md: engine defaults → preset → color scheme → palette/accent/contrast → named low-level args →theme(style={})→ chartstyle={}→ explicit mark colors.ValueErrorlisting the valid options;xy.theme_presets()/xy.theme_palettes()enumerate the catalog. Matplotlib-compatible stylesheet names stay inxy.pyplot.style.backgroundin both schemes, preserving thedata-xy-own-bg/ VS Code white-card behavior.Docs
docs/styling/theme-presets.md) rendering all five presets in light and dark, wired into the docs nav.Testing
tests/test_themes.py: catalog integrity (implemented-tokens-only, hex palettes), resolver purity/immutability, actionable validation errors, backward compat, full precedence chain, system dual-variant wire spec, palette→marks/categorical with explicit colors winning.system.ruff check/formatclean;node js/build.mjsreproduces the committed bundles byte-identically;scripts/render_smoke_nonumpy.pypasses.systemtoggle with a headless-Chromium probe (stubbedmatchMedia): tokens flip light→dark→light on the change event with no errors and no MutationObserver feedback loop.Closes ENG-10444.