如何从tap event hvnx.draw获取所选索引?

2024-04-19 20:56:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我能够毫无问题地快速显示networkx图形。 但是,我无法在tap event上检索所选索引

from bokeh.models import HoverTool, TapTool, CustomJS
from bokeh.io import show

callback = CustomJS( code="""
// the event that triggered the callback is cb_obj:
// The event type determines the relevant attributes
console.log('Tap event occurred')
console.log(arguments)
// console.log(cb_obj)
console.log(cb_data.source.data)
""")

GG = nx.Graph()
GG.add_edge('A','B')
GG.add_edge('B','C')
GG.add_edge('C','A')
hvnx.draw(GG).opts(tools=[TapTool(callback=callback), HoverTool(tooltips=[('index', '@index_hover')])])

# HOW-TO get node-id in JS callback?
# sx: 67.2230224609375
# sy: 45.66761779785156
# type: "point"
# x: -0.4242418711022395
# y: 0.8824665128664352

# index_hover: Array(3)
# 0: "A"
# 1: "B"
# 2: "C"


Tags: thefromimporteventlogaddindexcallback