Skip to content

DOC use sphinx-gallery css variable to adapt light/dark theme#27659

Merged
GaelVaroquaux merged 6 commits intoscikit-learn:mainfrom
glemaitre:improve-website-estimator
Nov 3, 2023
Merged

DOC use sphinx-gallery css variable to adapt light/dark theme#27659
GaelVaroquaux merged 6 commits intoscikit-learn:mainfrom
glemaitre:improve-website-estimator

Conversation

@glemaitre
Copy link
Copy Markdown
Member

The website rendering uses the CSS variable defined by sphinx-gallery. Therefore, we use the default OS preference while sphinx-gallery already provide some CSS variable.

Here, we intend to use these variables for a better integration (and it should make it compatible with pydata-theme for the future).

@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 25, 2023

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 455ed20. Link to the linter CI: here

--sklearn-color-text-on-default-background: var(--theme-code-foreground, var(--jp-content-font-color1, black));
--sklearn-color-background: var(--theme-background, var(--jp-layout-color0, white));
--sklearn-color-border-box: var(--theme-code-foreground, var(--jp-content-font-color1, black));
--sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double check that I understand this CSS (in which case TIL CSS vars!): this is going to set --sklearn-color-text-on-default-background to the value of --sg-text-color if it exists, falling back to --theme-code-foreground, falling back to --jp-content-font-color1 and if none of those exists black?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes exactly. So checking the rendering, it seems that does not solve the issue because sphinx-gallery is detecting that I am in a dark mode while we don't have dark mode in scikit-learn. Maybe it uses the OS then.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means that switching to a proper light/dark mode as the one offered by the pydata-sphinx-theme would be the way to go.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So sphinx-gallery sets the value of --sg-text-color based on the OS setting?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to make it work, I need to add data-theme="light" in the <html> tag since this is the selector imposed by sphinx-gallery.

Copy link
Copy Markdown
Member

@betatim betatim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming my understanding in the comment is correct, I think we should merge this.

It feels like a better solution would be to "invert" this. So that sphinx-gallery or a notebook viewer could set the colours used. But this is something for a new PR (if it is even a good idea).

@glemaitre
Copy link
Copy Markdown
Member Author

OK it works now.

@glemaitre
Copy link
Copy Markdown
Member Author

@GaelVaroquaux do you want to merge this one. Just to explain visually what it changes on my OS.

main branch

image

pr branch

image

@betatim
Copy link
Copy Markdown
Member

betatim commented Oct 27, 2023

Taking a step back to see if I understand what happens/this PR does: when the OS (or browser?) is set to dark mode currently the gallery is unchanged (white background) but the estimator representation changes to "dark mode". This is because the gallery doesn't automatically switch and the estimator does. Is that right?

I think we should merge this and maybe also think about some way to solve this "generically", without having to extend the var(var(var())) nesting we have to include ever more different CSS variable names.

@glemaitre
Copy link
Copy Markdown
Member Author

when the OS (or browser?) is set to dark mode currently the gallery is unchanged (white background) but the estimator representation changes to "dark mode". This is because the gallery doesn't automatically switch and the estimator does. Is that right?

This is right.

@betatim betatim added the Waiting for Second Reviewer First reviewer is done, need a second one! label Oct 31, 2023
Copy link
Copy Markdown
Member

@GaelVaroquaux GaelVaroquaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but it would be good to add a note somewhere in the docs.

Do we have docs for downstream libraries? We should

@GaelVaroquaux
Copy link
Copy Markdown
Member

Once the note in the doc is added, this is ready to merge (and I can do the merge)

@GaelVaroquaux GaelVaroquaux merged commit a1e263a into scikit-learn:main Nov 3, 2023
REDVM pushed a commit to REDVM/scikit-learn that referenced this pull request Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation module:utils Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants