-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adds
@register_theme
decorator (#3526)
* feat: Adds `@register_theme` decorator Resolves one item in #3519 * build: run `update-init-file` Adds `@register_theme` to top-level * test: Adds `test_register_theme_decorator` * refactor(typing): Specify `dict[str, Any]` instead of `dict[Any, Any]` The latter may give false-positives for json-incompatible dicts --------- Co-authored-by: Stefan Binder <[email protected]>
- Loading branch information
1 parent
5207768
commit f542e9e
Showing
6 changed files
with
114 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -617,6 +617,7 @@ | |
"mixins", | ||
"param", | ||
"parse_shorthand", | ||
"register_theme", | ||
"renderers", | ||
"repeat", | ||
"sample", | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ | |
renderers, | ||
) | ||
from .schema import * | ||
from .theme import themes | ||
from .theme import register_theme, themes |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import altair.vegalite.v5 as alt | ||
from altair.vegalite.v5.theme import VEGA_THEMES | ||
from altair.vegalite.v5.theme import VEGA_THEMES, register_theme, themes | ||
|
||
|
||
@pytest.fixture | ||
def chart(): | ||
return alt.Chart("data.csv").mark_bar().encode(x="x:Q") | ||
|
||
|
||
def test_vega_themes(chart): | ||
def test_vega_themes(chart) -> None: | ||
for theme in VEGA_THEMES: | ||
with alt.themes.enable(theme): | ||
dct = chart.to_dict() | ||
assert dct["usermeta"] == {"embedOptions": {"theme": theme}} | ||
assert dct["config"] == { | ||
"view": {"continuousWidth": 300, "continuousHeight": 300} | ||
} | ||
|
||
|
||
def test_register_theme_decorator() -> None: | ||
@register_theme("unique name", enable=True) | ||
def custom_theme() -> dict[str, int]: | ||
return {"height": 400, "width": 700} | ||
|
||
assert themes.active == "unique name" | ||
registered = themes.get() | ||
assert registered is not None | ||
assert registered() == {"height": 400, "width": 700} == custom_theme() |