Documentation for what is available in cb_obj and cb_data etc

In CustomJS callbacks, it is suggested to use cb_obj, cb_data etc. to communicate data from python code to javascript code. However, I searched around, but couldn’t find any documentation listing what is available from these communicators, is there a way to find the related information? Thanks.

From the very page you’ve linked to:

Additionally, the model that triggers the callback (i.e. the model that the callback is attached to) will be available as cb_obj .

Additionally, this section mentions both cb_obj and cb_data.

cb_data is indeed not very well document, I think mostly because it’s very model-specific. Sometimes the documentation of a particular model describes what you can expect to be in cb_data, sometimes not. A foolproof way to make sure is to read the source code. But backwards compatibility is not guaranteed of course.

I’m actually not sure cb_data is used for anything at all anymore. In the past it was a way to communicate selection geometries to callbacks on selection tools, but now there are proper events for selction geometries, and I don’t see anywhere that cb_data is set (from a quick search).

OK I spoke to soon, it’s definitely still used in a few places:

  • OpenURL apparently passes the CDS used

    ./models/callbacks/open_url.ts:
       32 :   execute(_cb_obj: unknown, {source}: {source: ColumnarDataSource}): void {
    
  • Web data sources (e.g. AjaxDataSouce) pass their HTTP responses

    ./models/sources/web_data_source.ts:
       45 :       data = adapter.execute(this, {response: raw_data})
    
  • Tap tools pass something (didn’t dig in to look)

    ./models/tools/gestures/tap_tool.ts:
       34 :           callback.execute(this.model, data)
       50 :           callback.execute(this.model, data)
    
  • Hover tools pass geometry (this old tool callback still exists, for this reason I guess)

    ./models/tools/inspectors/hover_tool.ts:
     380 :       this.model.callback!.execute(this.model, {index, geometry: g, renderer: r})
    
  • Drop downs pass an index, no idea about this and would not rely on it

    ./models/widgets/dropdown.ts:
      105 :         value_or_callback.execute(this.model, {index: i}) // TODO