Skip to content

Convert string titles in updatemenu and slider args to title.text - #5808

Open
bhaskargurram-ai wants to merge 1 commit into
plotly:mainfrom
bhaskargurram-ai:fix/updatemenu-string-titles
Open

bhaskargurram-ai wants to merge 1 commit into
plotly:mainfrom
bhaskargurram-ai:fix/updatemenu-string-titles

Conversation

@bhaskargurram-ai

Copy link
Copy Markdown

Link to issue

Closes #5032

Likely also addresses #5060 (same symptom: the title disappears after clicking a button since 6.0).

Description of change

Since plotly.js 3 (bundled from plotly.py 6.0), passing a string to a title attribute is no longer supported (plotly/plotly.js#7212). Figure properties are fine because TitleValidator maps strings to title.text, but the args of updatemenu buttons and slider steps are passed to Plotly.relayout/restyle/update verbatim, so a button with e.g. {"xaxis.title": "Time"} or {"xaxis": {"title": "Time"}} makes the title disappear.

This PR adds a MethodArgsValidator (used for layout.updatemenu.button.args, args2 and layout.slider.step.args via CUSTOM_VALIDATOR_DATATYPES in codegen) which converts plain string/number title values in these args:

  • top-level attribute paths: {"xaxis.title": "Time"} -> {"xaxis.title.text": "Time"}. Like plotly.js < 3 did, this only updates the text and keeps other title properties such as the font.
  • nested containers: {"xaxis": {"title": "Time"}} -> {"xaxis": {"title": {"text": "Time"}}}

Values that are already objects, title.text keys, other string properties and non-dict args (e.g. animation frame names) are left untouched, and the user's dicts are not mutated.

Demo

Clicking the buttons of a figure built with plotly.py, rendered with the bundled plotly.js 4.1.1:

before after
button relayout {"title": "Dotted", "xaxis.title": "x dotted", "yaxis.title": "y dotted"} title, x and y titles disappear "Dotted" / "x dotted" / "y dotted" (x title keeps its font)
button update [..., {"xaxis": {"title": "x nested"}, ...}] titles disappear "x nested" / "y nested"
slider step relayout {"xaxis.title": "x slider"} title disappears "x slider"

Testing strategy

Added tests/test_plotly_utils/validators/test_methodargs_validator.py (validator unit tests: coerced forms, forms left unchanged, no input mutation) and tests/test_core/test_graph_objs/test_method_args.py (serialized figure JSON for updatemenu args/args2, update args and slider steps). The string-title cases fail on main and pass with this change; existing validator/graph_objs/figure_messages tests are unchanged. plotly/validators/_validators.json was regenerated from codegen.

Guidelines

Plotly.js 3 dropped support for passing a string to title attributes.
Figure properties are coerced by TitleValidator, but the args of
updatemenu buttons and slider steps are passed to Plotly.js verbatim, so
buttons setting e.g. {"xaxis.title": "Time"} made the title disappear.

Add a MethodArgsValidator for layout.updatemenu.button.args/args2 and
layout.slider.step.args which maps such values to title.text.

Fixes plotly#5032

This branch has not been deployed

No deployments
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 this pull request may close these issues.

axis label change via updatemenus not working anymore in 6.0.0

1 participant