Skip to content

Avoid dropping rendering commands #190

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/spatialdata_plot/pl/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def show(
]

# prepare rendering params
render_cmds = OrderedDict()
render_cmds = []
for cmd, params in plotting_tree.items():
# strip prefix from cmd and verify it's valid
cmd = "_".join(cmd.split("_")[1:])
Expand All @@ -577,9 +577,9 @@ def show(

if "render" in cmd:
# verify that rendering commands have been called before
render_cmds[cmd] = params
render_cmds.append((cmd, params))

if len(render_cmds.keys()) == 0:
if len(render_cmds) == 0:
raise TypeError("Please specify what to plot using the 'render_*' functions before calling 'imshow()'.")

if title is not None:
Expand Down Expand Up @@ -609,7 +609,7 @@ def show(
# Check if user specified only certain elements to be plotted
cs_contents = _get_cs_contents(sdata)
elements_to_be_rendered = []
for cmd, params in render_cmds.items():
for cmd, params in render_cmds:
if cmd == "render_images" and cs_contents.query(f"cs == '{cs}'")["has_images"][0]: # noqa: SIM114
if params.elements is not None:
elements_to_be_rendered += (
Expand All @@ -632,13 +632,14 @@ def show(
)

# filter out cs without relevant elements
cmds = [cmd for cmd, _ in render_cmds]
coordinate_systems = _get_valid_cs(
sdata=sdata,
coordinate_systems=coordinate_systems,
render_images="render_images" in render_cmds,
render_labels="render_labels" in render_cmds,
render_points="render_points" in render_cmds,
render_shapes="render_shapes" in render_cmds,
render_images="render_images" in cmds,
render_labels="render_labels" in cmds,
render_points="render_points" in cmds,
render_shapes="render_shapes" in cmds,
elements=elements_to_be_rendered,
)

Expand Down Expand Up @@ -689,7 +690,7 @@ def show(
wants_shapes = False
wanted_elements = []

for cmd, params in render_cmds.items():
for cmd, params in render_cmds:
if cmd == "render_images" and has_images:
wants_images = True
wanted_images = params.elements if params.elements is not None else list(sdata.images.keys())
Expand Down