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

Interactivity attempt 4 #93

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 13 commits into from
Dec 29, 2022
Prev Previous commit
Next Next commit
single contour updates/fixes
  • Loading branch information
clewis7 committed Dec 29, 2022
commit 0517d5c6b74953b491a74676ec04f03bc9e358ac
4 changes: 3 additions & 1 deletion 4 fastplotlib/graphics/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ def event_handler(self, event):
if target_info.callback_function is not None:
# if callback_function is not None, then callback function should handle the entire event
target_info.callback_function(source=self, target=target_info.target, event=event, new_data=target_info.new_data)
elif isinstance(self, GraphicCollection):
elif isinstance(target_info.target, GraphicCollection):
# if target is a GraphicCollection, then indices will be stored in collection_index
indices = event.pick_info["collection_index"]
target_info.target._set_feature(feature=target_info.feature, new_data=target_info.new_data, indices=indices)
else:
# if target is a single graphic, then indices do not matter
target_info.target._set_feature(feature=target_info.feature, new_data=target_info.new_data,
indices=None)
clewis7 marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
5 changes: 2 additions & 3 deletions 5 fastplotlib/graphics/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

class ImageGraphic(Graphic, Interaction):
feature_events = [
"data-changed",
"color-changed",
"cmap-changed",
"data",
"cmap",
]
def __init__(
self,
Expand Down
28 changes: 14 additions & 14 deletions 28 fastplotlib/graphics/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@


class LineGraphic(Graphic, Interaction):
feature_events = [
"data",
"colors",
"cmap",
clewis7 marked this conversation as resolved.
Show resolved Hide resolved
]
def __init__(
self,
data: Any,
Expand Down Expand Up @@ -86,32 +91,27 @@ def __init__(

def _set_feature(self, feature: str, new_data: Any, indices: Any = None):
if not hasattr(self, "_previous_data"):
self._previous_data = {}
self._previous_data = dict()
elif hasattr(self, "_previous_data"):
self._reset_feature(feature)
# if feature in self._feature_events:

feature_instance = getattr(self, feature)
if indices is not None:
previous = feature_instance[indices].copy()
feature_instance[indices] = new_data
else:
previous = feature_instance[:].copy()
feature_instance[:] = new_data
previous = feature_instance._data.copy()
feature_instance._set(new_data)
if feature in self._previous_data.keys():
self._previous_data[feature].previous_data = previous
self._previous_data[feature].previous_indices = indices
else:
self._previous_data[feature] = PreviouslyModifiedData(previous_data=previous, previous_indices=indices)
# else:
# raise ValueError("name arg is not a valid feature")

def _reset_feature(self, feature: str):
if feature not in self._previous_data.keys():
raise ValueError("no previous data registered for this feature")
prev_ixs = self._previous_data[feature].previous_indices
feature_instance = getattr(self, feature)
if prev_ixs is not None:
feature_instance[prev_ixs] = self._previous_data[feature].previous_data
else:
feature_instance = getattr(self, feature)
if self._previous_data[feature].previous_indices is not None:
feature_instance[self._previous_data[feature].previous_indices] = self._previous_data[
feature].previous_data
else:
feature_instance[:] = self._previous_data[feature].previous_data
feature_instance._set(self._previous_data[feature].previous_data)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.