TapTool CustomJS - problem with many sources

Hello,

I have a quite strange and I think difficult problem with callbacks. Let me first describe how I am creating my plots and series. So, I am creating plots with many lines (one, two,…, n - dynamic generation) with markers in certain points. For each line I have different source - ColumnDataSource, and also I have different sourcers for markers as for each line i creating two types of markers. Someone could ask why I use many sources, so the answer is quite simple - each set of markers can store different data, which are used by HoverTools (n instances).

Now I want to add callback which allow me to fill some forms in html by data from source assigned to selected marker. I found huge problem and I do not know how to resolve it. I want to have one TapTool, which call JS function definied in CustomJS for selected marker. The main problem is to get information about source dynamically through clicked marker.

Has anybody knowledge whether is it possible or not? I am aware that my plot generation func. may be complex, but i need to have a lot of data presented directly on what plot.

Best regards

Adam

Hi,

···

On Mon, Jan 25, 2016 at 4:51 PM, [email protected] wrote:

Hello,

I have a quite strange and I think difficult problem with callbacks. Let me first describe how I am creating my plots and series. So, I am creating plots with many lines (one, two,…, n - dynamic generation) with markers in certain points. For each line I have different source - ColumnDataSource, and also I have different sourcers for markers as for each line i creating two types of markers. Someone could ask why I use many sources, so the answer is quite simple - each set of markers can store different data, which are used by HoverTools (n instances).

Now I want to add callback which allow me to fill some forms in html by data from source assigned to selected marker. I found huge problem and I do not know how to resolve it. I want to have one TapTool, which call JS function definied in CustomJS for selected marker. The main problem is to get information about source dynamically through clicked marker.

Has anybody knowledge whether is it possible or not? I am aware that my plot generation func. may be complex, but i need to have a lot of data presented directly on what plot.

if I understand the problem correctly then yes. CustomJS creates a JS function that takes n user-supplied arguments (I presume n=0 in your case), two special arguments cb_obj and cb_data, which understanding varies depending on the context and require which is a reference to require() function for importing modules. In the case of TapTool cb_obj is a reference to the data source used by the selected glyph and cb_data is null. So you should use cb_obj.get('data') in your code.

Mateusz

Best regards

Adam

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/61ddcfd4-f8e9-4f2b-92bf-058bf182a15c%40continuum.io.

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

Hi Mateusz,

Thank you for your reply. I tried to use cb_obj variable, but to be honest it returns just all source for clicked marker type. I need to go a bit deeper and get information about data assigned to clicked marker. Do you know how can I achieve it?

···

On Monday, January 25, 2016 at 5:49:27 PM UTC+1, mateusz.paprocki wrote:

Hi,

On Mon, Jan 25, 2016 at 4:51 PM, [email protected] wrote:

Hello,

I have a quite strange and I think difficult problem with callbacks. Let me first describe how I am creating my plots and series. So, I am creating plots with many lines (one, two,…, n - dynamic generation) with markers in certain points. For each line I have different source - ColumnDataSource, and also I have different sourcers for markers as for each line i creating two types of markers. Someone could ask why I use many sources, so the answer is quite simple - each set of markers can store different data, which are used by HoverTools (n instances).

Now I want to add callback which allow me to fill some forms in html by data from source assigned to selected marker. I found huge problem and I do not know how to resolve it. I want to have one TapTool, which call JS function definied in CustomJS for selected marker. The main problem is to get information about source dynamically through clicked marker.

Has anybody knowledge whether is it possible or not? I am aware that my plot generation func. may be complex, but i need to have a lot of data presented directly on what plot.

if I understand the problem correctly then yes. CustomJS creates a JS function that takes n user-supplied arguments (I presume n=0 in your case), two special arguments cb_obj and cb_data, which understanding varies depending on the context and require which is a reference to require() function for importing modules. In the case of TapTool cb_obj is a reference to the data source used by the selected glyph and cb_data is null. So you should use cb_obj.get('data') in your code.

Mateusz

Best regards

Adam

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/61ddcfd4-f8e9-4f2b-92bf-058bf182a15c%40continuum.io.

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

Hi Mateusz,

Thank you for your reply. I tried to use cb_obj variable, but to be honest it returns just all source for clicked marker type. I need to go a bit deeper and get information about data assigned to clicked marker. Do you know how can I achieve it?

You need to get the "selected" indices off the data source (i.e. the indices of the glyphs that were clicked). This code might be instructive:

  https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/util/util.coffee#L42-L52

Specifically in your case, you probably want

   cb_obj.get("selected")['1d'].indices

Bryan

···

On Jan 26, 2016, at 1:36 AM, [email protected] wrote:
  
On Monday, January 25, 2016 at 5:49:27 PM UTC+1, mateusz.paprocki wrote:
Hi,

On Mon, Jan 25, 2016 at 4:51 PM, <[email protected]> wrote:
Hello,

I have a quite strange and I think difficult problem with callbacks. Let me first describe how I am creating my plots and series. So, I am creating plots with many lines (one, two,..., n - dynamic generation) with markers in certain points. For each line I have different source - ColumnDataSource, and also I have different sourcers for markers as for each line i creating two types of markers. Someone could ask why I use many sources, so the answer is quite simple - each set of markers can store different data, which are used by HoverTools (n instances).

Now I want to add callback which allow me to fill some forms in html by data from source assigned to selected marker. I found huge problem and I do not know how to resolve it. I want to have one TapTool, which call JS function definied in CustomJS for selected marker. The main problem is to get information about source dynamically through clicked marker.

Has anybody knowledge whether is it possible or not? I am aware that my plot generation func. may be complex, but i need to have a lot of data presented directly on what plot.

if I understand the problem correctly then yes. CustomJS creates a JS function that takes n user-supplied arguments (I presume n=0 in your case), two special arguments cb_obj and cb_data, which understanding varies depending on the context and require which is a reference to require() function for importing modules. In the case of TapTool cb_obj is a reference to the data source used by the selected glyph and cb_data is null. So you should use `cb_obj.get('data')` in your code.

Mateusz

Best regards
Adam

--
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/61ddcfd4-f8e9-4f2b-92bf-058bf182a15c%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

--
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/a420257f-411b-40bf-8ca6-7ed04205cc5d%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Bryan,

Thanks a lot! Could you also answer on below questions?

  1. Is there any documentation with params for cb_obj and cb_data ?

  2. When I click on a marker i am retrieving 3 arrays - two empty, one with data (my plot has 3 series with 3 sources). Is there any possibility to get only data about clicked marker (non empty array)?

Adam

···

On Tuesday, January 26, 2016 at 7:47:50 PM UTC+1, Bryan Van de ven wrote:

On Jan 26, 2016, at 1:36 AM, adam.p…@onet.eu wrote:

Hi Mateusz,

Thank you for your reply. I tried to use cb_obj variable, but to be honest it returns just all source for clicked marker type. I need to go a bit deeper and get information about data assigned to clicked marker. Do you know how can I achieve it?

You need to get the “selected” indices off the data source (i.e. the indices of the glyphs that were clicked). This code might be instructive:

    [https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/util/util.coffee#L42-L52](https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/util/util.coffee#L42-L52)

Specifically in your case, you probably want

     cb_obj.get("selected")['1d'].indices

Bryan

On Monday, January 25, 2016 at 5:49:27 PM UTC+1, mateusz.paprocki wrote:

Hi,

On Mon, Jan 25, 2016 at 4:51 PM, [email protected] wrote:

Hello,

I have a quite strange and I think difficult problem with callbacks. Let me first describe how I am creating my plots and series. So, I am creating plots with many lines (one, two,…, n - dynamic generation) with markers in certain points. For each line I have different source - ColumnDataSource, and also I have different sourcers for markers as for each line i creating two types of markers. Someone could ask why I use many sources, so the answer is quite simple - each set of markers can store different data, which are used by HoverTools (n instances).

Now I want to add callback which allow me to fill some forms in html by data from source assigned to selected marker. I found huge problem and I do not know how to resolve it. I want to have one TapTool, which call JS function definied in CustomJS for selected marker. The main problem is to get information about source dynamically through clicked marker.

Has anybody knowledge whether is it possible or not? I am aware that my plot generation func. may be complex, but i need to have a lot of data presented directly on what plot.

if I understand the problem correctly then yes. CustomJS creates a JS function that takes n user-supplied arguments (I presume n=0 in your case), two special arguments cb_obj and cb_data, which understanding varies depending on the context and require which is a reference to require() function for importing modules. In the case of TapTool cb_obj is a reference to the data source used by the selected glyph and cb_data is null. So you should use cb_obj.get('data') in your code.

Mateusz

Best regards

Adam


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/61ddcfd4-f8e9-4f2b-92bf-058bf182a15c%40continuum.io.

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


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/a420257f-411b-40bf-8ca6-7ed04205cc5d%40continuum.io.

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

Hi Adam,

Take a look at this section of the user guide, hopefully it should have
answers to both questions:
http://bokeh.pydata.org/en/latest/docs/user_guide/interaction.html#javascript-callbacks

There's also:
http://bokeh.pydata.org/en/latest/docs/reference/models/callbacks.html#bokeh.models.callbacks.CustomJS

Bird

···

On 1/26/16 11:15 PM, [email protected] wrote:

Hi Bryan,

Thanks a lot! Could you also answer on below questions?
1. Is there any documentation with params for cb_obj and cb_data ?
2. When I click on a marker i am retrieving 3 arrays - two empty, one
with data (my plot has 3 series with 3 sources). Is there any
possibility to get only data about clicked marker (non empty array)?

Adam

On Tuesday, January 26, 2016 at 7:47:50 PM UTC+1, Bryan Van de ven wrote:

    > On Jan 26, 2016, at 1:36 AM, adam.p...@onet.eu <javascript:> wrote:
    >
    > Hi Mateusz,
    >
    > Thank you for your reply. I tried to use cb_obj variable, but to
    be honest it returns just all source for clicked marker type. I need
    to go a bit deeper and get information about data assigned to
    clicked marker. Do you know how can I achieve it?

    You need to get the "selected" indices off the data source (i.e. the
    indices of the glyphs that were clicked). This code might be
    instructive:

            https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/util/util.coffee#L42-L52
    <https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/util/util.coffee#L42-L52>

    Specifically in your case, you probably want

             cb_obj.get("selected")['1d'].indices

    Bryan
            
    > On Monday, January 25, 2016 at 5:49:27 PM UTC+1, mateusz.paprocki > wrote:
    > Hi,
    >
    > On Mon, Jan 25, 2016 at 4:51 PM, <[email protected]> wrote:
    > Hello,
    >
    > I have a quite strange and I think difficult problem with
    callbacks. Let me first describe how I am creating my plots and
    series. So, I am creating plots with many lines (one, two,..., n -
    dynamic generation) with markers in certain points. For each line I
    have different source - ColumnDataSource, and also I have different
    sourcers for markers as for each line i creating two types of
    markers. Someone could ask why I use many sources, so the answer is
    quite simple - each set of markers can store different data, which
    are used by HoverTools (n instances).
    >
    > Now I want to add callback which allow me to fill some forms in
    html by data from source assigned to selected marker. I found huge
    problem and I do not know how to resolve it. I want to have one
    TapTool, which call JS function definied in CustomJS for selected
    marker. The main problem is to get information about source
    dynamically through clicked marker.
    >
    > Has anybody knowledge whether is it possible or not? I am aware
    that my plot generation func. may be complex, but i need to have a
    lot of data presented directly on what plot.
    >
    > if I understand the problem correctly then yes. CustomJS creates a
    JS function that takes n user-supplied arguments (I presume n=0 in
    your case), two special arguments cb_obj and cb_data, which
    understanding varies depending on the context and require which is a
    reference to require() function for importing modules. In the case
    of TapTool cb_obj is a reference to the data source used by the
    selected glyph and cb_data is null. So you should use
    `cb_obj.get('data')` in your code.
    >
    > Mateusz
    >
    >
    > Best regards
    > Adam
    >
    > --
    > 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/61ddcfd4-f8e9-4f2b-92bf-058bf182a15c%40continuum.io
    <https://groups.google.com/a/continuum.io/d/msgid/bokeh/61ddcfd4-f8e9-4f2b-92bf-058bf182a15c%40continuum.io>.

    > For more options, visit
    https://groups.google.com/a/continuum.io/d/optout
    <https://groups.google.com/a/continuum.io/d/optout>.
    >
    >
    > --
    > 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] <javascript:>.
    > To post to this group, send email to [email protected]
    <javascript:>.
    > To view this discussion on the web visit
    https://groups.google.com/a/continuum.io/d/msgid/bokeh/a420257f-411b-40bf-8ca6-7ed04205cc5d%40continuum.io
    <https://groups.google.com/a/continuum.io/d/msgid/bokeh/a420257f-411b-40bf-8ca6-7ed04205cc5d%40continuum.io>.

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

--
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]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/a/continuum.io/d/msgid/bokeh/41cf430c-fb02-422c-8e48-1965ad54233d%40continuum.io
<https://groups.google.com/a/continuum.io/d/msgid/bokeh/41cf430c-fb02-422c-8e48-1965ad54233d%40continuum.io?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.