Hi all,
is there a way to prevent source.trigger(‘change’) to update the range of the whole plot when source is linked to a glyph?
The code below is supposed to re-center a plot once a point is clicked, and add a line to it. This is done in the callback by updating the x_range and y_range and updating the data source for the line glyph.
However, span_source.trigger(‘change’) causes the whole plot to reset, changing the x and y axes despite setting the range afterwards. When the trigger is removed, the plot recenters fine, but the change to the data source is not picked up and the line doesn’t get plotted. Is this an issue and/or is it preventable?
lz_source = ColumnDataSource(data=dict(x=b.V1, y=-np.log10(b.V5)))
rawdat = ColumnDataSource(data=dict(x=d.V2, spval=-np.log10(d.V4), pval=-np.log10(d.V8), weight=5+2*d.V3))
p4=figure(width=950, tools=“reset,tap”, height=200)
p4.circle(“x”, “y”, fill_alpha=0.6, size=10, source=lz_source)
p5=figure(width=950)
span_source=ColumnDataSource(data=dict(y0=, y1=, xmin=, xmax=))
Callback for clicking on a point
cb_click_lz = CustomJS(args=dict(lz_data=lz_source, xrange=p5.x_range, yrange=p5.y_range, rawdat=rawdat, span_source=span_source), code="""
index_selected=lz_data.selected[‘1d’].indices[0]
dat=rawdat.data
burden_p=lz_data.data[‘y’][index_selected]
// […] minp, maxp, minpos and maxpos get set dynamically according to data in rawdat that match the ‘y’ above
// add line
data=span_source.get(“data”)
data[‘y0’]=
data[‘y1’]=
data[‘xmin’]=
data[‘xmax’]=
data[‘y0’].push(burden_p)
data[‘y1’].push(burden_p)
data[‘xmin’].push(minpos)
data[‘xmax’].push(maxpos)
// if this line is here…
span_source.trigger(‘change’)
`
// …these 2 lines get ignored…
xrange.set({“start”: minpos, “end”: maxpos})
yrange.set({“start”: minp, “end”: maxp})
`
“”")
p4.add_tools(TapTool(callback=cb_click_lz))
p5.circle(‘x’, ‘spval’, size=‘weight’, fill_alpha=0.4, source=rawdat)
p5.segment(x0=‘xmin’, x1=‘xmax’, y0=‘y0’, y1=‘y1’, color=‘firebrick’, line_width=3, source=span_source)
pmax2= gridplot([[p4], [p5]])
show(pmax2)
``