-
Notifications
You must be signed in to change notification settings - Fork 793
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
refactor: alt.themes
-> alt.theme
#3618
Open
dangotbanned
wants to merge
52
commits into
main
Choose a base branch
from
refac-alt-theme
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
54e7e48
chore: Add notes for change targets
dangotbanned 66c51c3
chore: Add TODO in `update_init_file.py`
dangotbanned 754f665
refactor: Remove `altair.vegalite.v5.theme` from `alt.__all__`
dangotbanned 3dd9100
refactor: Add `alt.theme.py`
dangotbanned b1be633
build(typing): Generate `altair.vegalite.v5.schema.__init__.__all__`
dangotbanned 0bd8f75
build: Generate `altair.vegalite.v5.__init__.__all__`
dangotbanned c996c95
refactor: `utils.theme` -> `vegalite.v5.theme`
dangotbanned c286c38
refactor: Remove `alt.typing.theme`
dangotbanned ef9b846
refactor: Adds `alt.theme` implementation
dangotbanned e8d3062
test: Fix `test_common`
dangotbanned f7fe38b
chore(typing): Remove now fix ignore comments
dangotbanned 0a1c8d3
fix(typing): Use a bounded `TypeVar` to support `list[str]`
dangotbanned 05eca89
refactor: Add deprecation handling `alt.__init__.__getattr__`
dangotbanned 217d7fb
docs: Adds `alt.theme` to API Reference
dangotbanned 5078f88
docs: Add missing `altair` qualifier for `TypedDict`(s)
dangotbanned 2339116
fix(typing): Preserve generics in `PluginEnabler`
dangotbanned 48e44c0
refactor: Refine and fully document `generate_schema__init__`
dangotbanned a7dbaca
refactor: Use new functions for part of `update__all__variable`
dangotbanned a0947f8
fix: Don't consider suffix a part in `path_to_module_str`
dangotbanned 1e9f639
fix: Account for GH runner path
dangotbanned d895447
docs: Add link targets for API Reference sections
dangotbanned a9538bc
docs: Customize theme toctree order
dangotbanned e114493
docs: Update User Guide section
dangotbanned c8033b2
docs: Provide API ref link in warning
dangotbanned ef0f263
refactor: Remove unused `__future__` import
dangotbanned 58da996
feat: Support `alt.theme.(active|options)`
dangotbanned bc507a9
fix(typing): Partial resolve `mypy` `__getattr__`
dangotbanned e0f4721
test: Rename test to `test_theme_register_decorator`
dangotbanned 4e8def0
test: Add some more `(theme|themes)` equal checks
dangotbanned 9bd0316
test: Add `test_theme_unregister`
dangotbanned 0d95b44
feat: Raise instead of returning `None` in `unregister`
dangotbanned 3e6bde8
docs: Update remaining `ThemeRegistry` methods
dangotbanned 6141c7c
Merge branch 'main' into refac-alt-theme
dangotbanned d1ae98e
Merge branch 'main' into refac-alt-theme
dangotbanned 2ca4b11
Merge branch 'main' into refac-alt-theme
dangotbanned d3dccab
Merge branch 'main' into refac-alt-theme
dangotbanned 7c49b51
test: Adds `test_theme_remote_lambda`
dangotbanned a3e2d28
Merge branch 'main' into refac-alt-theme
dangotbanned a018165
docs: Suggest `alt.theme` instead of `alt.theme.themes`
dangotbanned 98f4ed3
Merge branch 'main' into refac-alt-theme
dangotbanned 4fe4321
Merge remote-tracking branch 'upstream/main' into refac-alt-theme
dangotbanned 2b3eb35
refactor: Rename `theme.themes` -> `theme._themes`
dangotbanned 10872b6
docs: Update `@theme.register`
dangotbanned 1127534
docs: Update `customization.rst`
dangotbanned cb56c82
feat: Add support displaying warning once
dangotbanned 0977228
docs: Adds `utils.deprecation.__all__`
dangotbanned 5a1dc68
docs: Add examples to deprecation message
dangotbanned 22d7df2
docs: Prefix `"
dangotbanned 25cbdc8
docs(typing): Adds static-only deprecation for `themes.register`
dangotbanned e29a2f7
Merge branch 'main' into refac-alt-theme
dangotbanned a0497e0
docs: "Deprecated in" -> "Deprecated since"
dangotbanned b84fd5f
docs: Add more specific constraints to `@deprecated_static_only`
dangotbanned File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,266 @@ | ||
"""Customizing chart configuration defaults.""" | ||
|
||
from __future__ import annotations | ||
|
||
from functools import wraps as _wraps | ||
from typing import TYPE_CHECKING | ||
|
||
from altair.vegalite.v5.schema._config import ( | ||
AreaConfigKwds, | ||
AutoSizeParamsKwds, | ||
AxisConfigKwds, | ||
AxisResolveMapKwds, | ||
BarConfigKwds, | ||
BindCheckboxKwds, | ||
BindDirectKwds, | ||
BindInputKwds, | ||
BindRadioSelectKwds, | ||
dangotbanned marked this conversation as resolved.
Show resolved
Hide resolved
|
||
BindRangeKwds, | ||
BoxPlotConfigKwds, | ||
BrushConfigKwds, | ||
CompositionConfigKwds, | ||
ConfigKwds, | ||
DateTimeKwds, | ||
DerivedStreamKwds, | ||
ErrorBandConfigKwds, | ||
ErrorBarConfigKwds, | ||
FeatureGeometryGeoJsonPropertiesKwds, | ||
FormatConfigKwds, | ||
GeoJsonFeatureCollectionKwds, | ||
GeoJsonFeatureKwds, | ||
GeometryCollectionKwds, | ||
GradientStopKwds, | ||
HeaderConfigKwds, | ||
IntervalSelectionConfigKwds, | ||
IntervalSelectionConfigWithoutTypeKwds, | ||
LegendConfigKwds, | ||
LegendResolveMapKwds, | ||
LegendStreamBindingKwds, | ||
LinearGradientKwds, | ||
LineConfigKwds, | ||
LineStringKwds, | ||
LocaleKwds, | ||
MarkConfigKwds, | ||
MergedStreamKwds, | ||
MultiLineStringKwds, | ||
MultiPointKwds, | ||
MultiPolygonKwds, | ||
NumberLocaleKwds, | ||
OverlayMarkDefKwds, | ||
PaddingKwds, | ||
PointKwds, | ||
PointSelectionConfigKwds, | ||
PointSelectionConfigWithoutTypeKwds, | ||
PolygonKwds, | ||
ProjectionConfigKwds, | ||
ProjectionKwds, | ||
RadialGradientKwds, | ||
RangeConfigKwds, | ||
RectConfigKwds, | ||
ResolveKwds, | ||
RowColKwds, | ||
ScaleConfigKwds, | ||
ScaleInvalidDataConfigKwds, | ||
ScaleResolveMapKwds, | ||
SelectionConfigKwds, | ||
StepKwds, | ||
StyleConfigIndexKwds, | ||
ThemeConfig, | ||
TickConfigKwds, | ||
TimeIntervalStepKwds, | ||
TimeLocaleKwds, | ||
TitleConfigKwds, | ||
TitleParamsKwds, | ||
TooltipContentKwds, | ||
TopLevelSelectionParameterKwds, | ||
VariableParameterKwds, | ||
ViewBackgroundKwds, | ||
ViewConfigKwds, | ||
) | ||
from altair.vegalite.v5.theme import themes | ||
|
||
if TYPE_CHECKING: | ||
import sys | ||
from typing import Callable | ||
|
||
if sys.version_info >= (3, 11): | ||
from typing import LiteralString | ||
else: | ||
from typing_extensions import LiteralString | ||
if sys.version_info >= (3, 10): | ||
from typing import ParamSpec | ||
else: | ||
from typing_extensions import ParamSpec | ||
|
||
from altair.utils.plugin_registry import Plugin | ||
|
||
P = ParamSpec("P") | ||
|
||
__all__ = [ | ||
"AreaConfigKwds", | ||
"AutoSizeParamsKwds", | ||
"AxisConfigKwds", | ||
"AxisResolveMapKwds", | ||
"BarConfigKwds", | ||
"BindCheckboxKwds", | ||
"BindDirectKwds", | ||
"BindInputKwds", | ||
"BindRadioSelectKwds", | ||
"BindRangeKwds", | ||
"BoxPlotConfigKwds", | ||
"BrushConfigKwds", | ||
"CompositionConfigKwds", | ||
"ConfigKwds", | ||
"DateTimeKwds", | ||
"DerivedStreamKwds", | ||
"ErrorBandConfigKwds", | ||
"ErrorBarConfigKwds", | ||
"FeatureGeometryGeoJsonPropertiesKwds", | ||
"FormatConfigKwds", | ||
"GeoJsonFeatureCollectionKwds", | ||
"GeoJsonFeatureKwds", | ||
"GeometryCollectionKwds", | ||
"GradientStopKwds", | ||
"HeaderConfigKwds", | ||
"IntervalSelectionConfigKwds", | ||
"IntervalSelectionConfigWithoutTypeKwds", | ||
"LegendConfigKwds", | ||
"LegendResolveMapKwds", | ||
"LegendStreamBindingKwds", | ||
"LineConfigKwds", | ||
"LineStringKwds", | ||
"LinearGradientKwds", | ||
"LocaleKwds", | ||
"MarkConfigKwds", | ||
"MergedStreamKwds", | ||
"MultiLineStringKwds", | ||
"MultiPointKwds", | ||
"MultiPolygonKwds", | ||
"NumberLocaleKwds", | ||
"OverlayMarkDefKwds", | ||
"PaddingKwds", | ||
"PointKwds", | ||
"PointSelectionConfigKwds", | ||
"PointSelectionConfigWithoutTypeKwds", | ||
"PolygonKwds", | ||
"ProjectionConfigKwds", | ||
"ProjectionKwds", | ||
"RadialGradientKwds", | ||
"RangeConfigKwds", | ||
"RectConfigKwds", | ||
"ResolveKwds", | ||
"RowColKwds", | ||
"ScaleConfigKwds", | ||
"ScaleInvalidDataConfigKwds", | ||
"ScaleResolveMapKwds", | ||
"SelectionConfigKwds", | ||
"StepKwds", | ||
"StyleConfigIndexKwds", | ||
"ThemeConfig", | ||
"ThemeConfig", | ||
"TickConfigKwds", | ||
"TimeIntervalStepKwds", | ||
"TimeLocaleKwds", | ||
"TitleConfigKwds", | ||
"TitleParamsKwds", | ||
"TooltipContentKwds", | ||
"TopLevelSelectionParameterKwds", | ||
"VariableParameterKwds", | ||
"ViewBackgroundKwds", | ||
"ViewConfigKwds", | ||
"enable", | ||
"get", | ||
"names", | ||
"register", | ||
"themes", | ||
"unregister", | ||
] | ||
|
||
|
||
def register( | ||
name: LiteralString, *, enable: bool | ||
) -> Callable[[Plugin[ThemeConfig]], Plugin[ThemeConfig]]: | ||
""" | ||
Decorator for registering a theme function. | ||
|
||
Parameters | ||
---------- | ||
name | ||
Unique name assigned in ``alt.theme.themes``. | ||
enable | ||
Auto-enable the wrapped theme. | ||
|
||
Examples | ||
-------- | ||
Register and enable a theme:: | ||
|
||
import altair as alt | ||
from altair import theme | ||
|
||
|
||
@theme.register("param_font_size", enable=True) | ||
def custom_theme() -> theme.ThemeConfig: | ||
sizes = 12, 14, 16, 18, 20 | ||
return { | ||
"autosize": {"contains": "content", "resize": True}, | ||
"background": "#F3F2F1", | ||
"config": { | ||
"axisX": {"labelFontSize": sizes[1], "titleFontSize": sizes[1]}, | ||
"axisY": {"labelFontSize": sizes[1], "titleFontSize": sizes[1]}, | ||
"font": "'Lato', 'Segoe UI', Tahoma, Verdana, sans-serif", | ||
"headerColumn": {"labelFontSize": sizes[1]}, | ||
"headerFacet": {"labelFontSize": sizes[1]}, | ||
"headerRow": {"labelFontSize": sizes[1]}, | ||
"legend": {"labelFontSize": sizes[0], "titleFontSize": sizes[1]}, | ||
"text": {"fontSize": sizes[0]}, | ||
"title": {"fontSize": sizes[-1]}, | ||
}, | ||
"height": {"step": 28}, | ||
"width": 350, | ||
} | ||
|
||
Until another theme has been enabled, all charts will use defaults set in ``custom_theme``:: | ||
|
||
from vega_datasets import data | ||
|
||
source = data.stocks() | ||
lines = ( | ||
alt.Chart(source, title=alt.Title("Stocks")) | ||
.mark_line() | ||
.encode(x="date:T", y="price:Q", color="symbol:N") | ||
) | ||
lines.interactive(bind_y=False) | ||
|
||
""" | ||
|
||
# HACK: See for `LiteralString` requirement in `name` | ||
# https://github.com/vega/altair/pull/3526#discussion_r1743350127 | ||
def decorate(func: Plugin[ThemeConfig], /) -> Plugin[ThemeConfig]: | ||
themes.register(name, func) | ||
if enable: | ||
themes.enable(name) | ||
|
||
@_wraps(func) | ||
def wrapper(*args: P.args, **kwargs: P.kwargs) -> ThemeConfig: | ||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
return decorate | ||
|
||
|
||
def unregister(name: LiteralString) -> Plugin[ThemeConfig] | None: | ||
""" | ||
Remove and return a previously registered theme. | ||
|
||
Parameters | ||
---------- | ||
name | ||
Unique name assigned in ``alt.theme.themes``. | ||
""" | ||
return themes.register(name, None) | ||
dangotbanned marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
enable = themes.enable | ||
get = themes.get | ||
names = themes.names | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solution is fine currently, but as soon as we start deprecating other imports it would make sense to generalize