From e12dec508a9709293e999c7500f3415b6d0d1108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ars=C3=A8ne=20Duval?= Date: Sun, 1 Nov 2026 19:41:44 +0100 Subject: [PATCH] Fix colorscale inconsistencies in updatemenu buttons --- codegen/datatypes.py | 35 +++++++++++++++++++ .../graph_objs/layout/updatemenu/_button.py | 26 ++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/codegen/datatypes.py b/codegen/datatypes.py index 9c386992632..bb7bb8ff7e4 100644 --- a/codegen/datatypes.py +++ b/codegen/datatypes.py @@ -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") @@ -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() diff --git a/plotly/graph_objs/layout/updatemenu/_button.py b/plotly/graph_objs/layout/updatemenu/_button.py index 0c3830ff265..d70059f4a97 100644 --- a/plotly/graph_objs/layout/updatemenu/_button.py +++ b/plotly/graph_objs/layout/updatemenu/_button.py @@ -3,6 +3,7 @@ from plotly.basedatatypes import BaseLayoutHierarchyType as _BaseLayoutHierarchyType import copy as _copy +import plotly.colors as _pc class Button(_BaseLayoutHierarchyType): @@ -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)