Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions codegen/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def build_datatype_py(node):
)
buffer.write("import copy as _copy\n")

if node.path_str == "layout.updatemenu.button":
buffer.write("import plotly.colors as _pc\n")

if node.name_property == "template":
buffer.write("import warnings\n")

Expand Down Expand Up @@ -367,6 +370,38 @@ def __init__(self"""
self._skip_invalid = False
"""
)

if node.path_str == "layout.updatemenu.button":
buffer.write(
"""
if self.method in ("restyle", "update"):
def normalize_args(args):
if not isinstance(args, (list, tuple)) or not args:
return args

if not isinstance(args[0], dict):
return args

changes = args[0].copy()
scale = changes.get("colorscale")

if isinstance(scale, str):
if scale.lower() in _pc.named_colorscales():
changes["colorscale"] = [
_pc.get_colorscale(scale)
]
return [changes, *args[1:]]

return args

if self.args is not None:
self.args = normalize_args(self.args)

if self.args2 is not None:
self.args2 = normalize_args(self.args2)
"""
)


# Return source string
return buffer.getvalue()
Expand Down
26 changes: 26 additions & 0 deletions plotly/graph_objs/layout/updatemenu/_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from plotly.basedatatypes import BaseLayoutHierarchyType as _BaseLayoutHierarchyType
import copy as _copy
import plotly.colors as _pc


class Button(_BaseLayoutHierarchyType):
Expand Down Expand Up @@ -357,3 +358,28 @@ def __init__(
self._set_property("visible", arg, visible)
self._process_kwargs(**dict(arg, **kwargs))
self._skip_invalid = False

if self.method in ("restyle", "update"):

def normalize_args(args):
if not isinstance(args, (list, tuple)) or not args:
return args

if not isinstance(args[0], dict):
return args

changes = args[0].copy()
scale = changes.get("colorscale")

if isinstance(scale, str):
if scale.lower() in _pc.named_colorscales():
changes["colorscale"] = [_pc.get_colorscale(scale)]
return [changes, *args[1:]]

return args

if self.args is not None:
self.args = normalize_args(self.args)

if self.args2 is not None:
self.args2 = normalize_args(self.args2)