Closed
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