From fd0ae43aefb6939c9d8181f09ed4e82c38994076 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Tue, 15 Oct 2019 08:52:49 -0400 Subject: [PATCH] Rename add_image to add_layout_image to avoid conflict with future image trace Same for select/for_each/update. --- packages/python/plotly/codegen/figure.py | 14 +++++--- .../plotly/plotly/graph_objs/_figure.py | 10 +++--- .../plotly/plotly/graph_objs/_figurewidget.py | 10 +++--- .../test_update_annotations.py | 32 ++++++++++--------- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/packages/python/plotly/codegen/figure.py b/packages/python/plotly/codegen/figure.py index 5b1d9bbb04..034145c01f 100644 --- a/packages/python/plotly/codegen/figure.py +++ b/packages/python/plotly/codegen/figure.py @@ -364,9 +364,15 @@ def update_{plural_name}( singular_name = node.plotly_name plural_name = node.name_property + if singular_name == "image": + # Rename image to layout_image to avoid conflict with an image trace + method_prefix = "layout_" + else: + method_prefix = "" + buffer.write( f""" - def select_{plural_name}( + def select_{method_prefix}{plural_name}( self, selector=None, row=None, col=None, secondary_y=None ): \"\"\" @@ -409,7 +415,7 @@ def select_{plural_name}( "{plural_name}", selector=selector, row=row, col=col, secondary_y=secondary_y ) - def for_each_{singular_name}( + def for_each_{method_prefix}{singular_name}( self, fn, selector=None, row=None, col=None, secondary_y=None ): \"\"\" @@ -460,7 +466,7 @@ def for_each_{singular_name}( return self - def update_{plural_name}( + def update_{method_prefix}{plural_name}( self, patch, selector=None, @@ -527,7 +533,7 @@ def update_{plural_name}( # Add layout array items buffer.write( f""" - def add_{singular_name}(self""" + def add_{method_prefix}{singular_name}(self""" ) add_constructor_params( buffer, diff --git a/packages/python/plotly/plotly/graph_objs/_figure.py b/packages/python/plotly/plotly/graph_objs/_figure.py index 418c022dde..e037b75363 100644 --- a/packages/python/plotly/plotly/graph_objs/_figure.py +++ b/packages/python/plotly/plotly/graph_objs/_figure.py @@ -16323,7 +16323,7 @@ def add_annotation( secondary_y=secondary_y, ) - def select_images(self, selector=None, row=None, col=None, secondary_y=None): + def select_layout_images(self, selector=None, row=None, col=None, secondary_y=None): """ Select images from a particular subplot cell and/or images that satisfy custom selection criteria. @@ -16364,7 +16364,9 @@ def select_images(self, selector=None, row=None, col=None, secondary_y=None): "images", selector=selector, row=row, col=col, secondary_y=secondary_y ) - def for_each_image(self, fn, selector=None, row=None, col=None, secondary_y=None): + def for_each_layout_image( + self, fn, selector=None, row=None, col=None, secondary_y=None + ): """ Apply a function to all images that satisfy the specified selection criteria @@ -16409,7 +16411,7 @@ def for_each_image(self, fn, selector=None, row=None, col=None, secondary_y=None return self - def update_images( + def update_layout_images( self, patch, selector=None, row=None, col=None, secondary_y=None, **kwargs ): """ @@ -16462,7 +16464,7 @@ def update_images( return self - def add_image( + def add_layout_image( self, arg=None, layer=None, diff --git a/packages/python/plotly/plotly/graph_objs/_figurewidget.py b/packages/python/plotly/plotly/graph_objs/_figurewidget.py index 0774628c4b..9e878b5c10 100644 --- a/packages/python/plotly/plotly/graph_objs/_figurewidget.py +++ b/packages/python/plotly/plotly/graph_objs/_figurewidget.py @@ -16323,7 +16323,7 @@ def add_annotation( secondary_y=secondary_y, ) - def select_images(self, selector=None, row=None, col=None, secondary_y=None): + def select_layout_images(self, selector=None, row=None, col=None, secondary_y=None): """ Select images from a particular subplot cell and/or images that satisfy custom selection criteria. @@ -16364,7 +16364,9 @@ def select_images(self, selector=None, row=None, col=None, secondary_y=None): "images", selector=selector, row=row, col=col, secondary_y=secondary_y ) - def for_each_image(self, fn, selector=None, row=None, col=None, secondary_y=None): + def for_each_layout_image( + self, fn, selector=None, row=None, col=None, secondary_y=None + ): """ Apply a function to all images that satisfy the specified selection criteria @@ -16409,7 +16411,7 @@ def for_each_image(self, fn, selector=None, row=None, col=None, secondary_y=None return self - def update_images( + def update_layout_images( self, patch, selector=None, row=None, col=None, secondary_y=None, **kwargs ): """ @@ -16462,7 +16464,7 @@ def update_images( return self - def add_image( + def add_layout_image( self, arg=None, layer=None, diff --git a/packages/python/plotly/plotly/tests/test_core/test_update_objects/test_update_annotations.py b/packages/python/plotly/plotly/tests/test_core/test_update_objects/test_update_annotations.py index 3e81debd1a..beb02e4800 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_update_objects/test_update_annotations.py +++ b/packages/python/plotly/plotly/tests/test_core/test_update_objects/test_update_annotations.py @@ -18,7 +18,8 @@ def assert_selected( ): # ## Test select_* # Get select_ method - fn = getattr(self.fig, "select_" + prop) + prefix = "layout_" if prop == "images" else "" + fn = getattr(self.fig, "select_" + prefix + prop) # Perform selection res = fn(selector=selector, row=row, col=col, secondary_y=secondary_y) @@ -34,7 +35,7 @@ def assert_selected( # ## Test for_each_* objs = [] - fn = getattr(self.fig, "for_each_" + prop[:-1]) + fn = getattr(self.fig, "for_each_" + prefix + prop[:-1]) fn( lambda v: objs.append(v), selector=selector, @@ -50,9 +51,10 @@ def assert_update( self, prop, inds, patch, selector=None, row=None, col=None, secondary_y=None ): # Copy figure and perform update + prefix = "layout_" if prop == "images" else "" fig_orig = go.Figure(self.fig) fig = go.Figure(self.fig) - fn = getattr(fig, "update_" + prop) + fn = getattr(fig, "update_" + prefix + prop) fn(patch, selector=selector, row=row, col=col, secondary_y=secondary_y) # Get original up updated object lis @@ -172,12 +174,12 @@ def test_select_shapes(self): def test_select_images(self): ( - self.fig.add_image(opacity=0.1, source="red") - .add_image(opacity=0.2, source="blue") - .add_image(opacity=0.3, source="red", row=1, col=1) - .add_image(opacity=0.4, row=1, col=2) - .add_image(opacity=0.5, row=1, col=2, secondary_y=True) - .add_image(opacity=0.6, source="blue", row=2, col=1) + self.fig.add_layout_image(opacity=0.1, source="red") + .add_layout_image(opacity=0.2, source="blue") + .add_layout_image(opacity=0.3, source="red", row=1, col=1) + .add_layout_image(opacity=0.4, row=1, col=2) + .add_layout_image(opacity=0.5, row=1, col=2, secondary_y=True) + .add_layout_image(opacity=0.6, source="blue", row=2, col=1) ) # Test selections @@ -233,12 +235,12 @@ def test_update_shapes(self): def test_update_images(self): ( - self.fig.add_image(opacity=0.1, source="red") - .add_image(opacity=0.2, source="blue") - .add_image(opacity=0.3, source="red", row=1, col=1) - .add_image(opacity=0.4, row=1, col=2) - .add_image(opacity=0.5, row=1, col=2, secondary_y=True) - .add_image(opacity=0.6, source="blue", row=2, col=1) + self.fig.add_layout_image(opacity=0.1, source="red") + .add_layout_image(opacity=0.2, source="blue") + .add_layout_image(opacity=0.3, source="red", row=1, col=1) + .add_layout_image(opacity=0.4, row=1, col=2) + .add_layout_image(opacity=0.5, row=1, col=2, secondary_y=True) + .add_layout_image(opacity=0.6, source="blue", row=2, col=1) ) self.assert_update("images", [0, 1, 2, 3, 4, 5], patch=dict(opacity=0))