Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Warnings should be reported for custom hover tool #9769

Open
Jacob-Barhak opened this issue Mar 10, 2020 · 0 comments
Open

[FEATURE] Warnings should be reported for custom hover tool #9769

Jacob-Barhak opened this issue Mar 10, 2020 · 0 comments
Milestone

Comments

@Jacob-Barhak
Copy link

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:
image

The expected result after fixing the lines should be:
image

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.

@bryevdv bryevdv added type: task and removed TRIAGE labels Apr 24, 2020
@bryevdv bryevdv added this to the short-term milestone Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants