如何将选定的点保留在 ColumnDataSource 对象上并使用 ResetTool 取消选择它们?

How to keep selected points on a ColumnDataSource object and deselect them with ResetTool?

我绘制了一个圆形字形。当我 select 某些点时,它们被标记为 selected。但是当我改变我正在使用的工具或当我点击图中的其他地方时,我失去了 selection。将 selection 保留在圆形字形上的最佳方法是什么?。当按下 ResetTool 时,我想取消 select 所有点。我正在使用散景的主 (0.12.14+25.g675aacf72) 分支,其中 Selection class 已经存在。

def update_selection(self, attr, old, new):
    ''' I do this to avoid deselection '''
    if new.indices == []:
        self.source.selected.indices = self.old_selection
    else:            
        self.old_selection = list(new.indices)

source.on_change(
    'selected',
    update_selection
)

我用它在按下重置工具时调用回调:

def deselect_points(self, event):
    ''' I do this to deselect point on Reset event
        But when the indices are updated the update_selection method is called
    '''
    self.source.selected.indices = []

plot.on_event(Reset, deselect_points)

那么有没有办法在重置事件中保持 selection 并且只 deselect 点?

2018 年 3 月 14 日更新

只有在启用点击工具时才会发生这种情况。所以我在 GitHub 上写了一个 issue 来检查这是否是预期的行为

最后我做了这样的解决方法:

# [...]

self.reset_selection = False

# [...]

def _reset_lines(self, event):
    # hide the glyphs which mark the selected points
    self.lr.visible = False
    self.lr_circle_selected.visible = False
    self.lr.data_source.data = self.empty_source.data
    self.lr_circle_selected.view = self.empty_view

    self.reset_selection = True

def update_selection(self, attr, old, new):
    if new.indices == []:
        if not self.reset_selection:
            new.indices = list(self.selection)    # keep the selection
        else:
            self.reset_selection = False
            self.selection = []
    else:
        self.selection = list(new.indices)

self.plot.on_event(Reset, self._reset_lines)

所以我打算同时使用它,但我找不到更好的东西

更新

好像the issue已经关门了。所以我希望这已经解决了