python - Python Bokeh 2.0.1 - UndoTool 的 JS 回调?
问题描述
我最近开始在 Anaconda 上使用 Bokeh 2.0.1。我的首要目标是使用 Bokeh 菜单工具将一些数据集可视化为独立的 html 文件。
除了现有工具之外,我还添加了一个功能,DoubleTap 在图上的抽头坐标处放置一个标签。它按计划工作,但是,我希望通过标准 Bokeh UndoTool 撤消此操作。我尝试向相关图形的 UndoTool 实例添加一个 CustomJS 回调。但是,我无法让它工作 - 当我单击图中的撤消按钮时,添加的标签不会消失。显然,“撤消”回调不会被触发。
我知道“撤消”回调不是问题,因为我还将它绑定到一个按钮并且它按计划工作。
概念代码为:
from bokeh.plotting import figure
from bokeh.events import MenuItemClick, ButtonClick
from bokeh.models import CustomJS, Button
from bokeh.events import DoubleTap
add_label = CustomJS(--something--)
remove_label = CustomJS(--something else--)
f_h = figure(tools='undo')
f_h.js_on_event(DoubleTap, add_label) # Works as planned - adds a label on a double tap
loc_button = Button()
loc_button.js_on_event(ButtonClick, remove_label) # Also works as planned - removes the last added label
f_h.tools[0].js_on_event(MenuItemClick, remove_label) # Doesn't work - aside from the standard scaling undo behavior nothing happens
提前致谢,
光伏
解决方案
有一个reset
事件:
from bokeh.io import show
from bokeh.models import CustomJS
from bokeh.plotting import figure
p = figure(tools='reset')
p.circle(x=0, y=0)
p.js_on_event('reset', CustomJS(code="console.log('Resetting!')"))
show(p)
推荐阅读
- html - 将 id 属性添加到 wordpress 帖子的 h1 元素
- java - Java 等价于具有多处理/多线程的 pythons/haskells map() 函数?
- tensorflow - Tensorflow:TypeError:get_eval_metric_ops_for_evaluators()得到了一个意外的关键字参数'include_metrics_per_category'
- powershell - 通过power-shell并行复制多个文件而不使用任何第三方软件?
- coq - 使用 eq_rect 进行路径归纳
- c++ - 我无法初始化 WCHAR
- symfony-3.3 - 如何访问合成的服务?
- swift - 从倒计时切换到倒计时
- swift - 快速枚举镜像获取关联值名称
- javascript - Chrome 上的 scrollIntoView() 窃听