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.
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 mantine_light and mantine_dark plotly figure templates #431
add mantine_light and mantine_dark plotly figure templates #431
Changes from 1 commit
9817ca4
c09c8cd
ca444b1
036173b
edf1163
141b7af
395709f
d6f42eb
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I'm a little uneasy about automatically calling this - the convenience is great, but it's a bit magical. For example if you like these themes and want to use them without DMC, you have to know to import the package anyway and silence your linter.
Curious if perhaps @ndrezn you know whether any other packages add their own templates like this, or if you have thoughts on this pattern?
If we do automatically call this, there's no reason to import it by name in
__init__.py
- justimport .figure_templates
will do.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.
I started with requiring it to be imported in an app, but thought it was an unnecessary line of code when it could just be made available, but I see your point about it being too magical.
I can't imagine why anyone would use this outside of DMC though. It's not different enough from
plotly_white
andplotly_dark
themes. It's just tweaked a little to make it look better with the color tones used in the default DMC theme.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.
I think this is okay, but I also haven't seen it before. It's quite nice to be able to use the templates API natively but I agree it's not obvious what's going on.
Probably worth a specific documentation page that explains how to do this and maybe provides a reduced import if you want to use just the named themes but not the rest of Mantine (
from dash_mantine_components import templates
?)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.
If it's documented that when you use the dmc library, you will have access to the "mantine_light" and "mantine_dark" templates, shouldn't that be OK?, Why is that any more magical than having access to all the other built-in templates that come with the Plotly library? They are not set as defaults - you have to specify them in the figure definition otherwise you get the standard "plotly" template. I really don't think people would want to use these templates if they are not using DMC
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.
It feels somewhat magical to me because with the built-in templates you can go look for docs on the
template
arg and you immediately get to https://plotly.com/python/templates/#view-available-themes - which lists all the built-in templates, and you can go from there to learn about each of these templates. With these ones, an operation that normally has no side-effects (importing a library) results in extra options being available in a different library, so if you want to learn about these or if they disappeared and you want to know how to get them back, what do you do?That said, given that the new options have the name
mantine
in them and that's a pretty distinctive name, it probably wouldn't be too hard for users to connect the dots and figure out that they came fromdash_mantine_components
- then if it's obvious how to find them in the docs we're good. Also we document exactly the pattern you're using 😅 https://plotly.com/python/templates/#saving-and-distributing-custom-themesSo OK, let's leave it as is. Then I'd still change the import in
__init__.py
to justimport .figure_templates
😎I don't think we can do this - importing a submodule will always import the parent - so unless we wanted to move the rest of DMC out of the top-level module we're always going to get it. Anyway I guess @AnnMarieW is right that this is similar enough to built-in themes that this is unlikely to come up much.
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.
ah, OK, I get it now:
You're right - it's better to make this a function that is called in the app. Also, if it's a function, I could make it so you could set the default to one of these templates, which would be very convenient when not using a theme switcher.
Next trick would be to make it possible to redraw the figure when the theme changes without updating the entire figure in a callback, but I think that would need a custom
Graph
component based ondcc.Graph
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.
Haha we convinced each other to swap places 🔀
Being able to set the default is really nice though, so this is great. I do have a slight preference for shortening the function name - could it just be
add_figure_templates
? It doesn't needmantine
in the name because it's already in thedash_mantine_components
package, and to my mind the key verb isadd
, ie add them to the Plotly options.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.
I agree, I wasn’t a fan of the name, but couldn’t think of a better one. I like your suggestion 🙂