K3D-tools / K3D-jupyter

K3D lets you create 3D plots backed by WebGL with high-level API (surfaces, isosurfaces, voxels, mesh, cloud points, vtk objects, volume renderer, colormaps, etc). The primary aim of K3D-jupyter is to be easy for use as stand alone package like matplotlib, but also to allow interoperation with existing libraries as VTK.
MIT License
917 stars 123 forks source link

Hover callback not working on points object #369

Closed davidwhealey closed 1 year ago

davidwhealey commented 1 year ago

I'm attempting to apply callbacks to points objects so I can plot some data and display information about the points interactively. Running the mesh_callback.ipynb example works, but if I replace the mesh with points, the callback no longer displays any labels.
Any help in figuring out how to get callbacks on single points of data would be helpful. Thank you!

import k3d
import numpy as np

points_number = 500
positions = 50 * np.random.random_sample((points_number,3)) - 25
point_size = 2
colors = np.random.randint(0, 0xFFFFFF, points_number)

plot = k3d.plot(name='points')
points = k3d.points(
    positions.astype(np.float32), 
    colors.astype(np.uint32), 
    point_size=point_size, 
    shader='dot'
)

label = k3d.label('', mode='local', color=0x0)

plot += points
plot += label

def update_label(p):
    global label    
    label.text = '\\vec{n} = \\begin{bmatrix} ' + "\\\\".join([str(v) for v in p['normal']]) +' \\end{bmatrix}'
    label.position = p['position']

points.hover_callback = update_label

plot.display()
plot.mode = 'callback'
davidwhealey commented 1 year ago

Oh, I have just discovered that callbacks only work on surfaces and not points and lines.