ENH Add themes for HTML display. Add dark theme#26862
ENH Add themes for HTML display. Add dark theme#26862adrinjalali merged 49 commits intoscikit-learn:mainfrom
Conversation
|
Normally, one does not call Normally this is done with a |
Yes, agree this change won't solve the dark theme problem (since as you said, this would require some detection on the browser). Instead, it adds a theming layer to the HTML renders. Also later, we can add dark theme with detection using @thomasjpfan how do you think about the overall approach? |
|
It seems the main use-case of the light/dark mode switching is to match it up to the light/dark mode used by the notebook that the HTML representation is rendered into. So I think we should add this if we have a way to query the notebook viewer (JupyterLab, VS Code, others?) to find out if they are using light/dark mode. This is another level up in complexity from using CSS Overall I think adding a way for the user to set the theme for the HTML repr by hand is not that attractive because it seems it would add yet another toggle (OS level, JupyterLab level, and scikit-learn level). And all of them are not connected to each other :-/ |
|
For me the question is "why would you want to do that?" - this is a serious question from me as someone who never uses dark mode. So I'm a weird person because a lot of people love dark mode and/or being able to switch. However it does mean I can't imagine why you'd ever want to have the notebook in dark (light) mode but the estimator reprs in light (dark) mode. Do you have an idea? |
|
@betatim I don't use dark mode myself either, and not aiming to solve the dark-mode problem with this MR. However, I do use Jupyter to generate reports and diagrams. And having the ability to style the pipeline diagram will certainly be useful. |
|
Put differently, this MR:
|
|
To me it seems like we need to wait for jupyterlab/jupyterlab#8777 to be able to have an automated themed' fix. In the meantime, we could make |
Interesting, yes Approach 1 - In Pipeline, add new optional attribute
|
|
I don't think we need to support multiple themes, and it certainly doesn't make sense to add this as an argument to pipeline. And this is only a temporary solution, in the long run, we'd depend on whatever the css info tells us. |
|
@thomasjpfan @adrinjalali pls help review again, thank you Looks like it can close #26364 |
|
I was thinking, I can start a next PR (and a few more in sequence) to refactor this themes section of the codebase in small and safe steps. The goal being to bring better support for CSS variables. At some point, it may be possible to set themes on jupyter-themes, that can propagate the styles to Do let me know wdyt this. |
thomasjpfan
left a comment
There was a problem hiding this comment.
Overall, I am happy with using css variables and prefers-color-scheme as the first step.
| _STYLE = """ | ||
| #$id { | ||
| color: black; | ||
| --sklearn-color-1: black; |
There was a problem hiding this comment.
I know I suggested the template for these variable names, but do you see better names for these color options given their usage?
For example, --sklearn-color-1 can be renamed to --sklearn-font-color.
There was a problem hiding this comment.
Hmm true, could be a matter of naming preference: whether we wanna define by color scheme (in which numbering 1 to 5 would be fine I think), or by its function/purpose. Maybe for now, we can do by purpose until we require theming it. Check out the latest commit
5953ca8 to
f0c5238
Compare
adcc5e2 to
11516c2
Compare
|
let me re-open, need to fix the branches |
|
Reopening |
|
@thomasjpfan @adrinjalali PR is ready for review again |
betatim
left a comment
There was a problem hiding this comment.
LGTM. I think this is a good improvement over what we have right now.

Reference Issues/PRs
Implements feature request for styled diagrams. See #26364
Screen.Recording.2023-07-20.at.11.14.01.PM.mov
Updated the documentation on Displaying Pipelines:

What does this implement/fix? Explain your changes.
This MR adds an extensible way to generate themes for HTML renders.
A dark theme is added to show how it is used.
Without any theme given, it falls back to the default "light" theme:

When a theme such as

themes.DARKis given, it can set the theme to dark theme:Any other comments?