Skip to content

refactor text graphic #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/api/graphic_features/CmapFeature.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Properties
:toctree: CmapFeature_api

CmapFeature.buffer
CmapFeature.name
CmapFeature.values

Methods
Expand Down
2 changes: 2 additions & 0 deletions docs/source/api/graphic_features/HeatmapCmapFeature.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Properties
.. autosummary::
:toctree: HeatmapCmapFeature_api

HeatmapCmapFeature.name
HeatmapCmapFeature.vmax
HeatmapCmapFeature.vmin

Expand All @@ -32,4 +33,5 @@ Methods
HeatmapCmapFeature.block_events
HeatmapCmapFeature.clear_event_handlers
HeatmapCmapFeature.remove_event_handler
HeatmapCmapFeature.reset_vmin_vmax

2 changes: 2 additions & 0 deletions docs/source/api/graphic_features/ImageCmapFeature.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Properties
.. autosummary::
:toctree: ImageCmapFeature_api

ImageCmapFeature.name
ImageCmapFeature.vmax
ImageCmapFeature.vmin

Expand All @@ -32,4 +33,5 @@ Methods
ImageCmapFeature.block_events
ImageCmapFeature.clear_event_handlers
ImageCmapFeature.remove_event_handler
ImageCmapFeature.reset_vmin_vmax

34 changes: 34 additions & 0 deletions docs/source/api/graphic_features/PointsSizesFeature.rst
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions docs/source/api/graphic_features/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Graphic Features
ImageCmapFeature
HeatmapCmapFeature
PointsDataFeature
PointsSizesFeature
ImageDataFeature
HeatmapDataFeature
PresentFeature
Expand Down
2 changes: 2 additions & 0 deletions docs/source/api/graphics/HeatmapGraphic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ Methods
HeatmapGraphic.add_linear_region_selector
HeatmapGraphic.add_linear_selector
HeatmapGraphic.link
HeatmapGraphic.reset_feature
HeatmapGraphic.set_feature

2 changes: 2 additions & 0 deletions docs/source/api/graphics/ImageGraphic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ Methods
ImageGraphic.add_linear_region_selector
ImageGraphic.add_linear_selector
ImageGraphic.link
ImageGraphic.reset_feature
ImageGraphic.set_feature

2 changes: 2 additions & 0 deletions docs/source/api/graphics/LineCollection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ Methods
LineCollection.add_linear_selector
LineCollection.link
LineCollection.remove_graphic
LineCollection.reset_feature
LineCollection.set_feature

2 changes: 2 additions & 0 deletions docs/source/api/graphics/LineGraphic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ Methods
LineGraphic.add_linear_region_selector
LineGraphic.add_linear_selector
LineGraphic.link
LineGraphic.reset_feature
LineGraphic.set_feature

2 changes: 2 additions & 0 deletions docs/source/api/graphics/LineStack.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ Methods
LineStack.add_linear_selector
LineStack.link
LineStack.remove_graphic
LineStack.reset_feature
LineStack.set_feature

11 changes: 5 additions & 6 deletions docs/source/api/graphics/TextGraphic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

3 changes: 3 additions & 0 deletions docs/source/api/selectors/LinearRegionSelector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Properties
:toctree: LinearRegionSelector_api

LinearRegionSelector.children
LinearRegionSelector.limits
LinearRegionSelector.position
LinearRegionSelector.position_x
LinearRegionSelector.position_y
Expand All @@ -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

2 changes: 2 additions & 0 deletions docs/source/api/selectors/LinearSelector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Properties
:toctree: LinearSelector_api

LinearSelector.children
LinearSelector.limits
LinearSelector.position
LinearSelector.position_x
LinearSelector.position_y
Expand All @@ -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
Expand Down
40 changes: 40 additions & 0 deletions docs/source/api/selectors/PolygonSelector.rst
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions docs/source/api/selectors/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Selectors

LinearSelector
LinearRegionSelector
PolygonSelector
Synchronizer
2 changes: 2 additions & 0 deletions docs/source/api/widgets/ImageWidget.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Properties
.. autosummary::
:toctree: ImageWidget_api

ImageWidget.cmap
ImageWidget.current_index
ImageWidget.data
ImageWidget.dims_order
Expand All @@ -35,6 +36,7 @@ Methods
.. autosummary::
:toctree: ImageWidget_api

ImageWidget.close
ImageWidget.reset_vmin_vmax
ImageWidget.set_data
ImageWidget.show
Expand Down
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/scatter_size.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 80 additions & 13 deletions fastplotlib/graphics/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
4 changes: 2 additions & 2 deletions fastplotlib/layouts/_subplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy