Problem in using p.x_range.on_change


I used p.x_range.on_change(‘start’, callback) for boxzoom event.
But this calback also runs when I pan as well. I do not want callback to run when I pan.

How can I prevent callback from running panning?
Is there any event for boxzooming?

There is not an even for box zoom. There is a box Selection event. The BoxSelectionTool emits a SelectionGeometry event that you could use with on_event. The event data will contain a geometry object that reports both screen and data space extents of the box:


But you would also need to update the ranges yourself manually in the event callback since a box selection will not cause a zoom to happen.

1 Like

thank you,
SelectionGeometry is a js event.
I need a python function.
Is there any way to generate a python function from SelectionGeometry event?

There are only events, not “js” events or “python” events". You can use any event with either js_on_event (JS) or on_event (Python)

1 Like

I couldn’t figure out the argument of callback

def cb(??):
p.on_event(‘SelectionGeometry’, cb)


It should have either zero arguments or a single argument named event.

1 Like

thank you.
now it worked