Skip to content

Commit 3975cf1

Browse files
authored
Merge pull request #3 from lilyMaung/refactor/add_vrect
Refactor/add vrect
2 parents 22ee227 + 163067f commit 3975cf1

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

plotly/basedatatypes.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4218,6 +4218,71 @@ def _process_multiple_axis_spanning_shapes(
42184218
exclude_empty_subplots=exclude_empty_subplots,
42194219
**shape_to_add,
42204220
)
4221+
# Run legacy annotation logic
4222+
augmented_annotation = shapeannotation.axis_spanning_shape_annotation(
4223+
annotation,
4224+
shape_type,
4225+
shape_args,
4226+
legacy_ann, # now defined
4227+
)
4228+
4229+
if augmented_annotation is not None:
4230+
self.add_annotation(
4231+
augmented_annotation,
4232+
row=row,
4233+
col=col,
4234+
exclude_empty_subplots=exclude_empty_subplots,
4235+
yref=shape_kwargs.get("yref", "y"),
4236+
)
4237+
elif shape_type == "vrect":
4238+
# Split kwargs into shape vs legacy annotation_* (which we map to label)
4239+
shape_kwargs, legacy_ann = shapeannotation.split_dict_by_key_prefix(kwargs, "annotation_")
4240+
4241+
# Build/merge label dict: start with explicit label=..., then copy safe legacy fields
4242+
label_dict = (kwargs.get("label") or {}).copy()
4243+
if "annotation_text" in legacy_ann and "text" not in label_dict:
4244+
label_dict["text"] = legacy_ann["annotation_text"]
4245+
if "annotation_font" in legacy_ann and "font" not in label_dict:
4246+
label_dict["font"] = legacy_ann["annotation_font"]
4247+
if "annotation_textangle" in legacy_ann and "textangle" not in label_dict:
4248+
label_dict["textangle"] = legacy_ann["annotation_textangle"]
4249+
4250+
# NOTE: Label does not support bgcolor/bordercolor; keep emitting a warning when present
4251+
if "annotation_bgcolor" in legacy_ann or "annotation_bordercolor" in legacy_ann:
4252+
import warnings
4253+
warnings.warn(
4254+
"annotation_bgcolor/annotation_bordercolor are not supported on shape.label "
4255+
"and will be ignored; use label.font/color or a background shape instead.",
4256+
FutureWarning,
4257+
)
4258+
4259+
# Build the shape
4260+
shape_to_add = _combine_dicts([shape_args, shape_kwargs])
4261+
if label_dict:
4262+
shape_to_add["label"] = label_dict
4263+
4264+
# Add the shape
4265+
self.add_shape(
4266+
row=row,
4267+
col=col,
4268+
exclude_empty_subplots=exclude_empty_subplots,
4269+
**shape_to_add,
4270+
)
4271+
4272+
# Run legacy annotation logic only if an explicit annotation object was provided
4273+
augmented_annotation = shapeannotation.axis_spanning_shape_annotation(
4274+
annotation, shape_type, shape_args, legacy_ann
4275+
)
4276+
if augmented_annotation is not None:
4277+
self.add_annotation(
4278+
augmented_annotation,
4279+
row=row,
4280+
col=col,
4281+
exclude_empty_subplots=exclude_empty_subplots,
4282+
yref=shape_kwargs.get("yref", "y"),
4283+
)
4284+
4285+
)
42214286
else:
42224287

42234288
# shapes are always added at the end of the tuple of shapes, so we see
@@ -4341,6 +4406,9 @@ def add_vrect(
43414406
annotation=None,
43424407
**kwargs,
43434408
):
4409+
# NEW (Step 2): translate legacy annotation_* → label (non-destructive; warns if used)
4410+
kwargs = _coerce_shape_label_from_legacy_annotation_kwargs(kwargs)
4411+
43444412
self._process_multiple_axis_spanning_shapes(
43454413
dict(type="rect", x0=x0, x1=x1, y0=0, y1=1),
43464414
row,

0 commit comments

Comments
 (0)