How to "subscribe" a callback to a ColumnDataSource in JS?

I have a source object in JS, and I need to attach a function to its change event, akin to doing the following in jquery

 $( "#object_id" ).click( function() {...} )

Two ways to approach it:

In JS: what is the correct way to attach the callback to the change event?

in Python: If I define a callback in python, and then trigger “change” of the source in JS, the python callback does not kick off

Suggestions?

I should have explained that obviously, using simply the callback functionality is not an option as this is part of a broader JS library

···

On Friday, 23 October 2015 18:13:51 UTC+1, Pythonic wrote:

I have a source object in JS, and I need to attach a function to its change event, akin to doing the following in jquery

 $( "#object_id" ).click( function() {...} )

Two ways to approach it:

In JS: what is the correct way to attach the callback to the change event?

in Python: If I define a callback in python, and then trigger “change” of the source in JS, the python callback does not kick off

Suggestions?

Follow up info: the callback defined in python does not have access to the broader JS space

···

On Friday, 23 October 2015 18:14:39 UTC+1, Pythonic wrote:

I should have explained that obviously, using simply the callback functionality is not an option as this is part of a broader JS library

On Friday, 23 October 2015 18:13:51 UTC+1, Pythonic wrote:

I have a source object in JS, and I need to attach a function to its change event, akin to doing the following in jquery

 $( "#object_id" ).click( function() {...} )

Two ways to approach it:

In JS: what is the correct way to attach the callback to the change event?

in Python: If I define a callback in python, and then trigger “change” of the source in JS, the python callback does not kick off

Suggestions?

Greetings,

On many of my plots, the hovertool activates in areas that are nowhere
close to my mouse and shows bogus information. For example, in the
attached screenshot my mouse is hovering over the glyph in the top
right, yet the hovertool activated for three different glyphs that are
very far apart on the plot. I have included a snippet from my code
below. Am I misusing the hover tool or is this a bug?

···

-----

import bokeh.plotting as bplt
from bokeh.models import HoverTool
from bokeh.models.widgets import Select
from bokeh.io import output_file, save, vform

...

def plot(benchmarks, ...):

    # configure the hover box
    hover = HoverTool(
        tooltips = [
            ("Device", "@device"),
            ("Backend", "@platform"),
            ("(x,y)", "(@x,@y)")
        ])

    # configure the plot title and axis labels, use CDN for the data source
    bplt.output_file(savefile + ".html", title=title, mode='cdn')
    plot = bplt.figure(title=title,
tools=[hover,'save,box_zoom,resize,reset'])

    # plot images/second vs. data size
    for benchmark in benchmarks:
        x = ...
        y = ...
        ...

        source = bplt.ColumnDataSource(
            data = dict(x=x,y=y,
                device=[device]*len(x),
                platform=[platform]*len(x),
            ))

        # generate the plot
        plot.line(x,y, legend=legend, color=color, line_width=2)
        plot.scatter('x', 'y', source=source, legend=legend, color=color,
            fill_color="white", size=8)

    plot.xaxis.axis_label = xlabel
    plot.yaxis.axis_label = ylabel
    plot.legend.orientation = legend_location

And in conclusion, it was a matter of variable context and the callback defined in Python can access the broader library

···

On Friday, 23 October 2015 18:17:07 UTC+1, Pythonic wrote:

Follow up info: the callback defined in python does not have access to the broader JS space

On Friday, 23 October 2015 18:14:39 UTC+1, Pythonic wrote:

I should have explained that obviously, using simply the callback functionality is not an option as this is part of a broader JS library

On Friday, 23 October 2015 18:13:51 UTC+1, Pythonic wrote:

I have a source object in JS, and I need to attach a function to its change event, akin to doing the following in jquery

 $( "#object_id" ).click( function() {...} )

Two ways to approach it:

In JS: what is the correct way to attach the callback to the change event?

in Python: If I define a callback in python, and then trigger “change” of the source in JS, the python callback does not kick off

Suggestions?

Is it possible to make a minimal complete example that reproduces this, and put it in a GH issue?

I will say that by default tho hover tool tries to attach itself to every renderer, which may not be appropriate in all cases. For instance if you just want to hover over the scatter markers, you can specify that with the 'names' or 'renderers' attributes on the tool:

http://bokeh.pydata.org/en/latest/docs/reference/models/tools.html#bokeh.models.tools.HoverTool.names
http://bokeh.pydata.org/en/latest/docs/reference/models/tools.html#bokeh.models.tools.HoverTool.renderers

Bryan

···

On Oct 23, 2015, at 12:31 PM, Brian Kloppenborg <[email protected]> wrote:

Greetings,

On many of my plots, the hovertool activates in areas that are nowhere
close to my mouse and shows bogus information. For example, in the
attached screenshot my mouse is hovering over the glyph in the top
right, yet the hovertool activated for three different glyphs that are
very far apart on the plot. I have included a snippet from my code
below. Am I misusing the hover tool or is this a bug?

-----

import bokeh.plotting as bplt
from bokeh.models import HoverTool
from bokeh.models.widgets import Select
from bokeh.io import output_file, save, vform

...

def plot(benchmarks, ...):

   # configure the hover box
   hover = HoverTool(
       tooltips = [
           ("Device", "@device"),
           ("Backend", "@platform"),
           ("(x,y)", "(@x,@y)")
       ])

   # configure the plot title and axis labels, use CDN for the data source
   bplt.output_file(savefile + ".html", title=title, mode='cdn')
   plot = bplt.figure(title=title,
tools=[hover,'save,box_zoom,resize,reset'])

   # plot images/second vs. data size
   for benchmark in benchmarks:
       x = ...
       y = ...
       ...

       source = bplt.ColumnDataSource(
           data = dict(x=x,y=y,
               device=[device]*len(x),
               platform=[platform]*len(x),
           ))

       # generate the plot
       plot.line(x,y, legend=legend, color=color, line_width=2)
       plot.scatter('x', 'y', source=source, legend=legend, color=color,
           fill_color="white", size=8)

   plot.xaxis.axis_label = xlabel
   plot.yaxis.axis_label = ylabel
   plot.legend.orientation = legend_location

--
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/562A6EDD.90103%40gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
<Screenshot from 2015-10-23 13:18:36.png>

I believe someone already reported this issue:

···

On 10/24/15 11:58 PM, Bryan Van de Ven wrote:

Is it possible to make a minimal complete example that reproduces this, and put it in a GH issue?

I will say that by default tho hover tool tries to attach itself to every renderer, which may not be appropriate in all cases. For instance if you just want to hover over the scatter markers, you can specify that with the 'names' or 'renderers' attributes on the tool:

tools — Bokeh 3.3.2 Documentation
tools — Bokeh 3.3.2 Documentation

Bryan

On Oct 23, 2015, at 12:31 PM, Brian Kloppenborg <[email protected]> wrote:

Greetings,

On many of my plots, the hovertool activates in areas that are nowhere
close to my mouse and shows bogus information. For example, in the
attached screenshot my mouse is hovering over the glyph in the top
right, yet the hovertool activated for three different glyphs that are
very far apart on the plot. I have included a snippet from my code
below. Am I misusing the hover tool or is this a bug?

-----

import bokeh.plotting as bplt
from bokeh.models import HoverTool
from bokeh.models.widgets import Select
from bokeh.io import output_file, save, vform

...

def plot(benchmarks, ...):

   # configure the hover box
   hover = HoverTool(
       tooltips = [
           ("Device", "@device"),
           ("Backend", "@platform"),
           ("(x,y)", "(@x,@y)")
       ])

   # configure the plot title and axis labels, use CDN for the data source
   bplt.output_file(savefile + ".html", title=title, mode='cdn')
   plot = bplt.figure(title=title,
tools=[hover,'save,box_zoom,resize,reset'])

   # plot images/second vs. data size
   for benchmark in benchmarks:
       x = ...
       y = ...
       ...

       source = bplt.ColumnDataSource(
           data = dict(x=x,y=y,
               device=[device]*len(x),
               platform=[platform]*len(x),
           ))

       # generate the plot
       plot.line(x,y, legend=legend, color=color, line_width=2)
       plot.scatter('x', 'y', source=source, legend=legend, color=color,
           fill_color="white", size=8)

   plot.xaxis.axis_label = xlabel
   plot.yaxis.axis_label = ylabel
   plot.legend.orientation = legend_location

--
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/562A6EDD.90103%40gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
<Screenshot from 2015-10-23 13:18:36.png>

Ah, in that case it appears the issue is with line rather than scatter.
I'll shut off the hover tool for the line and see if the issue persists.
Thanks Sarah!

···

On 10/25/2015 05:38 PM, Sarah Bird wrote:

I believe someone already reported this issue:
https://github.com/bokeh/bokeh/issues/3002

On 10/24/15 11:58 PM, Bryan Van de Ven wrote:

Is it possible to make a minimal complete example that reproduces this, and put it in a GH issue?

I will say that by default tho hover tool tries to attach itself to every renderer, which may not be appropriate in all cases. For instance if you just want to hover over the scatter markers, you can specify that with the 'names' or 'renderers' attributes on the tool:

tools — Bokeh 3.3.2 Documentation
tools — Bokeh 3.3.2 Documentation

Bryan

On Oct 23, 2015, at 12:31 PM, Brian Kloppenborg <[email protected]> wrote:

Greetings,

On many of my plots, the hovertool activates in areas that are nowhere
close to my mouse and shows bogus information. For example, in the
attached screenshot my mouse is hovering over the glyph in the top
right, yet the hovertool activated for three different glyphs that are
very far apart on the plot. I have included a snippet from my code
below. Am I misusing the hover tool or is this a bug?

-----

import bokeh.plotting as bplt
from bokeh.models import HoverTool
from bokeh.models.widgets import Select
from bokeh.io import output_file, save, vform

...

def plot(benchmarks, ...):

   # configure the hover box
   hover = HoverTool(
       tooltips = [
           ("Device", "@device"),
           ("Backend", "@platform"),
           ("(x,y)", "(@x,@y)")
       ])

   # configure the plot title and axis labels, use CDN for the data source
   bplt.output_file(savefile + ".html", title=title, mode='cdn')
   plot = bplt.figure(title=title,
tools=[hover,'save,box_zoom,resize,reset'])

   # plot images/second vs. data size
   for benchmark in benchmarks:
       x = ...
       y = ...
       ...

       source = bplt.ColumnDataSource(
           data = dict(x=x,y=y,
               device=[device]*len(x),
               platform=[platform]*len(x),
           ))

       # generate the plot
       plot.line(x,y, legend=legend, color=color, line_width=2)
       plot.scatter('x', 'y', source=source, legend=legend, color=color,
           fill_color="white", size=8)

   plot.xaxis.axis_label = xlabel
   plot.yaxis.axis_label = ylabel
   plot.legend.orientation = legend_location

--
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/562A6EDD.90103%40gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
<Screenshot from 2015-10-23 13:18:36.png>

After reading the github issue Sara pointed to, the method suggested by
Bryan (use name-based or renderer-based hit detection) is a suitable
workaround for my purposes. Thank you!

···

On 10/25/2015 05:38 PM, Sarah Bird wrote:

I believe someone already reported this issue:
https://github.com/bokeh/bokeh/issues/3002

On 10/24/15 11:58 PM, Bryan Van de Ven wrote:

Is it possible to make a minimal complete example that reproduces this, and put it in a GH issue?

I will say that by default tho hover tool tries to attach itself to every renderer, which may not be appropriate in all cases. For instance if you just want to hover over the scatter markers, you can specify that with the 'names' or 'renderers' attributes on the tool:

tools — Bokeh 3.3.2 Documentation
tools — Bokeh 3.3.2 Documentation

Bryan

On Oct 23, 2015, at 12:31 PM, Brian Kloppenborg <[email protected]> wrote:

Greetings,

On many of my plots, the hovertool activates in areas that are nowhere
close to my mouse and shows bogus information. For example, in the
attached screenshot my mouse is hovering over the glyph in the top
right, yet the hovertool activated for three different glyphs that are
very far apart on the plot. I have included a snippet from my code
below. Am I misusing the hover tool or is this a bug?

-----

import bokeh.plotting as bplt
from bokeh.models import HoverTool
from bokeh.models.widgets import Select
from bokeh.io import output_file, save, vform

...

def plot(benchmarks, ...):

   # configure the hover box
   hover = HoverTool(
       tooltips = [
           ("Device", "@device"),
           ("Backend", "@platform"),
           ("(x,y)", "(@x,@y)")
       ])

   # configure the plot title and axis labels, use CDN for the data source
   bplt.output_file(savefile + ".html", title=title, mode='cdn')
   plot = bplt.figure(title=title,
tools=[hover,'save,box_zoom,resize,reset'])

   # plot images/second vs. data size
   for benchmark in benchmarks:
       x = ...
       y = ...
       ...

       source = bplt.ColumnDataSource(
           data = dict(x=x,y=y,
               device=[device]*len(x),
               platform=[platform]*len(x),
           ))

       # generate the plot
       plot.line(x,y, legend=legend, color=color, line_width=2)
       plot.scatter('x', 'y', source=source, legend=legend, color=color,
           fill_color="white", size=8)

   plot.xaxis.axis_label = xlabel
   plot.yaxis.axis_label = ylabel
   plot.legend.orientation = legend_location

--
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/562A6EDD.90103%40gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
<Screenshot from 2015-10-23 13:18:36.png>