change trigger on data source overrides x_range set in callback

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)

``

I think this might be happening because span_source.trigger('change') redraws the plot, and the callback function somehow loses the handle to p5.x_range which is needed to update the x limits.

So a couple of questions that might help solve this:

  • Is there another way to add glyphs to a plot via a callback other than updating a ColumnDataSource and triggering a change?
  • Is it possible to prevent a full redraw or access the redrawn plot somehow, maybe through the return value of the trigger call, if there is one?
  • The only other thing I can think of is to draw all possible lines (there is only a limited, but large number of them) with alpha set to 0, and then select the line I want in the callback (which does not redraw) while setting selection_glyph to the styling I want. This seems very hacky and would potentially slow the plot down.
···

On Thursday, 9 February 2017 20:14:20 UTC, [email protected] wrote:

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)

``

Hi, did you manage to find a solution for this? I experience a similar issue: when I trigger change by a ColumnDataSource in plot, it’s x_range is reset to some previous state, even thought the range was changed from another JavaScript callback before. I wonder if that is related somehow.

Hi,

Including your own code in your own question (rather than general descriptions and references to old questions) will increase the likelihood that someone will be able to help.

Thanks,

Bryan

···

On May 18, 2018, at 12:27, [email protected] wrote:

Hi, did you manage to find a solution for this? I experience a similar issue: when I trigger change by a ColumnDataSource in plot, it's x_range is reset to some previous state, even thought the range was changed from another JavaScript callback before. I wonder if that is related somehow.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/378c12c3-dc8d-4a5d-b0e0-308425835798%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks, I’ve created a question here Redirecting to Google Groups

Best regards,
Eugene

···

суббота, 19 мая 2018 г., 16:02:27 UTC+3 пользователь Bryan Van de ven написал:

Hi,

Including your own code in your own question (rather than general descriptions and references to old questions) will increase the likelihood that someone will be able to help.

Thanks,

Bryan

On May 18, 2018, at 12:27, [email protected] wrote:

Hi, did you manage to find a solution for this? I experience a similar issue: when I trigger change by a ColumnDataSource in plot, it’s x_range is reset to some previous state, even thought the range was changed from another JavaScript callback before. I wonder if that is related somehow.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/378c12c3-dc8d-4a5d-b0e0-308425835798%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.