Skip to content

Commit fd0ae43

Browse files
committed
Rename add_image to add_layout_image to avoid conflict with future image trace
Same for select/for_each/update.
1 parent 52ae979 commit fd0ae43

File tree

4 files changed

+39
-27
lines changed

4 files changed

+39
-27
lines changed

Diff for: packages/python/plotly/codegen/figure.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,15 @@ def update_{plural_name}(
364364
singular_name = node.plotly_name
365365
plural_name = node.name_property
366366

367+
if singular_name == "image":
368+
# Rename image to layout_image to avoid conflict with an image trace
369+
method_prefix = "layout_"
370+
else:
371+
method_prefix = ""
372+
367373
buffer.write(
368374
f"""
369-
def select_{plural_name}(
375+
def select_{method_prefix}{plural_name}(
370376
self, selector=None, row=None, col=None, secondary_y=None
371377
):
372378
\"\"\"
@@ -409,7 +415,7 @@ def select_{plural_name}(
409415
"{plural_name}", selector=selector, row=row, col=col, secondary_y=secondary_y
410416
)
411417
412-
def for_each_{singular_name}(
418+
def for_each_{method_prefix}{singular_name}(
413419
self, fn, selector=None, row=None, col=None, secondary_y=None
414420
):
415421
\"\"\"
@@ -460,7 +466,7 @@ def for_each_{singular_name}(
460466
461467
return self
462468
463-
def update_{plural_name}(
469+
def update_{method_prefix}{plural_name}(
464470
self,
465471
patch,
466472
selector=None,
@@ -527,7 +533,7 @@ def update_{plural_name}(
527533
# Add layout array items
528534
buffer.write(
529535
f"""
530-
def add_{singular_name}(self"""
536+
def add_{method_prefix}{singular_name}(self"""
531537
)
532538
add_constructor_params(
533539
buffer,

Diff for: packages/python/plotly/plotly/graph_objs/_figure.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -16323,7 +16323,7 @@ def add_annotation(
1632316323
secondary_y=secondary_y,
1632416324
)
1632516325

16326-
def select_images(self, selector=None, row=None, col=None, secondary_y=None):
16326+
def select_layout_images(self, selector=None, row=None, col=None, secondary_y=None):
1632716327
"""
1632816328
Select images from a particular subplot cell and/or images
1632916329
that satisfy custom selection criteria.
@@ -16364,7 +16364,9 @@ def select_images(self, selector=None, row=None, col=None, secondary_y=None):
1636416364
"images", selector=selector, row=row, col=col, secondary_y=secondary_y
1636516365
)
1636616366

16367-
def for_each_image(self, fn, selector=None, row=None, col=None, secondary_y=None):
16367+
def for_each_layout_image(
16368+
self, fn, selector=None, row=None, col=None, secondary_y=None
16369+
):
1636816370
"""
1636916371
Apply a function to all images that satisfy the specified selection
1637016372
criteria
@@ -16409,7 +16411,7 @@ def for_each_image(self, fn, selector=None, row=None, col=None, secondary_y=None
1640916411

1641016412
return self
1641116413

16412-
def update_images(
16414+
def update_layout_images(
1641316415
self, patch, selector=None, row=None, col=None, secondary_y=None, **kwargs
1641416416
):
1641516417
"""
@@ -16462,7 +16464,7 @@ def update_images(
1646216464

1646316465
return self
1646416466

16465-
def add_image(
16467+
def add_layout_image(
1646616468
self,
1646716469
arg=None,
1646816470
layer=None,

Diff for: packages/python/plotly/plotly/graph_objs/_figurewidget.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -16323,7 +16323,7 @@ def add_annotation(
1632316323
secondary_y=secondary_y,
1632416324
)
1632516325

16326-
def select_images(self, selector=None, row=None, col=None, secondary_y=None):
16326+
def select_layout_images(self, selector=None, row=None, col=None, secondary_y=None):
1632716327
"""
1632816328
Select images from a particular subplot cell and/or images
1632916329
that satisfy custom selection criteria.
@@ -16364,7 +16364,9 @@ def select_images(self, selector=None, row=None, col=None, secondary_y=None):
1636416364
"images", selector=selector, row=row, col=col, secondary_y=secondary_y
1636516365
)
1636616366

16367-
def for_each_image(self, fn, selector=None, row=None, col=None, secondary_y=None):
16367+
def for_each_layout_image(
16368+
self, fn, selector=None, row=None, col=None, secondary_y=None
16369+
):
1636816370
"""
1636916371
Apply a function to all images that satisfy the specified selection
1637016372
criteria
@@ -16409,7 +16411,7 @@ def for_each_image(self, fn, selector=None, row=None, col=None, secondary_y=None
1640916411

1641016412
return self
1641116413

16412-
def update_images(
16414+
def update_layout_images(
1641316415
self, patch, selector=None, row=None, col=None, secondary_y=None, **kwargs
1641416416
):
1641516417
"""
@@ -16462,7 +16464,7 @@ def update_images(
1646216464

1646316465
return self
1646416466

16465-
def add_image(
16467+
def add_layout_image(
1646616468
self,
1646716469
arg=None,
1646816470
layer=None,

Diff for: packages/python/plotly/plotly/tests/test_core/test_update_objects/test_update_annotations.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def assert_selected(
1818
):
1919
# ## Test select_*
2020
# Get select_ method
21-
fn = getattr(self.fig, "select_" + prop)
21+
prefix = "layout_" if prop == "images" else ""
22+
fn = getattr(self.fig, "select_" + prefix + prop)
2223

2324
# Perform selection
2425
res = fn(selector=selector, row=row, col=col, secondary_y=secondary_y)
@@ -34,7 +35,7 @@ def assert_selected(
3435

3536
# ## Test for_each_*
3637
objs = []
37-
fn = getattr(self.fig, "for_each_" + prop[:-1])
38+
fn = getattr(self.fig, "for_each_" + prefix + prop[:-1])
3839
fn(
3940
lambda v: objs.append(v),
4041
selector=selector,
@@ -50,9 +51,10 @@ def assert_update(
5051
self, prop, inds, patch, selector=None, row=None, col=None, secondary_y=None
5152
):
5253
# Copy figure and perform update
54+
prefix = "layout_" if prop == "images" else ""
5355
fig_orig = go.Figure(self.fig)
5456
fig = go.Figure(self.fig)
55-
fn = getattr(fig, "update_" + prop)
57+
fn = getattr(fig, "update_" + prefix + prop)
5658
fn(patch, selector=selector, row=row, col=col, secondary_y=secondary_y)
5759

5860
# Get original up updated object lis
@@ -172,12 +174,12 @@ def test_select_shapes(self):
172174

173175
def test_select_images(self):
174176
(
175-
self.fig.add_image(opacity=0.1, source="red")
176-
.add_image(opacity=0.2, source="blue")
177-
.add_image(opacity=0.3, source="red", row=1, col=1)
178-
.add_image(opacity=0.4, row=1, col=2)
179-
.add_image(opacity=0.5, row=1, col=2, secondary_y=True)
180-
.add_image(opacity=0.6, source="blue", row=2, col=1)
177+
self.fig.add_layout_image(opacity=0.1, source="red")
178+
.add_layout_image(opacity=0.2, source="blue")
179+
.add_layout_image(opacity=0.3, source="red", row=1, col=1)
180+
.add_layout_image(opacity=0.4, row=1, col=2)
181+
.add_layout_image(opacity=0.5, row=1, col=2, secondary_y=True)
182+
.add_layout_image(opacity=0.6, source="blue", row=2, col=1)
181183
)
182184

183185
# Test selections
@@ -233,12 +235,12 @@ def test_update_shapes(self):
233235

234236
def test_update_images(self):
235237
(
236-
self.fig.add_image(opacity=0.1, source="red")
237-
.add_image(opacity=0.2, source="blue")
238-
.add_image(opacity=0.3, source="red", row=1, col=1)
239-
.add_image(opacity=0.4, row=1, col=2)
240-
.add_image(opacity=0.5, row=1, col=2, secondary_y=True)
241-
.add_image(opacity=0.6, source="blue", row=2, col=1)
238+
self.fig.add_layout_image(opacity=0.1, source="red")
239+
.add_layout_image(opacity=0.2, source="blue")
240+
.add_layout_image(opacity=0.3, source="red", row=1, col=1)
241+
.add_layout_image(opacity=0.4, row=1, col=2)
242+
.add_layout_image(opacity=0.5, row=1, col=2, secondary_y=True)
243+
.add_layout_image(opacity=0.6, source="blue", row=2, col=1)
242244
)
243245

244246
self.assert_update("images", [0, 1, 2, 3, 4, 5], patch=dict(opacity=0))

0 commit comments

Comments
 (0)