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

beginning base logic for interactivity impl #61

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

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
implementing reset_feature
  • Loading branch information
clewis7 committed Dec 19, 2022
commit bc688fc510b28b115c478d9759059f85a695d1e4
11 changes: 7 additions & 4 deletions 11 fastplotlib/graphics/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from abc import ABC, abstractmethod
from dataclasses import dataclass
# from .linecollection import LineCollection

class Graphic:
def __init__(
Expand Down Expand Up @@ -92,7 +93,7 @@ def _set_feature(self, feature: str, new_data: Any, indices: Any):
pass

clewis7 marked this conversation as resolved.
Show resolved Hide resolved
@abstractmethod
def _reset_feature(self):
def _reset_feature(self, feature: str, old_data: Any, indices: Any):
pass

def link(self, event_type: str, target: Graphic, feature: str, new_data: Any, indices_mapper: callable = None):
Expand All @@ -104,20 +105,22 @@ def link(self, event_type: str, target: Graphic, feature: str, new_data: Any, in

if event_type in self.registered_callbacks.keys():
self.registered_callbacks[event_type].append(
CallbackData(target=target, feature=feature, new_data=new_data))
CallbackData(target=target, feature=feature, new_data=new_data, old_data=getattr(target, feature).copy()))
else:
self.registered_callbacks[event_type] = list()
self.registered_callbacks[event_type].append(
CallbackData(target=target, feature=feature, new_data=new_data))
CallbackData(target=target, feature=feature, new_data=new_data, old_data=getattr(target, feature).copy()))

def event_handler(self, event):
clewis7 marked this conversation as resolved.
Show resolved Hide resolved
if event.type in self.registered_callbacks.keys():
for target_info in self.registered_callbacks[event.type]:
target_info.target._set_feature(feature=target_info.feature, new_data=target_info.new_data)
target_info.target._reset_feature(feature=target_info.feature, old_data=target_info.old_data, indices=None)
target_info.target._set_feature(feature=target_info.feature, new_data=target_info.new_data, indices=None)

@dataclass
class CallbackData:
"""Class for keeping track of the info necessary for interactivity after event occurs."""
target: Graphic
feature: str
new_data: Any
old_data: Any
9 changes: 7 additions & 2 deletions 9 fastplotlib/graphics/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,10 @@ def _set_feature(self, feature: str, new_data: Any, indices: Any = None):
else:
raise ValueError("name arg is not a valid feature")

def _reset_feature():
pass
def _reset_feature(self, feature: str, old_data: Any, indices: Any = None):
if feature in ["colors", "data"]:
update_func = getattr(self, f"update_{feature}")
update_func(old_data)
else:
raise ValueError("name arg is not a valid feature")

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