Complex use of the SHIFT key

Hello,

I am trying to create an undo button that will revert the selected points of my graph to the previous state but I get a weird behaviour when I use the SHIFT key.

In my button callback (python, using bokeh serve) I grab the ColumnDataSource that is used in the graph and I set the .selected[‘1d’][‘selected’] to the list of previously selected indices. After that I call .trigger(‘selected’, old, new) and everything updates fine. So far so good.

The problems come if I use the SHIFT key to add to an existing selection. The use case that goes wrong is the following. I select some points (call it group 1). Then I select some more by pressing SHIFT (group 2). Now both group 1 and 2 are selected. Then I press the undo button and the selected points become the ones I selected originally (group 1). But then if I press the SHIFT key and select another group of points (group 3) I get a total selection of all the 3 groups. Somehow the points of group 2 are remembered and reappear whne I select group 3.

I have tried everything I could think of to remove the group 2 points from the ColumnDataSource’s memory but I cannot even find where this information is stored. I tried to deepcopy the .selected dict but that didn’t help. I tried to deepcopy the whole ColumnDataSource before the SHIFT key is pressed but it is impossible.

Is there another way to create an undo functionality that will truly revert the state of the ColumnDataSourceto before the 1st SHIFT is pressed? Or is there a way to remove also the info of the selected indices when the SHIFT key is pressed? Or can I somehow simulate programmatically the null selection (pressing ESC or just selecting empty space on the graph)?

Thank you for your help

George

Hi George,

This seems like it might be a bug with the Undo tool. Can you submit a GitHub issue, so that I can draw attention to the developer that is most suited to comment and look into it?

In the immediate term, it might be possible to make a custom tool that works better. It's hard to make any more specific suggestions without a complete, minimal, runnable example to play around with. But you can find an example of a custom tool here:

  http://bokeh.pydata.org/en/latest/docs/user_guide/extensions_gallery/tool.html#userguide-extensions-examples-tool

I should also mention, the ".selected" attribute is an ugly wart that really needs to be fixed to support some other roadmap features as well as maintainability. This will probably happen in the near future, and unfortunately probably entail a breaking change, at least for setting the values. We are loathe to make breaking changes at this point, but some things absolutely have to be fixed before we can consider a 1.0 release.

Thanks,

Bryan

···

On Sep 30, 2016, at 9:12 AM, [email protected] wrote:

Hello,

I am trying to create an undo button that will revert the selected points of my graph to the previous state but I get a weird behaviour when I use the SHIFT key.

In my button callback (python, using bokeh serve) I grab the ColumnDataSource that is used in the graph and I set the .selected['1d']['selected'] to the list of previously selected indices. After that I call .trigger('selected', old, new) and everything updates fine. So far so good.

The problems come if I use the SHIFT key to add to an existing selection. The use case that goes wrong is the following. I select some points (call it group 1). Then I select some more by pressing SHIFT (group 2). Now both group 1 and 2 are selected. Then I press the undo button and the selected points become the ones I selected originally (group 1). But then if I press the SHIFT key and select another group of points (group 3) I get a total selection of all the 3 groups. Somehow the points of group 2 are remembered and reappear whne I select group 3.

I have tried everything I could think of to remove the group 2 points from the ColumnDataSource's memory but I cannot even find where this information is stored. I tried to deepcopy the .selected dict but that didn't help. I tried to deepcopy the whole ColumnDataSource before the SHIFT key is pressed but it is impossible.

Is there another way to create an undo functionality that will truly revert the state of the ColumnDataSourceto before the 1st SHIFT is pressed? Or is there a way to remove also the info of the selected indices when the SHIFT key is pressed? Or can I somehow simulate programmatically the null selection (pressing ESC or just selecting empty space on the graph)?

Thank you for your help

George

--
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/c8e585de-efce-4206-b666-d403479bf649%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Bryan,

Thanks for the reply.

I am posting a basic example of the code I am using that replicates the behaviour I am talking about.

As you suggested I will add this as a GitHub issue also


from bokeh.client import push_session
from bokeh.layouts import column
from bokeh.models import BoxSelectTool, LassoSelectTool, ColumnDataSource, Circle
from bokeh.plotting import curdoc, figure
from bokeh.models.widgets import Button
import numpy as np

global previously_selected_spike_indices

# Setup data
tsne = [np.random.random(50), np.random.random(50)]
tsne_figure_size = [500, 500]

# Scatter plot
tsne_fig_tools = "pan,wheel_zoom,box_zoom,box_select,lasso_select,tap,resize,reset,save"
tsne_figure = figure(tools=tsne_fig_tools, plot_width=tsne_figure_size[0], plot_height=tsne_figure_size[1],
                     title='T-sne', min_border=10, min_border_left=50, webgl=True)

tsne_source = ColumnDataSource({'tsne-x': tsne[0], 'tsne-y': tsne[1]})

tsne_selected_points_glyph = Circle(x='tsne-x', y='tsne-y', size=7, line_alpha=0, fill_alpha=1, fill_color='red')
tsne_nonselected_points_glyph = Circle(x='tsne-x', y='tsne-y', size=7,
                                       line_alpha=0, fill_alpha=1, fill_color='blue')

tsne_glyph_renderer = tsne_figure.add_glyph(tsne_source, tsne_nonselected_points_glyph,
                                            selection_glyph=tsne_selected_points_glyph,
                                            nonselection_glyph=tsne_nonselected_points_glyph,
                                            name='tsne_nonselected_glyph_renderer')

tsne_figure.select(BoxSelectTool).select_every_mousemove = False
tsne_figure.select(LassoSelectTool).select_every_mousemove = False

def on_tsne_data_update(attr, old, new):
    global previously_selected_spike_indices

    previously_selected_spike_indices = np.array(old['1d']['indices'])

tsne_source.on_change('selected', on_tsne_data_update)

# Undo button
undo_selected_points_button = Button(label='Undo last selection')

def on_button_undo_selection():
    global previously_selected_spike_indices
    tsne_source.data = {'tsne-x': tsne[0], 'tsne-y': tsne[1]}
    tsne_source.selected['1d']['indices'] = previously_selected_spike_indices
    old = new = tsne_source.selected
    tsne_source.trigger('selected', old, new)

undo_selected_points_button.on_click(on_button_undo_selection)

# Layout
lay = column(tsne_figure, undo_selected_points_button)

session = push_session(curdoc())
session.show(lay) # open the document in a browser
session.loop_until_closed()

With bokeh serve running if you select some points then with the SHIFT key select some more then press the Undo button (up to now everything works ok) and then with the SHIFT key select some other points you will see the 2nd group (that was removed with the Undo button) reappearing.

Again thanks for the help

George

···

On Sunday, October 2, 2016 at 1:48:11 AM UTC+1, Bryan Van de ven wrote:

Hi George,

This seems like it might be a bug with the Undo tool. Can you submit a GitHub issue, so that I can draw attention to the developer that is most suited to comment and look into it?

In the immediate term, it might be possible to make a custom tool that works better. It’s hard to make any more specific suggestions without a complete, minimal, runnable example to play around with. But you can find an example of a custom tool here:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/extensions_gallery/tool.html#userguide-extensions-examples-tool](http://bokeh.pydata.org/en/latest/docs/user_guide/extensions_gallery/tool.html#userguide-extensions-examples-tool)

I should also mention, the “.selected” attribute is an ugly wart that really needs to be fixed to support some other roadmap features as well as maintainability. This will probably happen in the near future, and unfortunately probably entail a breaking change, at least for setting the values. We are loathe to make breaking changes at this point, but some things absolutely have to be fixed before we can consider a 1.0 release.

Thanks,

Bryan

On Sep 30, 2016, at 9:12 AM, [email protected] wrote:

Hello,

I am trying to create an undo button that will revert the selected points of my graph to the previous state but I get a weird behaviour when I use the SHIFT key.

In my button callback (python, using bokeh serve) I grab the ColumnDataSource that is used in the graph and I set the .selected[‘1d’][‘selected’] to the list of previously selected indices. After that I call .trigger(‘selected’, old, new) and everything updates fine. So far so good.

The problems come if I use the SHIFT key to add to an existing selection. The use case that goes wrong is the following. I select some points (call it group 1). Then I select some more by pressing SHIFT (group 2). Now both group 1 and 2 are selected. Then I press the undo button and the selected points become the ones I selected originally (group 1). But then if I press the SHIFT key and select another group of points (group 3) I get a total selection of all the 3 groups. Somehow the points of group 2 are remembered and reappear whne I select group 3.

I have tried everything I could think of to remove the group 2 points from the ColumnDataSource’s memory but I cannot even find where this information is stored. I tried to deepcopy the .selected dict but that didn’t help. I tried to deepcopy the whole ColumnDataSource before the SHIFT key is pressed but it is impossible.

Is there another way to create an undo functionality that will truly revert the state of the ColumnDataSourceto before the 1st SHIFT is pressed? Or is there a way to remove also the info of the selected indices when the SHIFT key is pressed? Or can I somehow simulate programmatically the null selection (pressing ESC or just selecting empty space on the graph)?

Thank you for your help

George


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/c8e585de-efce-4206-b666-d403479bf649%40continuum.io.

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