☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Custom JS for BoxEditTool

Community Support
aroberts
aroberts

I have a BoxEditTool (tied to a ColumnDataSource), and I would like to register a callback that triggers whenever a rectangle is added/deleted by that BoxEditTool. Specifically, whenever a rectangle is created by the BoxEditTool, I would like to console.log the start and end coordinates of that rectangle. How can I do this?

Edit: I just figured out how to register the callback of the ColumnDataSource, but unfortunately, BoxEditTool does not distinguish between which corner the mouse started on vs which corner the mouse ended on. How can I get this information?

⌁   Link to post
sosroot
sosroot

Hi, there,
maybe this will help you move forward.

You add a callback

callb = CustomJS(
    args = {'source': source}, code ="""
        var data = source.data;
        var xP = cb_obj.x;
        var yP = cb_obj.y;
        console.log('mouse coordinates on press:(',xP,',',yP,')')
    """
)

and this line.

p.js_on_event(events.Press, callb)

As the rectangle is constructed by 2 mouse presses, the callback displays in the console the coordinates of the first point on the first press and those of the second point on the second press.

⌁   Link to post

End of archived discussion · Replies are disabled