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
updates to line, works w previous example
  • Loading branch information
clewis7 committed Dec 17, 2022
commit e203cff1bf75c23196dbad00b41e0780bb0e3b6f
22 changes: 6 additions & 16 deletions 22 fastplotlib/graphics/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,7 @@ def __repr__(self):
else:
return f"fastplotlib.{self.__class__.__name__} @ {hex(id(self))}"

def event_handler(self, event):
if event.type in self.registered_callbacks.keys():
for target_info in self.registered_callbacks[event.type]:
target_info.target._set_feature(name=target_info.feature, new_data=target_info.new_data,
indices=target_info.indices)

class Interaction(ABC):
# make them abstract properties
@property
@abstractmethod
def indices(self) -> Any:
Expand All @@ -100,20 +93,17 @@ def _set_feature(self, name: str, new_data: Any, indices: Any):

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):
# event occurs, causes change in feature of current graphic to data indices from pick_info,
# also causes change in target graphic to target feature at target data with corresponding or mapped
# indices based on the indice_mapper function

# events can be feature changes, when feature changes want to trigger an event

# indice mapper takes in source features and maps to target features
pass

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:
clewis7 marked this conversation as resolved.
Show resolved Hide resolved
"""Class for keeping track of the info necessary for interactivity after event occurs."""
def __init__(self, target: Graphic, feature: str, new_data: Any, indices: Any):
def __init__(self, target: Graphic, feature: str, new_data: Any):
self.target = target
self.feature = feature
self.new_data = new_data
self.indices = indices
32 changes: 15 additions & 17 deletions 32 fastplotlib/graphics/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import pygfx
from typing import *

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

class LineGraphic(Graphic):
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):
super(LineGraphic, self).__init__(data, colors=colors, cmap=cmap, *args, **kwargs)

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

@property
def indices(self) -> Any:
return self.indices
return None

@property
def features(self) -> List[str]:
return self.features
return None

def _set_feature(self, name: str, new_data: Any, indices: Any):
if name == "color":
self.update_colors(new_data)
elif name == "data":
self.update_data(new_data)
def _set_feature(self, feature: str, new_data: Any, indices: Any = None):
if feature in ["colors", "data"]:
update_func = getattr(self, f"update_{feature}")
update_func(new_data)
else:
raise ValueError("name arg is not a valid feature")

def link(self, event: str, target: Graphic, feature: str, new_data: Any, indices_mapper: callable = None):
def link(self, event_type: str, target: Graphic, feature: str, new_data: Any, indices_mapper: callable = None):
clewis7 marked this conversation as resolved.
Show resolved Hide resolved
valid_events = ["click"]
if event in valid_events:
self.world_object.add_event_handler(self.event_handler, event)
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 in self.registered_callbacks.keys():
self.registered_callbacks[event].append(EventData(target=target, feature=feature, new_data=new_data, indices=None))
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] = list()
self.registered_callbacks[event].append(EventData(target=target, feature=feature, new_data=new_data, indices=None))
self.registered_callbacks[event_type] = list()
self.registered_callbacks[event_type].append(EventData(target=target, feature=feature, new_data=new_data))
Morty Proxy This is a proxified and sanitized view of the page, visit original site.