Problem in using p.x_range.on_change

Hi,

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?
Or
Is there any event for boxzooming?
regards

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:

{"type":"rect","sx0":348,"sx1":493,"sy0":172,"sy1":341,"x0":59.69,"y0":40.28,"x1":89.26,"y1":72.8}

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?
regards

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

Hi,
I couldn’t figure out the argument of callback

def cb(??):
print("–*****-")
p.on_event(‘SelectionGeometry’, cb)

regards

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

1 Like

thank you.
now it worked