Skip to content

add repr for all graphic features #332

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
Oct 24, 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
4 changes: 4 additions & 0 deletions fastplotlib/graphics/_features/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ def _call_event_handlers(self, event_data: FeatureEvent):
)
func()

@abstractmethod
def __repr__(self) -> str:
pass


def cleanup_slice(key: Union[int, slice], upper_bound) -> Union[slice, int]:
"""
Expand Down
34 changes: 29 additions & 5 deletions fastplotlib/graphics/_features/_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ def _feature_changed(self, key, new_data):

self._call_event_handlers(event_data)

def __repr__(self) -> str:
s = f"ColorsFeature for {self._parent}. Call `<graphic>.colors()` to get values."
return s


class CmapFeature(ColorFeature):
"""
Expand Down Expand Up @@ -270,6 +274,10 @@ def __setitem__(self, key, cmap_name):
self._cmap_name = cmap_name
super(CmapFeature, self).__setitem__(key, colors)

@property
def name(self) -> str:
return self._cmap_name

@property
def values(self) -> np.ndarray:
return self._cmap_values
Expand All @@ -287,10 +295,18 @@ def values(self, values: np.ndarray):

super(CmapFeature, self).__setitem__(slice(None), colors)

def __repr__(self) -> str:
s = f"CmapFeature for {self._parent}, to get name or values: `<graphic>.cmap.name`, `<graphic>.cmap.values`"
return s


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

<graphic>.cmap() returns the Texture buffer for the cmap.

<graphic>.cmap.name returns the cmap name as a str.

**event pick info:**

Expand All @@ -309,17 +325,21 @@ class ImageCmapFeature(GraphicFeature):
def __init__(self, parent, cmap: str):
cmap_texture_view = get_cmap_texture(cmap)
super(ImageCmapFeature, self).__init__(parent, cmap_texture_view)
self.name = cmap
self._name = cmap

def _set(self, cmap_name: str):
if self._parent.data().ndim > 2:
return

self._parent.world_object.material.map.data[:] = make_colors(256, cmap_name)
self._parent.world_object.material.map.update_range((0, 0, 0), size=(256, 1, 1))
self.name = cmap_name
self._name = cmap_name

self._feature_changed(key=None, new_data=self.name)
self._feature_changed(key=None, new_data=self._name)

@property
def name(self) -> str:
return self._name

@property
def vmin(self) -> float:
Expand Down Expand Up @@ -359,7 +379,7 @@ def _feature_changed(self, key, new_data):
pick_info = {
"index": None,
"world_object": self._parent.world_object,
"name": self.name,
"name": self._name,
"vmin": self.vmin,
"vmax": self.vmax,
}
Expand All @@ -368,6 +388,10 @@ def _feature_changed(self, key, new_data):

self._call_event_handlers(event_data)

def __repr__(self) -> str:
s = f"ImageCmapFeature for {self._parent}. Use `<graphic>.cmap.name` to get str name of cmap."
return s


class HeatmapCmapFeature(ImageCmapFeature):
"""
Expand Down
8 changes: 8 additions & 0 deletions fastplotlib/graphics/_features/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def _feature_changed(self, key, new_data):

self._call_event_handlers(event_data)

def __repr__(self) -> str:
s = f"PointsDataFeature for {self._parent}, call `<graphic>.data()` to get values"
return s


class ImageDataFeature(GraphicFeatureIndexable):
"""
Expand Down Expand Up @@ -164,6 +168,10 @@ def _feature_changed(self, key, new_data):

self._call_event_handlers(event_data)

def __repr__(self) -> str:
s = f"ImageDataFeature for {self._parent}, call `<graphic>.data()` to get values"
return s


class HeatmapDataFeature(ImageDataFeature):
@property
Expand Down
4 changes: 4 additions & 0 deletions fastplotlib/graphics/_features/_present.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ def _feature_changed(self, key, new_data):
event_data = FeatureEvent(type="present", pick_info=pick_info)

self._call_event_handlers(event_data)

def __repr__(self) -> str:
s = f"PresentFeature for {self._parent}, call `<graphic>.present()` to get values"
return s
8 changes: 8 additions & 0 deletions fastplotlib/graphics/_features/_selection_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ def _feature_changed(self, key: Union[int, slice, Tuple[slice]], new_data: Any):

self._call_event_handlers(event_data)

def __repr__(self) -> str:
s = f"LinearSelectionFeature for {self._parent}"
return s


class LinearRegionSelectionFeature(GraphicFeature):
"""
Expand Down Expand Up @@ -313,3 +317,7 @@ def _feature_changed(self, key: Union[int, slice, Tuple[slice]], new_data: Any):
event_data = FeatureEvent(type="selection", pick_info=pick_info)

self._call_event_handlers(event_data)

def __repr__(self) -> str:
s = f"LinearRegionSelectionFeature for {self._parent}"
return s
6 changes: 5 additions & 1 deletion fastplotlib/graphics/_features/_sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ def _feature_changed(self, key, new_data):

event_data = FeatureEvent(type="sizes", pick_info=pick_info)

self._call_event_handlers(event_data)
self._call_event_handlers(event_data)

def __repr__(self) -> str:
s = f"PointsSizesFeature for {self._parent}, call `<graphic>.sizes()` to get values"
return s
4 changes: 4 additions & 0 deletions fastplotlib/graphics/_features/_thickness.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ def _feature_changed(self, key, new_data):
event_data = FeatureEvent(type="thickness", pick_info=pick_info)

self._call_event_handlers(event_data)

def __repr__(self) -> str:
s = f"ThicknessFeature for {self._parent}, call `<graphic>.thickness()` to get value"
return s
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