散景CustomJS传递字形数组

时间:2020-04-13 19:09:13

标签: javascript python bokeh bokehjs

我正在尝试创建多个数字,以播出有关国家的各种信息。最重要的是,我正在尝试使用一组按钮来隐藏所有数字上的国家图。使用CustomJS回调时,我尝试将带有各个国家的ColumnDataSource传递为列,并在列中包含相应的字形。 ColumnDataSource如下所示:

{'index':array([0,1],dtype = int64),'US': array([GlyphRenderer(id ='1038',...),GlyphRenderer(id ='1157',...)], dtype = object),“阿拉伯联合酋长国”:array([nan,nan]),“ United 王国'':数组([GlyphRenderer(id ='1079',...), GlyphRenderer(id ='1198',...)]}

然后我尝试像下面这样传入CustomJS:

callback = CustomJS(args={'source':source}, code="""..."""

但是,谷歌浏览器中的控制台显示以下错误。我正在努力了解它是否不可迭代,是因为每列中都有对象,还是因为列是字符串?

未捕获(承诺)TypeError :(中间值)(中间值)(中间值)不可迭代

当我直接传递一列时,它会按预期工作。但是,我尝试在许多国家/地区投放。

callback = CustomJS(args={'source':source.data['US']}, code="""..."""

非常感谢你, 托马斯

1 个答案:

答案 0 :(得分:0)

正如评论中指出的那样,我本可以通过字典。显然是事实,我通过传递ColumnDataSource来思考问题。

通过遍历所有字形来解决该问题,如下面的示例所示,使所有字形不可见。

callback = CustomJS(args={'source':one_line, 'countries': all_countries}, code="""
var arr_glyphs = source;
var arr_countries = countries;
var index;
var index_country;                     

for (index = 0; index < arr_countries.length; ++index) {
    for (index_country = 0; index_country < arr_countries[index].length; ++index_country) {
        arr_glyphs[arr_countries[index]][index_country].visible = false;
    };
};""")

谢谢您的帮助!