Skip to content

Commit d7bbb79

Browse files
authored
Inheritance Diagram Dark Mode Support (#1834)
Apply CSS filtering to have the inheritance diagram conform to dark mode, and add a example demonstrating inheritance diagram in kitchensink.. We also install graphviz on CI to test this. The css will only apply to inheritance diagram and not to all graphviz output. Addresses #820
1 parent e248a5a commit d7bbb79

File tree

8 files changed

+83
-6
lines changed

8 files changed

+83
-6
lines changed

.github/workflows/CI.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ jobs:
145145
with:
146146
python-version: ${{ matrix.python-version }}
147147
pandoc: true
148+
- name: "Install Graphviz on Windows 🗔"
149+
if: runner.os == 'Windows'
150+
run: choco install graphviz
151+
- name: "Install Graphviz on macOS "
152+
if: runner.os == 'macOS'
153+
run: |
154+
brew update
155+
brew install graphviz
156+
- name: "Install Graphviz on Linux 🐧"
157+
if: runner.os == 'Linux'
158+
run: |
159+
sudo apt-get update
160+
sudo apt-get install -y --no-install-recommends graphviz
148161
- name: "Build docs and check for warnings 📖"
149162
shell: bash
150163
run: |

docs/conf.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"sphinx.ext.autosummary",
3232
"sphinx.ext.todo",
3333
"sphinx.ext.viewcode",
34+
"sphinx.ext.intersphinx",
35+
"sphinx.ext.graphviz",
3436
"sphinxext.rediraffe",
3537
"sphinx_design",
3638
"sphinx_copybutton",
@@ -60,6 +62,8 @@
6062
# This pattern also affects html_static_path and html_extra_path.
6163
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "**.ipynb_checkpoints"]
6264

65+
intersphinx_mapping = {"sphinx": ("https://www.sphinx-doc.org/en/master", None)}
66+
6367
# -- Sitemap -----------------------------------------------------------------
6468

6569
# ReadTheDocs has its own way of generating sitemaps, etc.
@@ -90,6 +94,16 @@
9094
"jupyter": ("Jupyter", "https://jupyter.org"),
9195
}
9296

97+
98+
# -- sphinx_ext_graphviz options ---------------------------------------------
99+
100+
graphviz_output_format = "svg"
101+
inheritance_graph_attrs = dict(
102+
rankdir="LR",
103+
fontsize=14,
104+
ratio="compress",
105+
)
106+
93107
# -- sphinx_togglebutton options ---------------------------------------------
94108
togglebutton_hint = str(_("Click to expand"))
95109
togglebutton_hint_hide = str(_("Click to collapse"))

docs/examples/graphviz.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
========
2+
Graphviz
3+
========
4+
5+
Inheritance Diagram
6+
-------------------
7+
8+
If you use :mod:`sphinx.ext.inheritance_diagram` to generate inheritance diagrams with
9+
:mod:`sphinx.ext.graphviz`, and you output the inheritance diagrams in SVG format,
10+
they will automatically adapt to this theme's light or dark mode.
11+
12+
To have the inheritance-diagram render to SVG, inside ``conf.py``, you need
13+
the following option.
14+
15+
.. code-block:: python
16+
17+
# conf.py
18+
...
19+
graphviz_output_format = 'svg'
20+
...
21+
22+
Below is an example of the inheritance diagram for ``matplotlib.figure.Figure``.
23+
Try toggling light/dark mode to see it adapt!
24+
25+
.. inheritance-diagram:: matplotlib.figure.Figure
26+
27+
See the sphinx inheritance-diagram `documentation`_ for more information.
28+
29+
.. _documentation: https://www.sphinx-doc.org/en/master/usage/extensions/inheritance.html

docs/examples/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ See the sections in the primary sidebar and below to explore.
1818
kitchen-sink/index
1919
pydata
2020
execution
21+
graphviz
2122

2223

2324
.. Note: the caption below is intentionally long in order to test out what long captions look like.

pyproject.toml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[build-system]
2-
requires = ["sphinx-theme-builder @ https://github.com/pradyunsg/sphinx-theme-builder/archive/87214d0671c943992c05e3db01dca997e156e8d6.zip"]
2+
requires = [
3+
"sphinx-theme-builder @ https://github.com/pradyunsg/sphinx-theme-builder/archive/87214d0671c943992c05e3db01dca997e156e8d6.zip",
4+
]
35
build-backend = "sphinx_theme_builder"
46

57
[tool.sphinx-theme-builder]
@@ -10,7 +12,7 @@ additional-compiled-static-assets = [
1012
"vendor/",
1113
"styles/bootstrap.css",
1214
"scripts/bootstrap.js",
13-
"locale/"
15+
"locale/",
1416
]
1517

1618
[project]
@@ -27,7 +29,7 @@ dependencies = [
2729
"Babel",
2830
"pygments>=2.7",
2931
"accessible-pygments",
30-
"typing-extensions"
32+
"typing-extensions",
3133
]
3234
license = { file = "LICENSE" }
3335
maintainers = [
@@ -52,7 +54,7 @@ classifiers = [
5254
[project.optional-dependencies]
5355
doc = [
5456
"numpydoc",
55-
"linkify-it-py", # for link shortening
57+
"linkify-it-py", # for link shortening
5658
"rich",
5759
"sphinxext-rediraffe",
5860
"sphinx-sitemap",
@@ -76,10 +78,18 @@ doc = [
7678
"nbsphinx",
7779
"ipyleaflet",
7880
"colorama",
79-
"ipywidgets"
81+
"ipywidgets",
82+
"graphviz",
8083
]
8184
test = ["pytest", "pytest-cov", "pytest-regressions", "sphinx[test]"]
82-
dev = ["pyyaml", "pre-commit", "pydata-sphinx-theme[doc,test]", "tox", "pandoc", "sphinx-theme-builder[cli]"]
85+
dev = [
86+
"pyyaml",
87+
"pre-commit",
88+
"pydata-sphinx-theme[doc,test]",
89+
"tox",
90+
"pandoc",
91+
"sphinx-theme-builder[cli]",
92+
]
8393
a11y = ["pytest-playwright"]
8494
i18n = ["Babel", "jinja2"]
8595

readthedocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ build:
77
os: ubuntu-20.04
88
tools:
99
python: "3.10"
10+
apt_packages:
11+
- graphviz
1012
jobs:
1113
# build the gallery of themes before building the doc
1214
post_install:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* Styles for graphviz generated output from Sphinx */
2+
3+
/* Style the inheritance diagram such that it has a dark mode */
4+
html[data-theme="dark"] div.graphviz > object.inheritance {
5+
filter: brightness(0.8) invert(0.82) contrast(1.2);
6+
color-scheme: normal;
7+
}

src/pydata_sphinx_theme/assets/styles/pydata-sphinx-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
@import "./extensions/copybutton";
6969
@import "./extensions/ethical-ads";
7070
@import "./extensions/execution";
71+
@import "./extensions/graphviz";
7172
@import "./extensions/pydata";
7273
@import "./extensions/sphinx_design";
7374
@import "./extensions/togglebutton";

0 commit comments

Comments
 (0)