diff --git a/src/napari_spatialdata/_viewer.py b/src/napari_spatialdata/_viewer.py index 9df2f03f..30ef4835 100644 --- a/src/napari_spatialdata/_viewer.py +++ b/src/napari_spatialdata/_viewer.py @@ -161,13 +161,13 @@ def _write_element_to_disk( element: tuple[DaskDataFrame | GeoDataFrame | AnnData], overwrite: bool, ) -> None: - if sdata.is_backed: - self._delete_from_disk(sdata, element_name, overwrite) - sdata[element_name] = element - sdata.write_element(element_name) - else: - sdata[element_name] = element - logger.warning("Spatialdata object is not stored on disk, could only add element in memory.") + # if sdata.is_backed: + # self._delete_from_disk(sdata, element_name, overwrite) + # sdata[element_name] = element + # sdata.write_element(element_name) + # else: + sdata[element_name] = element + logger.warning("Annotations only added in memory, please manually save to disk.") def _save_points_to_sdata( self, layer_to_save: Points, spatial_element_name: str | None, overwrite: bool @@ -187,6 +187,8 @@ def _save_points_to_sdata( swap_data = swap_data[:, :2] parsed = PointsModel.parse(swap_data, transformations=transformation) + # saving to disk of points temporarily disabled until the interface update that will unify the view widget, + # annotation widget and scatterplot widget self._write_element_to_disk(sdata, spatial_element_name, parsed, overwrite) return parsed, coordinate_system @@ -247,7 +249,15 @@ def _save_shapes_to_sdata( if len(layer_to_save.data) == 0: raise ValueError("Cannot export a shapes element with no shapes") - polygons: list[Polygon] = [Polygon(i) for i in _transform_coordinates(layer_to_save.data, f=lambda x: x[::-1])] + coords = [ + np.array([layer_to_save.data_to_world(xy) for xy in shape._data]) + for shape in layer_to_save._data_view.shapes + ] + remove_z = coords[0].shape[1] == 3 + first_index = 1 if remove_z else 0 + polygons: list[Polygon] = [Polygon(p[::-1, first_index:]) for p in coords] + # polygons: list[Polygon] = [Polygon(i) for i in _transform_coordinates(coords, f=lambda x: x[::-1])] + # polygons: list[Polygon] = [Polygon(i) for i in _transform_coordinates(layer_to_save.data, f=lambda x: x[::-1])] gdf = GeoDataFrame({"geometry": polygons}) force_2d(gdf) @@ -573,6 +583,7 @@ def add_sdata_shapes(self, sdata: SpatialData, key: str, selected_cs: str, multi name=key, affine=affine, shape_type="polygon", + face_color="#00000000", metadata={ "sdata": sdata, "adata": adata, diff --git a/src/napari_spatialdata/_widgets.py b/src/napari_spatialdata/_widgets.py index 067a980b..eb18e266 100644 --- a/src/napari_spatialdata/_widgets.py +++ b/src/napari_spatialdata/_widgets.py @@ -135,6 +135,7 @@ def _onAction(self, items: Iterable[str]) -> None: self.model.layer.text = None # needed because of the text-feature order of updates # self.model.layer.features = properties.get("features", None) self.model.layer.face_color = properties["face_color"] + # self.model.layer.edge_color = properties["face_color"] self.model.layer.text = properties["text"] elif isinstance(self.model.layer, Labels): version = get_napari_version()