Skip to content

Commit 10c131e

Browse files
timtreisclaude
andcommitted
Fix inverted transfunc condition in render_shapes; add transfunc support to render_labels
The guard in _render_shapes was `if values_are_categorical` instead of `if not values_are_categorical`, causing transfunc to be silently ignored for continuous data and to crash with a TypeError for categorical data. render_labels had no transfunc support at all. Added the field to LabelsRenderParams, wired it through basic.py, and applied the same guard already present in _render_points. Fixes #596. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 525c94a commit 10c131e

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/spatialdata_plot/pl/basic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@ def render_labels(
854854
scale=param_values["scale"],
855855
table_name=param_values["table_name"],
856856
table_layer=param_values["table_layer"],
857+
transfunc=kwargs.get("transfunc"),
857858
zorder=n_steps,
858859
colorbar=param_values["colorbar"],
859860
colorbar_params=param_values["colorbar_params"],

src/spatialdata_plot/pl/render.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def _render_shapes(
402402
sdata_filt[element] = shapes
403403

404404
# color_source_vector is None when the values aren't categorical
405-
if values_are_categorical and render_params.transfunc is not None:
405+
if not values_are_categorical and render_params.transfunc is not None:
406406
color_vector = render_params.transfunc(color_vector)
407407

408408
norm = copy(render_params.cmap_params.norm)
@@ -1702,6 +1702,10 @@ def _render_labels(
17021702
if isinstance(color_vector.dtype, pd.CategoricalDtype):
17031703
color_vector = color_vector.remove_unused_categories()
17041704

1705+
# color_source_vector is None when the values aren't categorical
1706+
if color_source_vector is None and render_params.transfunc is not None:
1707+
color_vector = render_params.transfunc(color_vector)
1708+
17051709
def _draw_labels(
17061710
seg_erosionpx: int | None,
17071711
seg_boundaries: bool,

src/spatialdata_plot/pl/render_params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ class LabelsRenderParams:
304304
scale: str | None = None
305305
table_name: str | None = None
306306
table_layer: str | None = None
307+
transfunc: Callable[[float], float] | None = None
307308
zorder: int = 0
308309
colorbar: bool | str | None = "auto"
309310
colorbar_params: dict[str, object] | None = None

0 commit comments

Comments
 (0)