Following the discussion here, I decided to attempt creating a custom extension for the BoxZoomTool, adding a property that would change when the zoom completed, to be able to call a Python callback for on_change events (x_range and y_range on_change fired too many events, and caused strange image updating for my app). I followed the User Guide to create a custom.ts and then created an instance and passed it to the Figure. The Bokeh app itself is working, but I don’t get any difference (i.e. my custom _pan_end event doesn’t seem to fire, no console log output). I’m sure I’m doing something wrong with calling _pan_end, but I’m not sure which other BoxZoomTool method to override.
custom.ts:
import * as p from “core/properties”
import {BoxZoomTool, BoxZoomToolView} from “models/tools/gestures/box_zoom_tool”
import {GestureTool, GestureToolView} from “./gesture_tool”
export class CustomView extends BoxZoomToolView{
_pan_end(e){
super._pan_end(e)
console.log("Made it to _pan_end")
console.log($(this.mode.zoom_end))
this.model.zoom_end = !this.model.zoom_end
console.log($(this.mode.zoom_end))
}
}
export class Custom extends BoxZoomTool{
default_view: BoxZoomToolView
type: "Custom"
tool_name: "Custom Box Zoom"
}
Custom.define({
zoom_end: [p.Bool, false ]
})
``
run_custom.py
#!/usr/bin python
import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import layout
from bokeh.models import Slider, Button, BoxZoomTool
from bokeh.plotting import figure, ColumnDataSource
from bokeh.core.properties import Bool
from bokeh.util.compiler import TypeScript
class Custom(BoxZoomTool):
__implementation__ = "custom.ts" #TypeScript(JS_CODE)
zoom_end = Bool(default=False)
custom = Custom(zoom_end=False)
p =figure(tools = [custom])
p.line([1,2,3],[1,2,3])
i = 0
def zoom_end_update(attr,old,new):
i += 1
print str(i) + ' Zoom ended!!!!'
custom.on_change(‘zoom_end’,zoom_end_update)
#slider = Slider(start=0, end=10, value=1, step=.1, title=“Stuff”)
curdoc().add_root(p)
``