Skip to content

Commit a17e6a3

Browse files
emmanuellejonmmease
authored andcommitted
Reversed colorscale (#1933)
* reversed colorscales with _r * codegen
1 parent 151b63d commit a17e6a3

File tree

47 files changed

+208
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+208
-57
lines changed

packages/python/plotly/_plotly_utils/basevalidators.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,8 @@ def named_colorscales(self):
15321532
and len(c) == 2
15331533
and isinstance(c[0], str)
15341534
and isinstance(c[1], list)
1535+
and not c[0].endswith("_r")
1536+
and not c[0].startswith("_")
15351537
}
15361538

15371539
return self._named_colorscales
@@ -1558,7 +1560,8 @@ def description(self):
15581560
and the second item is a valid color string.
15591561
(e.g. [[0, 'green'], [0.5, 'red'], [1.0, 'rgb(0, 0, 255)']])
15601562
- One of the following named colorscales:
1561-
{colorscales_str}
1563+
{colorscales_str}.
1564+
Appending '_r' to a named colorscale reverses it.
15621565
""".format(
15631566
plotly_name=self.plotly_name, colorscales_str=colorscales_str
15641567
)
@@ -1575,13 +1578,16 @@ def validate_coerce(self, v):
15751578
if v_lower in self.named_colorscales:
15761579
# Convert to color list
15771580
v = self.named_colorscales[v_lower]
1578-
1581+
v_valid = True
1582+
elif v_lower.endswith("_r") and v_lower[:-2] in self.named_colorscales:
1583+
v = self.named_colorscales[v_lower[:-2]][::-1]
1584+
v_valid = True
1585+
#
1586+
if v_valid:
15791587
# Convert to list of lists colorscale
15801588
d = len(v) - 1
15811589
v = [[(1.0 * i) / (1.0 * d), x] for i, x in enumerate(v)]
15821590

1583-
v_valid = True
1584-
15851591
elif is_array(v) and len(v) > 0:
15861592
# If firset element is a string, treat as colorsequence
15871593
if isinstance(v[0], string_types):

packages/python/plotly/_plotly_utils/colors/_swatches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _swatches(module_names, module_contents, template=None):
2020
sequences = [
2121
(k, v)
2222
for k, v in module_contents.items()
23-
if not (k.startswith("_") or k == "swatches")
23+
if not (k.startswith("_") or k == "swatches" or k.endswith("_r"))
2424
]
2525

2626
return go.Figure(

packages/python/plotly/_plotly_utils/colors/carto.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,10 @@ def swatches(template=None):
382382
"rgb(237, 100, 90)",
383383
"rgb(165, 170, 153)",
384384
]
385+
386+
# Prefix variable names with _ so that they will not be added to the swatches
387+
_contents = dict(globals())
388+
for _k, _cols in _contents.items():
389+
if _k.startswith("_") or _k == "swatches" or _k.endswith("_r"):
390+
continue
391+
globals()[_k + "_r"] = _cols[::-1]

packages/python/plotly/_plotly_utils/colors/cmocean.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,10 @@ def swatches(template=None):
267267
"rgb(111, 23, 91)",
268268
"rgb(51, 13, 53)",
269269
]
270+
271+
# Prefix variable names with _ so that they will not be added to the swatches
272+
_contents = dict(globals())
273+
for _k, _cols in _contents.items():
274+
if _k.startswith("_") or _k == "swatches" or _k.endswith("_r"):
275+
continue
276+
globals()[_k + "_r"] = _cols[::-1]

packages/python/plotly/_plotly_utils/colors/colorbrewer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,10 @@ def swatches(template=None):
456456
"rgb(189,0,38)",
457457
"rgb(128,0,38)",
458458
]
459+
460+
# Prefix variable names with _ so that they will not be added to the swatches
461+
_contents = dict(globals())
462+
for _k, _cols in _contents.items():
463+
if _k.startswith("_") or _k == "swatches" or _k.endswith("_r"):
464+
continue
465+
globals()[_k + "_r"] = _cols[::-1]

packages/python/plotly/_plotly_utils/colors/cyclical.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,10 @@ def swatches(template=None):
125125
"#9139fa",
126126
"#c543fa",
127127
]
128+
129+
# Prefix variable names with _ so that they will not be added to the swatches
130+
_contents = dict(globals())
131+
for _k, _cols in _contents.items():
132+
if _k.startswith("_") or _k == "swatches" or _k.endswith("_r"):
133+
continue
134+
globals()[_k + "_r"] = _cols[::-1]

packages/python/plotly/_plotly_utils/colors/diverging.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@ def swatches(template=None):
3030

3131

3232
swatches.__doc__ = _swatches.__doc__
33+
34+
# Prefix variable names with _ so that they will not be added to the swatches
35+
_contents = dict(globals())
36+
for _k, _cols in _contents.items():
37+
if _k.startswith("_") or _k == "swatches" or _k.endswith("_r"):
38+
continue
39+
globals()[_k + "_r"] = _cols[::-1]

packages/python/plotly/_plotly_utils/colors/plotlyjs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,10 @@
179179
scale_name=scale_name, scale_sequence=scale_sequence
180180
)
181181
)
182+
183+
# Prefix variable names with _ so that they will not be added to the swatches
184+
_contents = dict(globals())
185+
for _k, _cols in _contents.items():
186+
if _k.startswith("_") or _k == "swatches" or _k.endswith("_r"):
187+
continue
188+
globals()[_k + "_r"] = _cols[::-1]

packages/python/plotly/_plotly_utils/colors/qualitative.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,10 @@ def swatches(template=None):
145145

146146
from .colorbrewer import Set1, Pastel1, Dark2, Set2, Pastel2, Set3 # noqa: F401
147147
from .carto import Antique, Bold, Pastel, Prism, Safe, Vivid # noqa: F401
148+
149+
# Prefix variable names with _ so that they will not be added to the swatches
150+
_contents = dict(globals())
151+
for _k, _cols in _contents.items():
152+
if _k.startswith("_") or _k == "swatches" or _k.endswith("_r"):
153+
continue
154+
globals()[_k + "_r"] = _cols[::-1]

packages/python/plotly/_plotly_utils/colors/sequential.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,10 @@ def swatches(template=None):
155155
Agsunset,
156156
Brwnyl,
157157
)
158+
159+
# Prefix variable names with _ so that they will not be added to the swatches
160+
_contents = dict(globals())
161+
for _k, _cols in _contents.items():
162+
if _k.startswith("_") or _k == "swatches" or _k.endswith("_r"):
163+
continue
164+
globals()[_k + "_r"] = _cols[::-1]

0 commit comments

Comments
 (0)