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
small changes
  • Loading branch information
clewis7 committed Dec 18, 2022
commit 0f2253170bf17d075dfc2c08ad78734d02e28a1d
28 changes: 21 additions & 7 deletions 28 fastplotlib/graphics/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,36 @@ def features(self) -> List[str]:
pass

@abstractmethod
def _set_feature(self, name: str, new_data: Any, indices: Any):
def _set_feature(self, feature: str, new_data: Any, indices: Any):
pass

clewis7 marked this conversation as resolved.
Show resolved Hide resolved
@abstractmethod
def link(self, event: str, target: Graphic, feature: str, new_data: Any, indices_mapper: callable = None):
def _reset_feature(self):
pass

def link(self, event_type: str, target: Graphic, feature: str, new_data: Any, indices_mapper: callable = None):
valid_events = ["click"]
if event_type in valid_events:
self.world_object.add_event_handler(self.event_handler, event_type)
else:
raise ValueError("event not possible")

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

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)

@dataclass
class EventData:
class CallbackData:
"""Class for keeping track of the info necessary for interactivity after event occurs."""
def __init__(self, target: Graphic, feature: str, new_data: Any):
self.target = target
self.feature = feature
self.new_data = new_data
target: Graphic
feature: str
new_data: Any
16 changes: 3 additions & 13 deletions 16 fastplotlib/graphics/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pygfx
from typing import *

from ._base import Graphic, EventData, Interaction
from ._base import Graphic, CallbackData, Interaction

class LineGraphic(Graphic, Interaction):
def __init__(self, data: np.ndarray, zlevel: float = None, size: float = 2.0, colors: np.ndarray = None, cmap: str = None, *args, **kwargs):
Expand Down Expand Up @@ -69,15 +69,5 @@ def _set_feature(self, feature: str, new_data: Any, indices: Any = None):
else:
raise ValueError("name arg is not a valid feature")

def link(self, event_type: str, target: Graphic, feature: str, new_data: Any, indices_mapper: callable = None):
valid_events = ["click"]
if event_type in valid_events:
self.world_object.add_event_handler(self.event_handler, event_type)
else:
raise ValueError("event not possible")

if event_type in self.registered_callbacks.keys():
self.registered_callbacks[event_type].append(EventData(target=target, feature=feature, new_data=new_data))
else:
self.registered_callbacks[event_type] = list()
self.registered_callbacks[event_type].append(EventData(target=target, feature=feature, new_data=new_data))
def _reset_feature():
pass
Morty Proxy This is a proxified and sanitized view of the page, visit original site.