holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 402 forks source link

CustomJSHover does apply correctly to Image #4556

Open emryslda opened 4 years ago

emryslda commented 4 years ago

Dear everyone,

I am trying to use Geoviews with CustomJsHover tool to customize the interactive output. I have found a problem with the @image object when deal with custom "code", any idea? Thank you in advance. I would like to show NaNs as blank in the interactive map.

import numpy as np
import xarray as xr
import holoviews as hv
import geoviews as gv 
hv.extension('bokeh','matplotlib') 
import cartopy.crs as crs
from bokeh.models import HoverTool, CustomJSHover

x,y = np.mgrid[-50:51, -50:51] * 0.1
r = 0.5*np.sin(np.pi  +3*x**2+y**2)+0.5
r[r<0.5]=np.nan
coords=np.arange(0,101)
im_custom=CustomJSHover(code="""
                     return value + " tot"
                     """)

tooltips=[
  ("value","@image{1.1}"),   # GIVES RIGHT VALUE BUT WITH NaNs (0.1..0.6.. etc)
  ("value","@image{custom}") # GIVES some strange 0th, 1st, ... or NaN
]

hover = HoverTool(tooltips=tooltips, formatters={'image' : im_custom})

ds = xr.Dataset({'R': (['x', 'y'],r)},coords={'x': (['x'], coords),'y': (['y'], coords)})
ensemble = gv.Image(ds, kdims=['x', 'y'],vdims=[ 'R']).opts(tools=[hover])
ensemble
ppwadhwa commented 4 years ago

Sounds like a bug, but it might be at the bokeh level and not geoviews. Have you tried using this custom hover tool with a regular bokeh image?

jlstevens commented 4 years ago

Just a quick comment to note that this issue has been reproduced and it seems to be a problem using a HoloViews Image so it not a problem that is arising at the GeoViews level.