@@ -1238,13 +1238,7 @@ def test_datashader_alpha_not_applied_twice(sdata_blobs: SpatialData):
12381238 ],
12391239)
12401240def test_datashader_respects_fill_alpha (sdata_blobs : SpatialData , fill_alpha : float , expected_max : int ):
1241- """Datashader must apply fill_alpha as a multiplicative scale on the rendered alpha.
1242-
1243- Regression test for https://github.com/scverse/spatialdata-plot/issues/617.
1244- Before the fix, ``fill_alpha`` was passed only as ``ds.tf.shade(min_alpha=...)``,
1245- which is a floor on alpha for non-empty pixels rather than a scaling factor, so
1246- shapes always rendered at alpha=255 regardless of ``fill_alpha`` (including 0.0).
1247- """
1241+ """fill_alpha must scale the rendered alpha channel linearly on the datashader path (#617)."""
12481242 fig , ax = plt .subplots ()
12491243 sdata_blobs .pl .render_shapes (
12501244 element = "blobs_polygons" ,
@@ -1264,20 +1258,14 @@ def test_datashader_respects_fill_alpha(sdata_blobs: SpatialData, fill_alpha: fl
12641258@pytest .mark .parametrize (
12651259 ("outline_alpha" , "expected_max" ),
12661260 [
1267- (0.0 , None ), # no outline image is rendered
1261+ (0.0 , None ),
12681262 (0.3 , 76 ),
12691263 (0.5 , 127 ),
12701264 (1.0 , 255 ),
12711265 ],
12721266)
12731267def test_datashader_respects_outline_alpha (sdata_blobs : SpatialData , outline_alpha : float , expected_max : int | None ):
1274- """Datashader must apply outline_alpha as a multiplicative scale on the rendered alpha.
1275-
1276- Regression test for https://github.com/scverse/spatialdata-plot/issues/617.
1277- Same root cause as fill_alpha: ``outline_alpha`` was passed only as
1278- ``ds.tf.shade(min_alpha=...)``, which is a floor on alpha for non-empty pixels,
1279- so outlines always rendered with max alpha=255 regardless of ``outline_alpha``.
1280- """
1268+ """outline_alpha must scale the outline image's alpha; alpha=0 must skip rendering entirely (#617)."""
12811269 fig , ax = plt .subplots ()
12821270 sdata_blobs .pl .render_shapes (
12831271 element = "blobs_polygons" ,
@@ -1289,18 +1277,16 @@ def test_datashader_respects_outline_alpha(sdata_blobs: SpatialData, outline_alp
12891277 fig .canvas .draw ()
12901278
12911279 axes_images = [c for c in ax .get_children () if isinstance (c , matplotlib .image .AxesImage )]
1292- # The outline is rendered red on top of the (gray) fill; pick the red one.
12931280 outline_imgs = [
12941281 img
12951282 for img in axes_images
12961283 if (arr := img .get_array ()).ndim == 3 and arr .shape [- 1 ] == 4 and arr [..., 0 ].max () > arr [..., 1 ].max ()
12971284 ]
12981285 if expected_max is None :
1299- assert not outline_imgs , "outline_alpha=0 should not render an outline image"
1286+ assert not outline_imgs
13001287 else :
1301- assert outline_imgs , "no outline AxesImage found"
1302- rgba = outline_imgs [0 ].get_array ()
1303- assert int (rgba [..., 3 ].max ()) == expected_max
1288+ assert outline_imgs
1289+ assert int (outline_imgs [0 ].get_array ()[..., 3 ].max ()) == expected_max
13041290 plt .close (fig )
13051291
13061292
0 commit comments