Skip to content

Commit

Permalink
Rename add_image to add_layout_image to avoid conflict with future im…
Browse files Browse the repository at this point in the history
…age trace

Same for select/for_each/update.
  • Loading branch information
jonmmease committed Oct 15, 2019
1 parent 52ae979 commit fd0ae43
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
14 changes: 10 additions & 4 deletions packages/python/plotly/codegen/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
\"\"\"
Expand Down Expand Up @@ -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
):
\"\"\"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions packages/python/plotly/plotly/graph_objs/_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
):
"""
Expand Down Expand Up @@ -16462,7 +16464,7 @@ def update_images(

return self

def add_image(
def add_layout_image(
self,
arg=None,
layer=None,
Expand Down
10 changes: 6 additions & 4 deletions packages/python/plotly/plotly/graph_objs/_figurewidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
):
"""
Expand Down Expand Up @@ -16462,7 +16464,7 @@ def update_images(

return self

def add_image(
def add_layout_image(
self,
arg=None,
layer=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit fd0ae43

Please sign in to comment.