You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code below attempts to create a custom hover tool using Holoviews.
However, this code is not successful and the custom function has no effect.
import holoviews as hv
import numpy as np
import panel as pn
import bokeh
from bokeh.resources import INLINE
from bokeh.models import HoverTool
from bokeh.models import CustomJSHover
pn.extension(safe_embed=True)
for library in [hv,pn,bokeh]:
print ("%s version %s"% ( library, library.__version__))
hv.extension('bokeh')
frequencies = [0.5, 0.75, 1.0, 1.25]
MyCustom = CustomJSHover(code='''
return "test"
''')
MyHover1 = HoverTool(
tooltips=[
( 'xvals', '@xvals'),
( 'yvals', '@yvals'),
# the line below should be:
# ( 'phase', '@phase{custom}'),
# ( 'freq', '@freq{custom}'),
( 'phase', '@phase'),
( 'freq', '@freq'),
],
formatters={
'xvals' : 'numeral',
'yvals' : 'numeral',
# the lines below should be:
# '@phase' : MyCustom,
# '@freq' : MyCustom,
'phase' : MyCustom,
'freq' : MyCustom,
},
point_policy="follow_mouse"
)
def sine_curve(phase, freq):
xvals = [0.1* i for i in range(100)]
data = {
'xvals' : xvals,
'yvals' : [np.sin(phase+freq*x) for x in xvals],
'phase' : [phase for x in xvals],
'freq' : [freq for x in xvals],
}
plot = hv.Points( data, kdims = ['xvals','yvals'], vdims = ['phase','freq'])
return plot
phases = [0, np.pi/2, np.pi, 3*np.pi/2]
curve_dict_2D = {(p,f):sine_curve(p,f) for p in phases for f in frequencies}
hmap = hv.HoloMap(curve_dict_2D, kdims=['phase', 'frequency']).opts(tools = [MyHover1])
panel_Object = pn.pane.HoloViews(hmap)
panel_Object.save('SineHover.html', resources=INLINE, title = 'Hover Example', embed=True)
hv.save(hmap,'test_holoviews.html')
To fix this and let MyCustom function to execute, there is a need to do two changes in the Hover tool that are commented out in the code. When running the current ode, there is no error or warning message explaining what is wrong, yet instead of printing "test" for Phase an Freq, the system shows a hover tip where the freq and phase numbers are written:
The expected result after fixing the lines should be:
Adding warnings or errors will help a user figure out how to properly create custom hover tools - there are not many examples and the user is many times clueless when not getting the expected results without understanding why.
The issues still exists in Bokeh 1.4.0.
The text was updated successfully, but these errors were encountered:
The code below attempts to create a custom hover tool using Holoviews.
However, this code is not successful and the custom function has no effect.
To fix this and let MyCustom function to execute, there is a need to do two changes in the Hover tool that are commented out in the code. When running the current ode, there is no error or warning message explaining what is wrong, yet instead of printing "test" for Phase an Freq, the system shows a hover tip where the freq and phase numbers are written:
The expected result after fixing the lines should be:
Adding warnings or errors will help a user figure out how to properly create custom hover tools - there are not many examples and the user is many times clueless when not getting the expected results without understanding why.
The issues still exists in Bokeh 1.4.0.
The text was updated successfully, but these errors were encountered: