Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Refactor autoshapes to use shape.label for vline/hline/vrect/hrect#5444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
nochinxx wants to merge17 commits intoplotly:mainChoose a base branch fromlilyMaung:refactor/autoshapes-use-shape-label
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+475 −39
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
…el_from_legacy_annotation_kwargs(kwargs) to format kwargs into shape.label
…bel (prep for shape.label refactor)
…position normalizer-refactor(vline): emit a single labeled shape; map legacy annotation_position to label.textposition
Fixes error in vline related to shape label instead of annotations
…notation positions to the shape’s label.textposition.
Refactor/add vrect
Migrate add_hrect from annotation to shape/label
Member
ndrezn commentedDec 10, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Wow, fantastic PR! This is an exciting refactor and would be a great add to Plotly.py. Let us know when you need help reviewing. |
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is a first step toward refactoring the autoshape helpers to use the new
layout.shape.labelAPI in Plotly.js, while keeping backward-compatible annotation behavior for now.Scope
This PR updates:
Figure.add_vlineFigure.add_hlineFigure.add_vrectFigure.add_hrectKey changes:
Legacy → label shim
_coerce_shape_label_from_legacy_annotation_kwargs(kwargs)to translate a safe subset ofannotation_*kwargs into alabeldict:annotation_text→label.textannotation_font→label.fontannotation_textangle→label.textangleannotation_*from kwargs.annotation_*field is used, aFutureWarningis emitted to encourage migrating tolabel={...}.Add shape.label for autoshapes
In
_process_multiple_axis_spanning_shapes, forshape_typein:"vline""hline""vrect""hrect"we now:
shape_kwargsandlegacy_annviashapeannotation.split_dict_by_key_prefix(..., "annotation_").label_dictstarting from any explicitlabelpassed by the user and then merging in legacy fields if they are not present.label_dictto the new shape (shape_to_add["label"] = label_dict) before callingadd_shape(...).Mapping annotation_position → label.textposition
We partially map
annotation_positionintolabel.textpositionto keep intuitive placement:Forlines:
vline:"top"→"end""bottom"→"start""middle"/"center"→"middle"hline:"right"→"end""left"→"start""middle"/"center"→"middle"_normalize_legacy_line_position_to_textpositionis used to validate legacy strings and to keep behavior predictable.Forrectangles (
vrect,hrect):"inside "/"outside "and map the remaining part to a valid rect textposition:"top left","top center","top right", …"middle left","middle center","middle right", …"bottom left","bottom center","bottom right", …"top","bottom","left","right"are mapped to sensible defaults (e.g."top"→"top center").Warnings for unsupported styling
annotation_bgcolor/annotation_bordercolorarenot supported onshape.labeland are currently ignored with aFutureWarningsuggesting use of label font/color or a background shape instead.Backward compatibility (important)
axis_spanning_shape_annotation(...)is still called.add_annotation(...)is still called whenaugmented_annotationis notNone.layout.annotationscontinues to work,label, which will allow us to stop creating separate annotations in a later step.Bug / motivation
This work is motivated by the issue where using
add_vlinewithannotation_texton a datetime x-axis can raise aTypeErrordue to arithmetic on mixed types when positioning the annotation (see the discussion in#3065).By moving toward
shape.label:For now, we keep the annotation logic in place to avoid breaking existing behavior while we gather feedback.
Tests
Locally, I ran: