Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6075ca2

Browse filesBrowse files
authored
add repr for all graphic features (#332)
1 parent d7072b5 commit 6075ca2
Copy full SHA for 6075ca2

File tree

7 files changed

+62
-6
lines changed
Filter options

7 files changed

+62
-6
lines changed

‎fastplotlib/graphics/_features/_base.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_features/_base.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ def _call_event_handlers(self, event_data: FeatureEvent):
191191
)
192192
func()
193193

194+
@abstractmethod
195+
def __repr__(self) -> str:
196+
pass
197+
194198

195199
def cleanup_slice(key: Union[int, slice], upper_bound) -> Union[slice, int]:
196200
"""

‎fastplotlib/graphics/_features/_colors.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_features/_colors.py
+29-5Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ def _feature_changed(self, key, new_data):
234234

235235
self._call_event_handlers(event_data)
236236

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

238242
class CmapFeature(ColorFeature):
239243
"""
@@ -270,6 +274,10 @@ def __setitem__(self, key, cmap_name):
270274
self._cmap_name = cmap_name
271275
super(CmapFeature, self).__setitem__(key, colors)
272276

277+
@property
278+
def name(self) -> str:
279+
return self._cmap_name
280+
273281
@property
274282
def values(self) -> np.ndarray:
275283
return self._cmap_values
@@ -287,10 +295,18 @@ def values(self, values: np.ndarray):
287295

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

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

291303
class ImageCmapFeature(GraphicFeature):
292304
"""
293-
Colormap for :class:`ImageGraphic`
305+
Colormap for :class:`ImageGraphic`.
306+
307+
<graphic>.cmap() returns the Texture buffer for the cmap.
308+
309+
<graphic>.cmap.name returns the cmap name as a str.
294310
295311
**event pick info:**
296312
@@ -309,17 +325,21 @@ class ImageCmapFeature(GraphicFeature):
309325
def __init__(self, parent, cmap: str):
310326
cmap_texture_view = get_cmap_texture(cmap)
311327
super(ImageCmapFeature, self).__init__(parent, cmap_texture_view)
312-
self.name = cmap
328+
self._name = cmap
313329

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

318334
self._parent.world_object.material.map.data[:] = make_colors(256, cmap_name)
319335
self._parent.world_object.material.map.update_range((0, 0, 0), size=(256, 1, 1))
320-
self.name = cmap_name
336+
self._name = cmap_name
321337

322-
self._feature_changed(key=None, new_data=self.name)
338+
self._feature_changed(key=None, new_data=self._name)
339+
340+
@property
341+
def name(self) -> str:
342+
return self._name
323343

324344
@property
325345
def vmin(self) -> float:
@@ -359,7 +379,7 @@ def _feature_changed(self, key, new_data):
359379
pick_info = {
360380
"index": None,
361381
"world_object": self._parent.world_object,
362-
"name": self.name,
382+
"name": self._name,
363383
"vmin": self.vmin,
364384
"vmax": self.vmax,
365385
}
@@ -368,6 +388,10 @@ def _feature_changed(self, key, new_data):
368388

369389
self._call_event_handlers(event_data)
370390

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

372396
class HeatmapCmapFeature(ImageCmapFeature):
373397
"""

‎fastplotlib/graphics/_features/_data.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_features/_data.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ def _feature_changed(self, key, new_data):
100100

101101
self._call_event_handlers(event_data)
102102

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

104108
class ImageDataFeature(GraphicFeatureIndexable):
105109
"""
@@ -164,6 +168,10 @@ def _feature_changed(self, key, new_data):
164168

165169
self._call_event_handlers(event_data)
166170

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

168176
class HeatmapDataFeature(ImageDataFeature):
169177
@property

‎fastplotlib/graphics/_features/_present.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_features/_present.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ def _feature_changed(self, key, new_data):
6666
event_data = FeatureEvent(type="present", pick_info=pick_info)
6767

6868
self._call_event_handlers(event_data)
69+
70+
def __repr__(self) -> str:
71+
s = f"PresentFeature for {self._parent}, call `<graphic>.present()` to get values"
72+
return s

‎fastplotlib/graphics/_features/_selection_features.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_features/_selection_features.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ def _feature_changed(self, key: Union[int, slice, Tuple[slice]], new_data: Any):
191191

192192
self._call_event_handlers(event_data)
193193

194+
def __repr__(self) -> str:
195+
s = f"LinearSelectionFeature for {self._parent}"
196+
return s
197+
194198

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

315319
self._call_event_handlers(event_data)
320+
321+
def __repr__(self) -> str:
322+
s = f"LinearRegionSelectionFeature for {self._parent}"
323+
return s

‎fastplotlib/graphics/_features/_sizes.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_features/_sizes.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,8 @@ def _feature_changed(self, key, new_data):
105105

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

108-
self._call_event_handlers(event_data)
108+
self._call_event_handlers(event_data)
109+
110+
def __repr__(self) -> str:
111+
s = f"PointsSizesFeature for {self._parent}, call `<graphic>.sizes()` to get values"
112+
return s

‎fastplotlib/graphics/_features/_thickness.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_features/_thickness.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ def _feature_changed(self, key, new_data):
4040
event_data = FeatureEvent(type="thickness", pick_info=pick_info)
4141

4242
self._call_event_handlers(event_data)
43+
44+
def __repr__(self) -> str:
45+
s = f"ThicknessFeature for {self._parent}, call `<graphic>.thickness()` to get value"
46+
return s

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.