Skip to content

add support for the _r convention to reverse colorscales #1681

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

Closed
nicolaskruchten opened this issue Jul 24, 2019 · 1 comment · Fixed by #1933
Closed

add support for the _r convention to reverse colorscales #1681

nicolaskruchten opened this issue Jul 24, 2019 · 1 comment · Fixed by #1933
Assignees
Milestone

Comments

@nicolaskruchten
Copy link
Contributor

...the way Matplotlib does it.

@jonmmease
Copy link
Contributor

jonmmease commented Jul 24, 2019

yeah, this would be great.

This would be handled in the ColorscaleValidator.validate_coerce, when processing string inputs...

def validate_coerce(self, v):
v_valid = False
if v is None:
v_valid = True
elif isinstance(v, string_types):
v_lower = v.lower()
if v_lower in self.named_colorscales:
# Convert to color list
v = self.named_colorscales[v_lower]
# Convert to list of lists colorscale
d = len(v) - 1
v = [[(1.0 * i) / (1.0 * d), x] for i, x in enumerate(v)]
v_valid = True

with something like

elif v_lower.endswith('_r') and v_lower[:-2] in self.named_colorscales:
    v = list(reversed(self.named_colorscales[v_lower[:-2]]))
    ...

And we would need to update the description (which is used for docstring and validation error messages) at

def description(self):
colorscales_str = "\n".join(
textwrap.wrap(
repr(sorted(list(self.named_colorscales))),
initial_indent=" " * 12,
subsequent_indent=" " * 13,
break_on_hyphens=False,
width=80,
)
)
desc = """\
The '{plotly_name}' property is a colorscale and may be
specified as:
- A list of colors that will be spaced evenly to create the colorscale.
Many predefined colorscale lists are included in the sequential, diverging,
and cyclical modules in the plotly.colors package.
- A list of 2-element lists where the first element is the
normalized color level value (starting at 0 and ending at 1),
and the second item is a valid color string.
(e.g. [[0, 'green'], [0.5, 'red'], [1.0, 'rgb(0, 0, 255)']])
- One of the following named colorscales:
{colorscales_str}
""".format(
plotly_name=self.plotly_name, colorscales_str=colorscales_str
)

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

Successfully merging a pull request may close this issue.

3 participants