Repository navigation
very high level interactivity API #39
Copy link
Copy link
Closed
Milestone
Description
Just a vague idea for now. Currently basic interactivity is implemented with the pygfx events system for the Heatmap. We can think of a high level interactivity API where certain features across Graphic can linked together by a selection of built-in interactivity.
Usage example:
hm_data = np.random.rand(100, 20)
data_indices = np.arange(20)
contours = # get 20 contours
hm_graphic = plot.heatmap(hm_data, indices=data_indices)
# plot the other graphic in the same or some other scene
contour_graphic = plot.multi_line(contours, indices=data_indices)
hm_options = dict(
feature="row",
update_color=[1, 1, 1, 0.5],
update_data=None, # can change the data if desired
event="double_click"
)
contour_options = dict(
feature="line",
update_color=[1, 1, 1, 1],
update_data=None, # if desired
event="click"
)
# bi-directional linking
# heatmap -> contours
linker = hm_graphic.link(source_options=hm_options, target=contour_graphic, target_options=contour_options)
# contours -> heatmap
linker2 = contour_graphic.link(source_options=contour_options, target=hm_graphic, target_options=hm_options)
# to unlink
hm_graphic.unlink(linker)Also allow custom indices mapper to make the data from graphics where the indices don't directly map onto the indices of another graphic. For examples Image -> Contour
# continue from above, so the previous heatmap is also present somewhere in the renderer/canvas
img_data = np.random.rand(512, 512)
image_graphic = plot.image(img_data)
def get_closest_contour(indices) -> np.array:
# convert source graphic indices to target graphic indices
# stuff to map image indices -> contour indices
return contour_indices
image_options = dict(
feature="pixel",
update_data=None, # we don't want to change anything in the image
event="click",
indices_mapper=get_closest_contour,
)
contour_options_img = dict(
feature="line",
update_color=[1, 1, 1, 1],
event=None,
chain_event=True, # this graphic will pass on the source's event to its target if a target exists
)
linker_img = image_graphic.link(source_options=image_options, target=contour_graphic, target_options=contour_options_img)When image_graphic gets a click event it triggers the contour_graphic to change its "line" feature, but since we set chain_event=True for contour_options_img, the contour_graphic will pass along the click event to anything that it is linked to downstream.
Metadata
Metadata
Assignees
Labels
No labels
Activity
kushalkolar commentedon Nov 7, 2022
Allow multi selection too such as:
kushalkolar commentedon Nov 7, 2022
allow changing features of datapoints that are not selected, the inverse of the set of selected datapoints
kushalkolar commentedon Nov 20, 2022
Alternative idea to having dicts is to create an events mixin class for each
Graphicthat defines which feature are interactable.kushalkolar commentedon Dec 5, 2022
For most graphics we can probably define new events such as "hover". For graphics such as line we can allow this to be triggered either by hovering on the actual line, or by an area enclosed by the line.
kushalkolar commentedon Dec 30, 2022
most of it was done in #93, leaving this open for more complex things outlined above
kushalkolar commentedon Jan 2, 2023
continued in #100