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

Clean up PLOTLY_SCALES constant #3185

Closed
nicolaskruchten opened this issue May 6, 2021 · 7 comments
Closed

Clean up PLOTLY_SCALES constant #3185

nicolaskruchten opened this issue May 6, 2021 · 7 comments

Comments

@nicolaskruchten
Copy link
Contributor

Right now we declare this in colors and tools (not DRY!) and this is a case-sensitive list that doesn't include all the new scales that are accepted by the validators. This list is reimported in a few places downstream within our own library.

Note also: the docstring of ColorscaleValidator hardcodes an incomplete list of the keys of this list 🤯

I came across this while trying to use "viridis" as a scale name with a newly-added function that reused the patterns in colors: #3136

@CarlAndersson
Copy link
Contributor

This might not be the appropriate place to comment, feel free to ignore or remove this if so!

From the perspective of reusing existing patterns, it would be great if there was a "get colorscale by name" function which can be used with all the existing colorscales, builtin to the javascript package or from one of the colors namespaces. I assume that the functionality exists somewhere, since it's possible to pass just a name when creating a plot, but I couldn't find it...

@nicolaskruchten
Copy link
Contributor Author

Yeah that would be a much cleaner way forward. Unfortunately we've been exporting this one static object for a long time so there's probably a lot of downstream code that uses it. The way we can assign in a figure any colorscale by name, case-insensitively and with the _r option is handled here: https://github.com/plotly/plotly.py/blob/master/packages/python/plotly/_plotly_utils/basevalidators.py#L1529

We can probably populate PLOTLY_SCALES in a similar way via introspection, but that won't get us case-insensitivity. I wonder if using a custom dict type that ignores case when reading keys would do it, although I'm afraid that won't be very robust.

In the meantime, once I've merged your excellent #3136 PR, I was planning on modifying your function to accept any of the values that the ColorscaleValidator accepts (in a local way to that function, for expediency). If you want to make that change to your PR I'd be grateful but no pressure ;) That would allow us to pass in Plasma and plasma and Plasma_r as valid built-ins, which would be really nice.

@CarlAndersson
Copy link
Contributor

Soo, I implemented a "name, possibly capitalized, possibly reversed" to "actual colors" function. Should I create a new PR for it or just add it to #3136 ?
I did this inside the named_colorscales function with an optional argument. What's the take on dual purpose functions? Should I make it a separate function instead?

@nicolaskruchten
Copy link
Contributor Author

Let's make a new function in a new PR I think so I can take a look.

@nicolaskruchten
Copy link
Contributor Author

(and thanks!)

@CarlAndersson
Copy link
Contributor

CarlAndersson commented May 7, 2021

PR: #3186

@gvwilson
Copy link
Contributor

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants