diff --git a/docs/source/api/graphic_features/CmapFeature.rst b/docs/source/api/graphic_features/CmapFeature.rst index 03e3330b7..7cc2f681f 100644 --- a/docs/source/api/graphic_features/CmapFeature.rst +++ b/docs/source/api/graphic_features/CmapFeature.rst @@ -21,6 +21,7 @@ Properties :toctree: CmapFeature_api CmapFeature.buffer + CmapFeature.name CmapFeature.values Methods diff --git a/docs/source/api/graphic_features/HeatmapCmapFeature.rst b/docs/source/api/graphic_features/HeatmapCmapFeature.rst index 77df37ab0..bac43c9b9 100644 --- a/docs/source/api/graphic_features/HeatmapCmapFeature.rst +++ b/docs/source/api/graphic_features/HeatmapCmapFeature.rst @@ -20,6 +20,7 @@ Properties .. autosummary:: :toctree: HeatmapCmapFeature_api + HeatmapCmapFeature.name HeatmapCmapFeature.vmax HeatmapCmapFeature.vmin @@ -32,4 +33,5 @@ Methods HeatmapCmapFeature.block_events HeatmapCmapFeature.clear_event_handlers HeatmapCmapFeature.remove_event_handler + HeatmapCmapFeature.reset_vmin_vmax diff --git a/docs/source/api/graphic_features/ImageCmapFeature.rst b/docs/source/api/graphic_features/ImageCmapFeature.rst index d2174ff9a..ae65744c7 100644 --- a/docs/source/api/graphic_features/ImageCmapFeature.rst +++ b/docs/source/api/graphic_features/ImageCmapFeature.rst @@ -20,6 +20,7 @@ Properties .. autosummary:: :toctree: ImageCmapFeature_api + ImageCmapFeature.name ImageCmapFeature.vmax ImageCmapFeature.vmin @@ -32,4 +33,5 @@ Methods ImageCmapFeature.block_events ImageCmapFeature.clear_event_handlers ImageCmapFeature.remove_event_handler + ImageCmapFeature.reset_vmin_vmax diff --git a/docs/source/api/graphic_features/PointsSizesFeature.rst b/docs/source/api/graphic_features/PointsSizesFeature.rst new file mode 100644 index 000000000..7915cb09d --- /dev/null +++ b/docs/source/api/graphic_features/PointsSizesFeature.rst @@ -0,0 +1,34 @@ +.. _api.PointsSizesFeature: + +PointsSizesFeature +****************** + +================== +PointsSizesFeature +================== +.. currentmodule:: fastplotlib.graphics._features + +Constructor +~~~~~~~~~~~ +.. autosummary:: + :toctree: PointsSizesFeature_api + + PointsSizesFeature + +Properties +~~~~~~~~~~ +.. autosummary:: + :toctree: PointsSizesFeature_api + + PointsSizesFeature.buffer + +Methods +~~~~~~~ +.. autosummary:: + :toctree: PointsSizesFeature_api + + PointsSizesFeature.add_event_handler + PointsSizesFeature.block_events + PointsSizesFeature.clear_event_handlers + PointsSizesFeature.remove_event_handler + diff --git a/docs/source/api/graphic_features/index.rst b/docs/source/api/graphic_features/index.rst index aff2aabda..1c4b33392 100644 --- a/docs/source/api/graphic_features/index.rst +++ b/docs/source/api/graphic_features/index.rst @@ -9,6 +9,7 @@ Graphic Features ImageCmapFeature HeatmapCmapFeature PointsDataFeature + PointsSizesFeature ImageDataFeature HeatmapDataFeature PresentFeature diff --git a/docs/source/api/graphics/HeatmapGraphic.rst b/docs/source/api/graphics/HeatmapGraphic.rst index 57466698a..6da6f6531 100644 --- a/docs/source/api/graphics/HeatmapGraphic.rst +++ b/docs/source/api/graphics/HeatmapGraphic.rst @@ -38,4 +38,6 @@ Methods HeatmapGraphic.add_linear_region_selector HeatmapGraphic.add_linear_selector HeatmapGraphic.link + HeatmapGraphic.reset_feature + HeatmapGraphic.set_feature diff --git a/docs/source/api/graphics/ImageGraphic.rst b/docs/source/api/graphics/ImageGraphic.rst index 083c72abb..871462701 100644 --- a/docs/source/api/graphics/ImageGraphic.rst +++ b/docs/source/api/graphics/ImageGraphic.rst @@ -36,4 +36,6 @@ Methods ImageGraphic.add_linear_region_selector ImageGraphic.add_linear_selector ImageGraphic.link + ImageGraphic.reset_feature + ImageGraphic.set_feature diff --git a/docs/source/api/graphics/LineCollection.rst b/docs/source/api/graphics/LineCollection.rst index 003ad2897..3f67feed9 100644 --- a/docs/source/api/graphics/LineCollection.rst +++ b/docs/source/api/graphics/LineCollection.rst @@ -41,4 +41,6 @@ Methods LineCollection.add_linear_selector LineCollection.link LineCollection.remove_graphic + LineCollection.reset_feature + LineCollection.set_feature diff --git a/docs/source/api/graphics/LineGraphic.rst b/docs/source/api/graphics/LineGraphic.rst index 75af2c4fe..4aae4bbee 100644 --- a/docs/source/api/graphics/LineGraphic.rst +++ b/docs/source/api/graphics/LineGraphic.rst @@ -36,4 +36,6 @@ Methods LineGraphic.add_linear_region_selector LineGraphic.add_linear_selector LineGraphic.link + LineGraphic.reset_feature + LineGraphic.set_feature diff --git a/docs/source/api/graphics/LineStack.rst b/docs/source/api/graphics/LineStack.rst index 6104d0f74..36ae6808e 100644 --- a/docs/source/api/graphics/LineStack.rst +++ b/docs/source/api/graphics/LineStack.rst @@ -41,4 +41,6 @@ Methods LineStack.add_linear_selector LineStack.link LineStack.remove_graphic + LineStack.reset_feature + LineStack.set_feature diff --git a/docs/source/api/graphics/TextGraphic.rst b/docs/source/api/graphics/TextGraphic.rst index c83c108f6..6290dcc2e 100644 --- a/docs/source/api/graphics/TextGraphic.rst +++ b/docs/source/api/graphics/TextGraphic.rst @@ -21,10 +21,15 @@ Properties :toctree: TextGraphic_api TextGraphic.children + TextGraphic.face_color + TextGraphic.outline_color + TextGraphic.outline_size TextGraphic.position TextGraphic.position_x TextGraphic.position_y TextGraphic.position_z + TextGraphic.text + TextGraphic.text_size TextGraphic.visible TextGraphic.world_object @@ -33,10 +38,4 @@ Methods .. autosummary:: :toctree: TextGraphic_api - TextGraphic.update_face_color - TextGraphic.update_outline_color - TextGraphic.update_outline_size - TextGraphic.update_position - TextGraphic.update_size - TextGraphic.update_text diff --git a/docs/source/api/selectors/LinearRegionSelector.rst b/docs/source/api/selectors/LinearRegionSelector.rst index e1824cfc8..ce0d8d9b6 100644 --- a/docs/source/api/selectors/LinearRegionSelector.rst +++ b/docs/source/api/selectors/LinearRegionSelector.rst @@ -21,6 +21,7 @@ Properties :toctree: LinearRegionSelector_api LinearRegionSelector.children + LinearRegionSelector.limits LinearRegionSelector.position LinearRegionSelector.position_x LinearRegionSelector.position_y @@ -33,7 +34,9 @@ Methods .. autosummary:: :toctree: LinearRegionSelector_api + LinearRegionSelector.add_ipywidget_handler LinearRegionSelector.get_selected_data LinearRegionSelector.get_selected_index LinearRegionSelector.get_selected_indices + LinearRegionSelector.make_ipywidget_slider diff --git a/docs/source/api/selectors/LinearSelector.rst b/docs/source/api/selectors/LinearSelector.rst index 2c30579f1..4056bcc46 100644 --- a/docs/source/api/selectors/LinearSelector.rst +++ b/docs/source/api/selectors/LinearSelector.rst @@ -21,6 +21,7 @@ Properties :toctree: LinearSelector_api LinearSelector.children + LinearSelector.limits LinearSelector.position LinearSelector.position_x LinearSelector.position_y @@ -33,6 +34,7 @@ Methods .. autosummary:: :toctree: LinearSelector_api + LinearSelector.add_ipywidget_handler LinearSelector.get_selected_data LinearSelector.get_selected_index LinearSelector.get_selected_indices diff --git a/docs/source/api/selectors/PolygonSelector.rst b/docs/source/api/selectors/PolygonSelector.rst new file mode 100644 index 000000000..aaa434dbf --- /dev/null +++ b/docs/source/api/selectors/PolygonSelector.rst @@ -0,0 +1,40 @@ +.. _api.PolygonSelector: + +PolygonSelector +*************** + +=============== +PolygonSelector +=============== +.. currentmodule:: fastplotlib + +Constructor +~~~~~~~~~~~ +.. autosummary:: + :toctree: PolygonSelector_api + + PolygonSelector + +Properties +~~~~~~~~~~ +.. autosummary:: + :toctree: PolygonSelector_api + + PolygonSelector.children + PolygonSelector.position + PolygonSelector.position_x + PolygonSelector.position_y + PolygonSelector.position_z + PolygonSelector.visible + PolygonSelector.world_object + +Methods +~~~~~~~ +.. autosummary:: + :toctree: PolygonSelector_api + + PolygonSelector.get_selected_data + PolygonSelector.get_selected_index + PolygonSelector.get_selected_indices + PolygonSelector.get_vertices + diff --git a/docs/source/api/selectors/index.rst b/docs/source/api/selectors/index.rst index 918944fd8..01c040728 100644 --- a/docs/source/api/selectors/index.rst +++ b/docs/source/api/selectors/index.rst @@ -6,4 +6,5 @@ Selectors LinearSelector LinearRegionSelector + PolygonSelector Synchronizer diff --git a/docs/source/api/widgets/ImageWidget.rst b/docs/source/api/widgets/ImageWidget.rst index 62ec176ce..4e779f20b 100644 --- a/docs/source/api/widgets/ImageWidget.rst +++ b/docs/source/api/widgets/ImageWidget.rst @@ -20,6 +20,7 @@ Properties .. autosummary:: :toctree: ImageWidget_api + ImageWidget.cmap ImageWidget.current_index ImageWidget.data ImageWidget.dims_order @@ -35,6 +36,7 @@ Methods .. autosummary:: :toctree: ImageWidget_api + ImageWidget.close ImageWidget.reset_vmin_vmax ImageWidget.set_data ImageWidget.show diff --git a/examples/desktop/screenshots/scatter_size.png b/examples/desktop/screenshots/scatter_size.png index db637d270..1d0f91f9c 100644 --- a/examples/desktop/screenshots/scatter_size.png +++ b/examples/desktop/screenshots/scatter_size.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a4cefd4cf57e54e1ef7883edea54806dfde57939d0a395c5a7758124e41b8beb -size 63485 +oid sha256:3eb05d8a18aada52a6ab02a0d3d030aab97510aace226cf3967e5c5c1cd3274d +size 66044 diff --git a/fastplotlib/graphics/text.py b/fastplotlib/graphics/text.py index 2648e2fa6..a159d9560 100644 --- a/fastplotlib/graphics/text.py +++ b/fastplotlib/graphics/text.py @@ -10,11 +10,14 @@ def __init__( self, text: str, position: Tuple[int] = (0, 0, 0), - size: int = 10, + size: int = 14, face_color: Union[str, np.ndarray] = "w", outline_color: Union[str, np.ndarray] = "w", outline_thickness=0, - name: str = None, + screen_space: bool = True, + anchor: str = "middle-center", + *args, + **kwargs ): """ Create a text Graphic @@ -39,15 +42,30 @@ def __init__( outline_thickness: int, default 0 text outline thickness + screen_space: bool = True + whether the text is rendered in screen space, in contrast to world space + name: str, optional name of graphic, passed to Graphic + anchor: str, default "middle-center" + position of the origin of the text + a string representing the vertical and horizontal anchors, separated by a dash + + * Vertical values: "top", "middle", "baseline", "bottom" + * Horizontal values: "left", "center", "right" """ + super(TextGraphic, self).__init__(*args, **kwargs) - super(TextGraphic, self).__init__(name=name) + self._text = text world_object = pygfx.Text( - pygfx.TextGeometry(text=str(text), font_size=size, screen_space=False), + pygfx.TextGeometry( + text=str(text), + font_size=size, + screen_space=screen_space, + anchor=anchor, + ), pygfx.TextMaterial( color=face_color, outline_color=outline_color, @@ -59,22 +77,71 @@ def __init__( self.world_object.position = position - self.name = None + @property + def text(self): + """Returns the text of this graphic.""" + return self._text + + @text.setter + def text(self, text: str): + """Set the text of this graphic.""" + if not isinstance(text, str): + raise ValueError("Text must be of type str.") - def update_text(self, text: str): - self.world_object.geometry.set_text(text) + self._text = text + self.world_object.geometry.set_text(self._text) + + @property + def text_size(self): + """Returns the text size of this graphic.""" + return self.world_object.geometry.font_size + + @text_size.setter + def text_size(self, size: Union[int, float]): + """Set the text size of this graphic.""" + if not (isinstance(size, int) or isinstance(size, float)): + raise ValueError("Text size must be of type int or float") - def update_size(self, size: int): self.world_object.geometry.font_size = size - def update_face_color(self, color: Union[str, np.ndarray]): + @property + def face_color(self): + """Returns the face color of this graphic.""" + return self.world_object.material.color + + @face_color.setter + def face_color(self, color: Union[str, np.ndarray]): + """Set the face color of this graphic.""" + if not (isinstance(color, str) or isinstance(color, np.ndarray)): + raise ValueError("Face color must be of type str or np.ndarray") + + color = pygfx.Color(color) + self.world_object.material.color = color - def update_outline_size(self, size: int): + @property + def outline_size(self): + """Returns the outline size of this graphic.""" + return self.world_object.material.outline_thickness + + @outline_size.setter + def outline_size(self, size: Union[int, float]): + """Set the outline size of this text graphic.""" + if not (isinstance(size, int) or isinstance(size, float)): + raise ValueError("Outline size must be of type int or float") + self.world_object.material.outline_thickness = size - def update_outline_color(self, color: Union[str, np.ndarray]): + @property + def outline_color(self): + """Returns the outline color of this graphic.""" + return self.world_object.material.outline_color + + @outline_color.setter + def outline_color(self, color: Union[str, np.ndarray]): + """Set the outline color of this graphic""" + if not (isinstance(color, str) or isinstance(color, np.ndarray)): + raise ValueError("Outline color must be of type str or np.ndarray") + self.world_object.material.outline_color = color - def update_position(self, pos: Tuple[int, int, int]): - self.world_object.position.set(*pos) diff --git a/fastplotlib/layouts/_subplot.py b/fastplotlib/layouts/_subplot.py index a8cd4852b..0878dc0fd 100644 --- a/fastplotlib/layouts/_subplot.py +++ b/fastplotlib/layouts/_subplot.py @@ -152,9 +152,9 @@ def set_title(self, text: Any): text = str(text) if self._title_graphic is not None: - self._title_graphic.update_text(text) + self._title_graphic.text = text else: - tg = TextGraphic(text) + tg = TextGraphic(text=text, size=18) self._title_graphic = tg self.docks["top"].size = 35 diff --git a/fastplotlib/layouts/graphic_methods_mixin.py b/fastplotlib/layouts/graphic_methods_mixin.py index 760083cb9..b00187df7 100644 --- a/fastplotlib/layouts/graphic_methods_mixin.py +++ b/fastplotlib/layouts/graphic_methods_mixin.py @@ -313,7 +313,7 @@ def add_line_stack(self, data: List[numpy.ndarray], z_position: Union[List[float """ return self._create_graphic(LineStack, data, z_position, thickness, colors, cmap, separation, separation_axis, name, *args, **kwargs) - def add_scatter(self, data: numpy.ndarray, sizes: Union[int, numpy.ndarray, list] = 1, colors: numpy.ndarray = 'w', alpha: float = 1.0, cmap: str = None, cmap_values: Union[numpy.ndarray, List] = None, z_position: float = 0.0, *args, **kwargs) -> ScatterGraphic: + def add_scatter(self, data: numpy.ndarray, sizes: Union[int, float, numpy.ndarray, list] = 1, colors: numpy.ndarray = 'w', alpha: float = 1.0, cmap: str = None, cmap_values: Union[numpy.ndarray, List] = None, z_position: float = 0.0, *args, **kwargs) -> ScatterGraphic: """ Create a Scatter Graphic, 2d or 3d @@ -368,7 +368,7 @@ def add_scatter(self, data: numpy.ndarray, sizes: Union[int, numpy.ndarray, list """ return self._create_graphic(ScatterGraphic, data, sizes, colors, alpha, cmap, cmap_values, z_position, *args, **kwargs) - def add_text(self, text: str, position: Tuple[int] = (0, 0, 0), size: int = 10, face_color: Union[str, numpy.ndarray] = 'w', outline_color: Union[str, numpy.ndarray] = 'w', outline_thickness=0, name: str = None) -> TextGraphic: + def add_text(self, text: str, position: Tuple[int] = (0, 0, 0), size: int = 14, face_color: Union[str, numpy.ndarray] = 'w', outline_color: Union[str, numpy.ndarray] = 'w', outline_thickness=0, screen_space: bool = True, anchor: str = 'middle-center', *args, **kwargs) -> TextGraphic: """ Create a text Graphic @@ -393,10 +393,19 @@ def add_text(self, text: str, position: Tuple[int] = (0, 0, 0), size: int = 10, outline_thickness: int, default 0 text outline thickness + screen_space: bool = True + whether the text is rendered in screen space, in contrast to world space + name: str, optional name of graphic, passed to Graphic + anchor: str, default "middle-center" + position of the origin of the text + a string representing the vertical and horizontal anchors, separated by a dash + + * Vertical values: "top", "middle", "baseline", "bottom" + * Horizontal values: "left", "center", "right" """ - return self._create_graphic(TextGraphic, text, position, size, face_color, outline_color, outline_thickness, name, *args, **kwargs) + return self._create_graphic(TextGraphic, text, position, size, face_color, outline_color, outline_thickness, screen_space, anchor, *args, **kwargs)