Commit 15f1151 1 parent c12ca27 commit 15f1151 Copy full SHA for 15f1151
File tree 2 files changed +81
-10
lines changed
2 files changed +81
-10
lines changed Original file line number Diff line number Diff line change 1
1
"""Utilities for registering and working with themes."""
2
2
3
- from typing import Callable
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from typing import TYPE_CHECKING , Callable
4
7
5
8
from .plugin_registry import PluginRegistry
6
9
10
+ if sys .version_info >= (3 , 11 ):
11
+ from typing import LiteralString
12
+ else :
13
+ from typing_extensions import LiteralString
14
+
15
+ if TYPE_CHECKING :
16
+ from altair .utils .plugin_registry import PluginEnabler
17
+ from altair .vegalite .v5 .theme import _ThemeName
18
+
7
19
ThemeType = Callable [..., dict ]
8
20
9
21
10
22
class ThemeRegistry (PluginRegistry [ThemeType , dict ]):
11
- pass
23
+ def enable (
24
+ self , name : LiteralString | _ThemeName | None = None , ** options
25
+ ) -> PluginEnabler :
26
+ """
27
+ Enable a theme by name.
28
+
29
+ This can be either called directly, or used as a context manager.
30
+
31
+ Parameters
32
+ ----------
33
+ name : string (optional)
34
+ The name of the theme to enable. If not specified, then use the
35
+ current active name.
36
+ **options :
37
+ Any additional parameters will be passed to the theme as keyword
38
+ arguments
39
+
40
+ Returns
41
+ -------
42
+ PluginEnabler:
43
+ An object that allows enable() to be used as a context manager
44
+
45
+ Notes
46
+ -----
47
+ Default `vega` themes can be previewed at https://vega.github.io/vega-themes/
48
+ """
49
+ return super ().enable (name , ** options )
Original file line number Diff line number Diff line change 2
2
3
3
from __future__ import annotations
4
4
5
- from typing import Final
5
+ from typing import TYPE_CHECKING , Final , Literal
6
6
7
7
from altair .utils .theme import ThemeRegistry
8
8
9
+ if TYPE_CHECKING :
10
+ import sys
11
+
12
+ if sys .version_info >= (3 , 10 ):
13
+ from typing import TypeAlias
14
+ else :
15
+ from typing_extensions import TypeAlias
16
+
17
+ # If you add a theme here, also add it in `VEGA_THEMES` below.
18
+ _ThemeName : TypeAlias = Literal [
19
+ "default" ,
20
+ "carbonwhite" ,
21
+ "carbong10" ,
22
+ "carbong90" ,
23
+ "carbong100" ,
24
+ "dark" ,
25
+ "excel" ,
26
+ "fivethirtyeight" ,
27
+ "ggplot2" ,
28
+ "googlecharts" ,
29
+ "latimes" ,
30
+ "opaque" ,
31
+ "powerbi" ,
32
+ "quartz" ,
33
+ "urbaninstitute" ,
34
+ "vox" ,
35
+ ]
36
+
37
+ # If you add a theme here, also add it in `_ThemeName` above.
9
38
VEGA_THEMES = [
10
- "ggplot2 " ,
11
- "quartz " ,
12
- "vox " ,
13
- "fivethirtyeight " ,
39
+ "carbonwhite " ,
40
+ "carbong10 " ,
41
+ "carbong90 " ,
42
+ "carbong100 " ,
14
43
"dark" ,
15
- "latimes" ,
16
- "urbaninstitute" ,
17
44
"excel" ,
45
+ "fivethirtyeight" ,
46
+ "ggplot2" ,
18
47
"googlecharts" ,
48
+ "latimes" ,
19
49
"powerbi" ,
50
+ "quartz" ,
51
+ "urbaninstitute" ,
52
+ "vox" ,
20
53
]
21
54
22
55
@@ -38,7 +71,7 @@ def __repr__(self) -> str:
38
71
39
72
# The entry point group that can be used by other packages to declare other
40
73
# themes that will be auto-detected. Explicit registration is also
41
- # allowed by the PluginRegistery API.
74
+ # allowed by the PluginRegistry API.
42
75
ENTRY_POINT_GROUP : Final = "altair.vegalite.v5.theme"
43
76
themes = ThemeRegistry (entry_point_group = ENTRY_POINT_GROUP )
44
77
You can’t perform that action at this time.
0 commit comments