Skip to content
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

Add new option vega_theme_light #25

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You can customize the plugin by setting options in `mkdocs.yml`. For example:
plugins:
- charts:
vega_width: container
vega_theme: default
vega_theme_light: default
vega_theme_dark: dark
vega_renderer: svg
use_data_path: True
Expand All @@ -22,9 +22,9 @@ You can customize the plugin by setting options in `mkdocs.yml`. For example:
```

- `vega_width` (default is `container`). When not specified explicitly in the JSON schema, the `width` to use (see [vegalite customizing size](https://vega.github.io/vega-lite/docs/size.html)). When set to `container` width will be 100%.
- `vega_theme` (default is `default`). Specify one of the available [vegalite themes](https://vega.github.io/vega-themes/).
- `vega_theme_dark` (default is `dark`). When using the [mkdocs-material](https://squidfunk.github.io/mkdocs-material) theme with a dark mode or the user's preferred color scheme in the browser or OS is "dark", automatically render charts using this theme. Dark mode toggle is also supported. Specify one of the available [vegalite themes](https://vega.github.io/vega-themes/).
- `vega_renderer` (default is `svg`). Specify one of the available [vegalite renderers](https://vega.github.io/vega-themes/).
- `vega_theme_light` (default is `default`). Specify one of the available [vegalite themes](https://vega.github.io/vega-themes/) to use when in light mode. When using the [mkdocs-material](https://squidfunk.github.io/mkdocs-material) theme with a light mode or the user's preferred color scheme in the browser or OS is "light", automatically render charts using this theme. [Color pallete toggle](https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/#color-palette-toggle) is also supported.
- `vega_theme_dark` (default is `dark`). Specify one of the available [vegalite themes](https://vega.github.io/vega-themes/) to use when in dark mode. When using the [mkdocs-material](https://squidfunk.github.io/mkdocs-material) theme with a dark mode or the user's preferred color scheme in the browser or OS is "dark", automatically render charts using this theme. [Color pallete toggle](https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/#color-palette-toggle) is also supported.
- `vega_renderer` (default is `svg`). Specify one of `canvas` or `svg`. See the [demo vegalite renderers](https://vega.github.io/vega-themes/).
- `use_data_path` (default is `True`). When `True`, any relative urls used in the JSON schema are relative to the `data_path`. When `False`, relative urls should be relative to the URL of the page.
- `data_path` (default is `""`). When `use_data_path` is enabled, the base path relative to the `docs/` folder.
- `integrations.mkdocs_material.themes_light` (default is `[default]`). When using the [mkdocs-material](https://squidfunk.github.io/mkdocs-material) theme, specify the light [color schemes](https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/#color-scheme).
Expand Down
4 changes: 1 addition & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ nav:

plugins:
- search
- charts:
vega_theme: default
vega_renderer: "canvas"
- charts
- git-revision-date-localized:
type: timeago
timezone: Europe/Amsterdam
Expand Down
8 changes: 7 additions & 1 deletion mkdocs_charts_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class ChartsPlugin(BasePlugin):
config_scheme = (
("data_path", config_options.Type(str, default="")),
("use_data_path", config_options.Type(bool, default=True)),
("vega_theme", config_options.Type(str, default="default")),
("vega_theme", config_options.Type(str, default="deprecated")),
("vega_theme_light", config_options.Type(str, default="default")),
("vega_theme_dark", config_options.Type(str, default="dark")),
("vega_renderer", config_options.Type(str, default="svg")),
("vega_width", config_options.Type(str, default="container")),
Expand All @@ -48,6 +49,11 @@ def on_config(self, config, **kwargs):
Event trigger on config.
See https://www.mkdocs.org/user-guide/plugins/#on_config.
"""
if self.config.get("vega_theme") != "deprecated":
raise PluginError(
"[mkdocs_charts_plugin]: 'vega_theme' is deprecated and has been renamed to 'vega_theme_light'. Together with 'vega_theme_dark' this enables automatic theme switching. Please update your mkdocs.yml."
)

# Add pointer to mkdocs-charts-plugin.js
# which is added to the output directory during on_post_build() event
config["extra_javascript"] = ["js/mkdocs-charts-plugin.js"] + config["extra_javascript"]
Expand Down
1 change: 0 additions & 1 deletion tests/fixtures/projects/basic/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ theme:
plugins:
# - search
- charts:
vega_theme: dark
vega_renderer: "canvas"

use_directory_urls: true
Expand Down
36 changes: 36 additions & 0 deletions tests/fixtures/projects/basic/mkdocs_colorswitch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
site_name: My Docs

theme:
name: material
palette:
# Palette toggle for light mode
- scheme: default
toggle:
icon: material/brightness-7
name: Switch to dark mode

# Palette toggle for dark mode
- scheme: slate
toggle:
icon: material/brightness-4
name: Switch to light mode

plugins:
# - search
- charts

use_directory_urls: true

markdown_extensions:
- pymdownx.superfences:
custom_fences:
- name: vegalite
class: vegalite
format: !!python/name:mkdocs_charts_plugin.fences.fence_vegalite
- pymdownx.tabbed:
alternate_style: true

extra_javascript:
- https://cdn.jsdelivr.net/npm/vega@5
- https://cdn.jsdelivr.net/npm/vega-lite@5
- https://cdn.jsdelivr.net/npm/vega-embed@6
5 changes: 3 additions & 2 deletions tests/fixtures/projects/basic/mkdocs_instant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ theme:
plugins:
# - search
- charts:
vega_theme: dark
vega_theme_light: default
vega_theme_dark: dark
vega_renderer: "canvas"

use_directory_urls: true
Expand All @@ -18,7 +19,7 @@ markdown_extensions:
custom_fences:
- name: vegalite
class: vegalite
format: !!python/name:mkdocs_charts_plugin.fences.fence__vegalite
format: !!python/name:mkdocs_charts_plugin.fences.fence_vegalite
- pymdownx.tabbed:
alternate_style: true

Expand Down
1 change: 0 additions & 1 deletion tests/fixtures/projects/invalid_json/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ site_name: My Docs

plugins:
- charts:
vega_theme: dark
vega_renderer: "canvas"

use_directory_urls: true
Expand Down
Loading