Thanks to visit codestin.com
Credit goes to github.com

Skip to content

all feature docs #212

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 2 commits into from
May 26, 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
70 changes: 68 additions & 2 deletions docs/source/api/graphic_features.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Features
********
.. _api_graphic_features:

Graphic Features
****************

Image
#####

.. autoclass:: fastplotlib.graphics.features.ImageDataFeature
:members:
Expand All @@ -13,3 +18,64 @@ Features
:exclude-members: __init__
:no-undoc-members:

Heatmap
#######

.. autoclass:: fastplotlib.graphics.features.HeatmapDataFeature
:members:
:inherited-members:
:exclude-members: __init__
:no-undoc-members:

.. autoclass:: fastplotlib.graphics.features.HeatmapCmapFeature
:members:
:inherited-members:
:exclude-members: __init__
:no-undoc-members:

Line
####

.. autoclass:: fastplotlib.graphics.features.PositionsDataFeature
:members:
:inherited-members:
:exclude-members: __init__
:no-undoc-members:

.. autoclass:: fastplotlib.graphics.features.ColorsFeature
:members:
:inherited-members:
:exclude-members: __init__
:no-undoc-members:

.. autoclass:: fastplotlib.graphics.features.ThicknessFeature
:members:
:inherited-members:
:exclude-members: __init__
:no-undoc-members:

Scatter
#######

.. autoclass:: fastplotlib.graphics.features.PositionsDataFeature
:members:
:inherited-members:
:exclude-members: __init__
:no-undoc-members:

.. autoclass:: fastplotlib.graphics.features.ColorsFeature
:members:
:inherited-members:
:exclude-members: __init__
:no-undoc-members:

Common
######

Features common to all graphics

.. autoclass:: fastplotlib.graphics.features.PresentFeature
:members:
:inherited-members:
:exclude-members: __init__
:no-undoc-members:
19 changes: 11 additions & 8 deletions fastplotlib/graphics/features/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ class FeatureEvent:
type: str, example "colors"

pick_info: dict in the form:
============== =======================================================================
index indices where feature data was changed, ``range`` object or List[int]
============== =======================================================================
world_object world object the feature belongs to
new_data the new data for this feature
============== =======================================================================

============== =============================================================================
key value
============== =============================================================================
"index" indices where feature data was changed, ``range`` object or ``List[int]``
"world_object" world object the feature belongs to
"new_data: the new data for this feature
============== =============================================================================

"""
def __init__(self, type: str, pick_info: dict):
Expand Down Expand Up @@ -105,8 +107,8 @@ def add_event_handler(self, handler: callable):
"""
Add an event handler. All added event handlers are called when this feature changes.
The `handler` can optionally accept ``FeatureEvent`` as the first and only argument.
The ``FeatureEvent`` only has two attributes, `type` which denotes the type of event
as a str in the form of "<feature_name>-changed", such as "color-changed".
The ``FeatureEvent`` only has two attributes, ``type`` which denotes the type of event
as a ``str`` in the form of "<feature_name>", such as "color".

Parameters
----------
Expand Down Expand Up @@ -289,6 +291,7 @@ def _update_range(self, key):
@property
@abstractmethod
def buffer(self) -> Union[Buffer, Texture]:
"""Underlying buffer for this feature"""
pass

@property
Expand Down
36 changes: 34 additions & 2 deletions fastplotlib/graphics/features/_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@


class ColorFeature(GraphicFeatureIndexable):
"""
Manages the color buffer for :class:`LineGraphic` or :class:`ScatterGraphic`

**event pick info:**

==================== =============================== =========================================================================
key type description
==================== =============================== =========================================================================
"index" ``numpy.ndarray`` or ``None`` changed indices in the buffer
"new_data" ``numpy.ndarray`` or ``None`` new buffer data at the changed indices
"collection-index" int the index of the graphic within the collection that triggered the event
"world_object" pygfx.WorldObject world object
==================== =============================== =========================================================================


"""
@property
def buffer(self):
return self._parent.world_object.geometry.colors
Expand Down Expand Up @@ -204,6 +220,8 @@ def _feature_changed(self, key, new_data):
class CmapFeature(ColorFeature):
"""
Indexable colormap feature, mostly wraps colors and just provides a way to set colormaps.

Same event pick info as :class:`ColorFeature`
"""
def __init__(self, parent, colors):
super(ColorFeature, self).__init__(parent, colors)
Expand All @@ -227,7 +245,19 @@ def __setitem__(self, key, value):

class ImageCmapFeature(GraphicFeature):
"""
Colormap for ImageGraphic
Colormap for :class:`ImageGraphic`

**event pick info:**

================ =================== ===============
key type description
================ =================== ===============
"index" ``None`` not used
"new_data" ``str`` colormap name
"world_object" pygfx.WorldObject world object
================ =================== ===============


"""
def __init__(self, parent, cmap: str):
cmap_texture_view = get_cmap_texture(cmap)
Expand Down Expand Up @@ -257,7 +287,9 @@ def _feature_changed(self, key, new_data):

class HeatmapCmapFeature(ImageCmapFeature):
"""
Colormap for HeatmapGraphic
Colormap for :class:`HeatmapGraphic`

Same event pick info as :class:`ImageCmapFeature`
"""

def _set(self, cmap_name: str):
Expand Down
15 changes: 13 additions & 2 deletions fastplotlib/graphics/features/_present.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@

class PresentFeature(GraphicFeature):
"""
Toggles if the object is present in the scene, different from visible \n
Toggles if the object is present in the scene, different from visible.
Useful for computing bounding boxes from the Scene to only include graphics
that are present
that are present.

**event pick info:**

==================== ======================== =========================================================================
key type description
==================== ======================== =========================================================================
"index" ``None`` not used
"new_data" ``bool`` new data, ``True`` or ``False``
"collection-index" int the index of the graphic within the collection that triggered the event
"world_object" pygfx.WorldObject world object
==================== ======================== ========================================================================
"""
def __init__(self, parent, present: bool = True, collection_index: int = False):
self._scene = None
Expand Down
13 changes: 12 additions & 1 deletion fastplotlib/graphics/features/_thickness.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@

class ThicknessFeature(GraphicFeature):
"""
Used by Line graphics for line material thickness
Used by Line graphics for line material thickness.

**event pick info:**

===================== ======================== =========================================================================
key type description
==================== ======================== =========================================================================
"index" ``None`` not used
"new_data" ``float`` new thickness value
"collection-index" int the index of the graphic within the collection that triggered the event
"world_object" pygfx.WorldObject world object
==================== ======================== ========================================================================
"""
def __init__(self, parent, thickness: float):
self._scene = None
Expand Down
26 changes: 22 additions & 4 deletions fastplotlib/graphics/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def __init__(
**present**: :class:`.PresentFeature`
Control the presence of the Graphic in the scene


Examples
--------
.. code-block:: python
Expand Down Expand Up @@ -396,17 +397,34 @@ def __init__(
kwargs:
additional keyword arguments passed to Graphic


Features
--------

**data**: :class:`.HeatmapDataFeature`
Manages the data buffer displayed in the HeatmapGraphic

**cmap**: :class:`.HeatmapCmapFeature`
Manages the colormap

**present**: :class:`.PresentFeature`
Control the presence of the Graphic in the scene


Examples
--------
.. code-block:: python

from fastplotlib import Plot
# create a `Plot` instance
plot = Plot()
# make some random 2D image data
data = np.random.rand(512, 512)
# plot the image data
plot.add_image(data=data)

# make some random 2D heatmap data
data = np.random.rand(10_000, 8_000)

# add a heatmap
plot.add_heatmap(data=data)

# show the plot
plot.show()
"""
Expand Down
16 changes: 15 additions & 1 deletion fastplotlib/graphics/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(
thickness of the line

colors: str, array, or iterable, default "w"
specify colors as a single human readable string, a single RGBA array,
specify colors as a single human-readable string, a single RGBA array,
or an iterable of strings or RGBA arrays

cmap: str, optional
Expand All @@ -62,6 +62,20 @@ def __init__(
kwargs
passed to Graphic

Features
--------

**data**: :class:`.ImageDataFeature`
Manages the line [x, y, z] positions data buffer, allows regular and fancy indexing.
ex: ``scatter.data[:, 0] = 5```, ``scatter.data[xs > 5] = 3``

**colors**: :class:`.ColorFeature`
Manages the color buffer, allows regular and fancy indexing.
ex: ``scatter.data[:, 1] = 0.5``, ``scatter.colors[xs > 5] = "cyan"``

**present**: :class:`.PresentFeature`
Control the presence of the Graphic in the scene, set to ``True`` or ``False``

"""

self.data = PointsDataFeature(self, data, collection_index=collection_index)
Expand Down
Loading