diff --git a/whitecanvas/canvas/_base.py b/whitecanvas/canvas/_base.py index aef0b470..526a37a1 100644 --- a/whitecanvas/canvas/_base.py +++ b/whitecanvas/canvas/_base.py @@ -19,7 +19,6 @@ from cmap import Color from numpy.typing import ArrayLike from psygnal import Signal, SignalGroup -from typing_extensions import deprecated from whitecanvas import layers as _l from whitecanvas import protocols, theme @@ -49,7 +48,6 @@ OrientationLike, Rect, Symbol, - _Void, ) from whitecanvas.utils.normalize import as_array_1d, normalize_xy from whitecanvas.utils.type_check import is_real_number @@ -62,7 +60,6 @@ _L = TypeVar("_L", bound=_l.Layer) _L0 = TypeVar("_L0", _l.Bars, _l.Band) -_void = _Void() class CanvasEvents(SignalGroup): @@ -734,22 +731,6 @@ def stack_over(self, layer: _L0) -> StackOverPlotter[Self, _L0]: def between(self, l0, l1) -> BetweenPlotter[Self]: return BetweenPlotter(self, l0, l1) - @deprecated( - "ImageRef is deprecated and will be removed in the future. " - "Please use the Image methods `with_text`, `with_colorbar` instead.", - ) - def imref(self, layer: _l.Image): - """The Image reference namespace.""" - from whitecanvas.canvas._imageref import ImageRef - - while isinstance(layer, _l.LayerWrapper): - layer = layer._base_layer - if not isinstance(layer, _l.Image): - raise TypeError( - f"Expected an Image layer or its wrapper, got {type(layer)}." - ) - return ImageRef(self, layer) - def fit(self, layer: _l.DataBoundLayer[_P]) -> FitPlotter[Self, _P]: """The fit plotter namespace.""" return FitPlotter(self, layer) diff --git a/whitecanvas/canvas/_imageref.py b/whitecanvas/canvas/_imageref.py deleted file mode 100644 index 28516aa6..00000000 --- a/whitecanvas/canvas/_imageref.py +++ /dev/null @@ -1,56 +0,0 @@ -# pragma: no cover -from __future__ import annotations - -import weakref -from typing import TYPE_CHECKING, Callable, Generic, TypeVar - -import numpy as np - -from whitecanvas._exceptions import ReferenceDeletedError -from whitecanvas.layers import _mixin -from whitecanvas.types import ColorType, Orientation - -if TYPE_CHECKING: - from whitecanvas.canvas._base import CanvasBase - from whitecanvas.layers._primitive import Image, Texts - -_C = TypeVar("_C", bound="CanvasBase") - - -class ImageRef(Generic[_C]): - def __init__(self, canvas: _C, image: Image): - self._canvas_ref = weakref.ref(canvas) - self._image_ref = weakref.ref(image) - - def _canvas(self) -> _C: - canvas = self._canvas_ref() - if canvas is None: - raise ReferenceDeletedError("Canvas has been deleted.") - return canvas - - def _image(self) -> Image: - image = self._image_ref() - if image is None: - raise ReferenceDeletedError("Image has been deleted.") - return image - - def add_colorbar( - self, - pos=None, - orient: str | Orientation = Orientation.VERTICAL, - ) -> _C: - cbar = self._image()._make_colorbar(pos=pos, orient=orient) - return self._canvas().add_layer(cbar) - - def add_text( - self, - *, - size: int = 8, - color_rule: ColorType | Callable[[np.ndarray], ColorType] | None = None, - fmt: str = "", - text_invalid: str | None = None, - ) -> Texts[_mixin.MonoFace, _mixin.MonoEdge, _mixin.MultiFont]: - text_layer = self._image()._make_text_layer( - size=size, color_rule=color_rule, fmt=fmt, text_invalid=text_invalid - ) # fmt: skip - return self._canvas().add_layer(text_layer) diff --git a/whitecanvas/layers/group/labeled.py b/whitecanvas/layers/group/labeled.py index 9037900c..f1ff2cad 100644 --- a/whitecanvas/layers/group/labeled.py +++ b/whitecanvas/layers/group/labeled.py @@ -5,7 +5,6 @@ import numpy as np from cmap import Colormap from numpy.typing import NDArray -from typing_extensions import deprecated from whitecanvas.backend import Backend from whitecanvas.layers import _legend, _mixin, _text_utils @@ -28,14 +27,12 @@ Origin, Rect, XYData, - _Void, ) from whitecanvas.utils.normalize import as_any_1d_array, as_color_array if TYPE_CHECKING: from typing_extensions import Self -_void = _Void() _NFace = TypeVar("_NFace", bound="_mixin.FaceNamespace") _NEdge = TypeVar("_NEdge", bound="_mixin.EdgeNamespace") _Size = TypeVar("_Size") @@ -131,10 +128,6 @@ def with_text_offset(self, dx: Any, dy: Any): self.texts.set_pos(px + xoff, py + yoff) self._text_offset = _offset - @deprecated("add_text_offset is deprecated. Please use with_text_offset instead.") - def add_text_offset(self, *args, **kwargs): - return self.with_text_offset(*args, **kwargs) - def with_xerr( self, len_lower: float, @@ -736,12 +729,12 @@ def origin(self, origin: Origin | str): self.image.origin = origin @overload - def fit_to(self, bbox: Rect | tuple[float, float, float, float], /) -> Image: - ... + def fit_to(self, bbox: Rect | tuple[float, float, float, float], /) -> Image: ... @overload - def fit_to(self, left: float, right: float, bottom: float, top: float, /) -> Image: - ... + def fit_to( + self, left: float, right: float, bottom: float, top: float, / + ) -> Image: ... def fit_to(self, *args) -> Image: """Fit the image to the given bounding box."""