使用TapTool

时间:2018-06-01 14:11:41

标签: javascript bokeh

我在TapTool上使用CustomJS回调时遇到问题。我想在点击之后强制选择50个点。因此,我做了一个javascript回调,修改了数据源中选择的索引列表,并应该更新绘图。我可以通过控制台看到数据源已更新,但情节不是。

我已经从文档示例(https://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html)制作了测试版本,但它既不起作用也不起作用。是否因为更改选择时更新绘图有不同的方法?

以下是我所做的测试版本:

from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource, Slider
from bokeh.plotting import Figure, output_file, show

output_notebook()

x = [x*0.005 for x in range(0, 200)]
y = x

source = ColumnDataSource(data=dict(x=x, y=y))

plot = Figure(plot_width=400, plot_height=400)
plot.circle('x', 'y', source=source, line_width=3, line_alpha=0.6)

callback = CustomJS(args=dict(source=source), code="""
    var l_selected=source.selected;
    var indices = l_selected['1d'].indices;
    if(indices.length <= 1) {
        var new_indices = Array.from(new Array(50), (x,i) => i + indices[0]);
        l_selected['1d'].indices=new_indices;
    }
    source.selected=l_selected;
    console.log(source.selected)
    source.change.emit();
""")


slider = Slider(start=0.1, end=4, value=1, step=.1, title="power")
slider.js_on_change('value', callback)

plot.add_tools(TapTool(callback=callback))

layout = column(slider, plot)

show(layout)

我不知道它是否有用,但我使用的是0.12.16版本的Bokeh,我试图让它在Jupyter笔记本中运行

1 个答案:

答案 0 :(得分:1)

Seb在评论中给出了答案。由于散景0.12.15 BIM360Setup.GET; SalespersonPurchaser.GET(BIM360Setup."Default Job Admin"); IF Token = '' THEN Token := Get3LeggedToken; StorageID := COPYSTR(FileURNID,STRPOS(FileURNID,'/') + 1);//*** HttpWebRequestMgt.Initialize(STRSUBSTNO('https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/%1',StorageID)); HttpWebRequestMgt.DisableUI; HttpWebRequestMgt.SetMethod('PUT'); HttpWebRequestMgt.SetContentType('application/x-www-form-urlencoded'); HttpWebRequestMgt.AddHeader('Authorization','Bearer ' + Token); HttpWebRequestMgt.SetReturnType('*/*'); FileManagement.BLOBImportFromServerFile(TempBlob,ServerFolder+'\'+Filename); HttpWebRequestMgt.AddBodyBlob(TempBlob); CLEAR(TempBlob); TempBlob.Blob.CREATEINSTREAM(ResponseInStream); HttpWebRequestMgt.GetResponse(ResponseInStream,HttpStatusCode,ResponseHeaders); ResponseText := TempBlob.ReadAsText('',TEXTENCODING::UTF8); CLEAR(HttpWebRequestMgt); CLEAR(TempBlob); 成为source.selected['1d']