Skip to content

Commit c3cd50a

Browse files
committed
hotfix annotations
1 parent 885b5fa commit c3cd50a

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/napari_spatialdata/_viewer.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ def _write_element_to_disk(
161161
element: tuple[DaskDataFrame | GeoDataFrame | AnnData],
162162
overwrite: bool,
163163
) -> None:
164-
if sdata.is_backed:
165-
self._delete_from_disk(sdata, element_name, overwrite)
166-
sdata[element_name] = element
167-
sdata.write_element(element_name)
168-
else:
169-
sdata[element_name] = element
170-
logger.warning("Spatialdata object is not stored on disk, could only add element in memory.")
164+
# if sdata.is_backed:
165+
# self._delete_from_disk(sdata, element_name, overwrite)
166+
# sdata[element_name] = element
167+
# sdata.write_element(element_name)
168+
# else:
169+
sdata[element_name] = element
170+
logger.warning("Annotations only added in memory, please manually save to disk.")
171171

172172
def _save_points_to_sdata(
173173
self, layer_to_save: Points, spatial_element_name: str | None, overwrite: bool
@@ -187,6 +187,8 @@ def _save_points_to_sdata(
187187
swap_data = swap_data[:, :2]
188188
parsed = PointsModel.parse(swap_data, transformations=transformation)
189189

190+
# saving to disk of points temporarily disabled until the interface update that will unify the view widget,
191+
# annotation widget and scatterplot widget
190192
self._write_element_to_disk(sdata, spatial_element_name, parsed, overwrite)
191193

192194
return parsed, coordinate_system
@@ -247,7 +249,15 @@ def _save_shapes_to_sdata(
247249
if len(layer_to_save.data) == 0:
248250
raise ValueError("Cannot export a shapes element with no shapes")
249251

250-
polygons: list[Polygon] = [Polygon(i) for i in _transform_coordinates(layer_to_save.data, f=lambda x: x[::-1])]
252+
coords = [
253+
np.array([layer_to_save.data_to_world(xy) for xy in shape._data])
254+
for shape in layer_to_save._data_view.shapes
255+
]
256+
remove_z = coords[0].shape[1] == 3
257+
first_index = 1 if remove_z else 0
258+
polygons: list[Polygon] = [Polygon(p[::-1, first_index:]) for p in coords]
259+
# polygons: list[Polygon] = [Polygon(i) for i in _transform_coordinates(coords, f=lambda x: x[::-1])]
260+
# polygons: list[Polygon] = [Polygon(i) for i in _transform_coordinates(layer_to_save.data, f=lambda x: x[::-1])]
251261
gdf = GeoDataFrame({"geometry": polygons})
252262

253263
force_2d(gdf)
@@ -573,6 +583,7 @@ def add_sdata_shapes(self, sdata: SpatialData, key: str, selected_cs: str, multi
573583
name=key,
574584
affine=affine,
575585
shape_type="polygon",
586+
face_color="#00000000",
576587
metadata={
577588
"sdata": sdata,
578589
"adata": adata,

src/napari_spatialdata/_widgets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def _onAction(self, items: Iterable[str]) -> None:
135135
self.model.layer.text = None # needed because of the text-feature order of updates
136136
# self.model.layer.features = properties.get("features", None)
137137
self.model.layer.face_color = properties["face_color"]
138+
# self.model.layer.edge_color = properties["face_color"]
138139
self.model.layer.text = properties["text"]
139140
elif isinstance(self.model.layer, Labels):
140141
version = get_napari_version()

0 commit comments

Comments
 (0)