"colorscale": { "description": "A Plotly colorscale either picked by a name: (any of Greys, YlGnBu, Greens, YlOrRd, Bluered, RdBu, Reds, Blues, Picnic, Rainbow, Portland, Jet, Hot, Blackbody, Earth, Electric, Viridi
| 1523 | |
| 1524 | |
| 1525 | class ColorscaleValidator(BaseValidator): |
| 1526 | """ |
| 1527 | "colorscale": { |
| 1528 | "description": "A Plotly colorscale either picked by a name: |
| 1529 | (any of Greys, YlGnBu, Greens, YlOrRd, Bluered, |
| 1530 | RdBu, Reds, Blues, Picnic, Rainbow, Portland, |
| 1531 | Jet, Hot, Blackbody, Earth, Electric, Viridis) |
| 1532 | customized as an {array} of 2-element {arrays} |
| 1533 | where the first element is the normalized color |
| 1534 | level value (starting at *0* and ending at *1*), |
| 1535 | and the second item is a valid color string.", |
| 1536 | "requiredOpts": [], |
| 1537 | "otherOpts": [ |
| 1538 | "dflt" |
| 1539 | ] |
| 1540 | }, |
| 1541 | """ |
| 1542 | |
| 1543 | def __init__(self, plotly_name, parent_name, **kwargs): |
| 1544 | super(ColorscaleValidator, self).__init__( |
| 1545 | plotly_name=plotly_name, parent_name=parent_name, **kwargs |
| 1546 | ) |
| 1547 | |
| 1548 | # named colorscales initialized on first use |
| 1549 | self._named_colorscales = None |
| 1550 | |
| 1551 | @property |
| 1552 | def named_colorscales(self): |
| 1553 | if self._named_colorscales is None: |
| 1554 | import inspect |
| 1555 | import itertools |
| 1556 | from plotly import colors |
| 1557 | |
| 1558 | colorscale_members = itertools.chain( |
| 1559 | inspect.getmembers(colors.sequential), |
| 1560 | inspect.getmembers(colors.diverging), |
| 1561 | inspect.getmembers(colors.cyclical), |
| 1562 | ) |
| 1563 | |
| 1564 | self._named_colorscales = { |
| 1565 | c[0].lower(): c[1] |
| 1566 | for c in colorscale_members |
| 1567 | if isinstance(c, tuple) |
| 1568 | and len(c) == 2 |
| 1569 | and isinstance(c[0], str) |
| 1570 | and isinstance(c[1], list) |
| 1571 | and not c[0].endswith("_r") |
| 1572 | and not c[0].startswith("_") |
| 1573 | } |
| 1574 | |
| 1575 | return self._named_colorscales |
| 1576 | |
| 1577 | def description(self): |
| 1578 | colorscales_str = "\n".join( |
| 1579 | textwrap.wrap( |
| 1580 | repr(sorted(list(self.named_colorscales))), |
| 1581 | initial_indent=" " * 12, |
| 1582 | subsequent_indent=" " * 13, |
no outgoing calls