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 e203cff

Browse filesBrowse files
committed
updates to line, works w previous example
1 parent 71eb48f commit e203cff
Copy full SHA for e203cff

File tree

2 files changed

+21
-33
lines changed
Filter options

2 files changed

+21
-33
lines changed

‎fastplotlib/graphics/_base.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_base.py
+6-16Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,7 @@ def __repr__(self):
7171
else:
7272
return f"fastplotlib.{self.__class__.__name__} @ {hex(id(self))}"
7373

74-
def event_handler(self, event):
75-
if event.type in self.registered_callbacks.keys():
76-
for target_info in self.registered_callbacks[event.type]:
77-
target_info.target._set_feature(name=target_info.feature, new_data=target_info.new_data,
78-
indices=target_info.indices)
79-
8074
class Interaction(ABC):
81-
# make them abstract properties
8275
@property
8376
@abstractmethod
8477
def indices(self) -> Any:
@@ -100,20 +93,17 @@ def _set_feature(self, name: str, new_data: Any, indices: Any):
10093

10194
@abstractmethod
10295
def link(self, event: str, target: Graphic, feature: str, new_data: Any, indices_mapper: callable = None):
103-
# event occurs, causes change in feature of current graphic to data indices from pick_info,
104-
# also causes change in target graphic to target feature at target data with corresponding or mapped
105-
# indices based on the indice_mapper function
106-
107-
# events can be feature changes, when feature changes want to trigger an event
108-
109-
# indice mapper takes in source features and maps to target features
11096
pass
11197

98+
def event_handler(self, event):
99+
if event.type in self.registered_callbacks.keys():
100+
for target_info in self.registered_callbacks[event.type]:
101+
target_info.target._set_feature(feature=target_info.feature, new_data=target_info.new_data)
102+
112103
@dataclass
113104
class EventData:
114105
"""Class for keeping track of the info necessary for interactivity after event occurs."""
115-
def __init__(self, target: Graphic, feature: str, new_data: Any, indices: Any):
106+
def __init__(self, target: Graphic, feature: str, new_data: Any):
116107
self.target = target
117108
self.feature = feature
118109
self.new_data = new_data
119-
self.indices = indices

‎fastplotlib/graphics/line.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/line.py
+15-17Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
import pygfx
33
from typing import *
44

5-
from ._base import Graphic
6-
from ._base import EventData
5+
from ._base import Graphic, EventData, Interaction
76

8-
class LineGraphic(Graphic):
7+
class LineGraphic(Graphic, Interaction):
98
def __init__(self, data: np.ndarray, zlevel: float = None, size: float = 2.0, colors: np.ndarray = None, cmap: str = None, *args, **kwargs):
109
super(LineGraphic, self).__init__(data, colors=colors, cmap=cmap, *args, **kwargs)
1110

@@ -57,29 +56,28 @@ def update_colors(self, colors: np.ndarray):
5756

5857
@property
5958
def indices(self) -> Any:
60-
return self.indices
59+
return None
6160

6261
@property
6362
def features(self) -> List[str]:
64-
return self.features
63+
return None
6564

66-
def _set_feature(self, name: str, new_data: Any, indices: Any):
67-
if name == "color":
68-
self.update_colors(new_data)
69-
elif name == "data":
70-
self.update_data(new_data)
65+
def _set_feature(self, feature: str, new_data: Any, indices: Any = None):
66+
if feature in ["colors", "data"]:
67+
update_func = getattr(self, f"update_{feature}")
68+
update_func(new_data)
7169
else:
7270
raise ValueError("name arg is not a valid feature")
7371

74-
def link(self, event: str, target: Graphic, feature: str, new_data: Any, indices_mapper: callable = None):
72+
def link(self, event_type: str, target: Graphic, feature: str, new_data: Any, indices_mapper: callable = None):
7573
valid_events = ["click"]
76-
if event in valid_events:
77-
self.world_object.add_event_handler(self.event_handler, event)
74+
if event_type in valid_events:
75+
self.world_object.add_event_handler(self.event_handler, event_type)
7876
else:
7977
raise ValueError("event not possible")
8078

81-
if event in self.registered_callbacks.keys():
82-
self.registered_callbacks[event].append(EventData(target=target, feature=feature, new_data=new_data, indices=None))
79+
if event_type in self.registered_callbacks.keys():
80+
self.registered_callbacks[event_type].append(EventData(target=target, feature=feature, new_data=new_data))
8381
else:
84-
self.registered_callbacks[event] = list()
85-
self.registered_callbacks[event].append(EventData(target=target, feature=feature, new_data=new_data, indices=None))
82+
self.registered_callbacks[event_type] = list()
83+
self.registered_callbacks[event_type].append(EventData(target=target, feature=feature, new_data=new_data))

0 commit comments

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