Skip to content

Commit

Permalink
Unlimit the vdim bounds and add ability for additional vdim hover (#3193
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ahuang11 authored and philippjfr committed Nov 25, 2018
1 parent 80a037a commit 52b4e6c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion holoviews/element/raster.py
Expand Up @@ -246,7 +246,7 @@ class Image(Dataset, Raster, SheetCoordinateSystem):
of a string or dimension object.""")

vdims = param.List(default=[Dimension('z')],
bounds=(1, 1), doc="""
bounds=(1, None), doc="""
The dimension description of the data held in the matrix.""")

rtol = param.Number(default=None, doc="""
Expand Down
41 changes: 25 additions & 16 deletions holoviews/plotting/bokeh/raster.py
Expand Up @@ -27,8 +27,11 @@ def _hover_opts(self, element):
xdim, ydim = element.kdims
tooltips = [(xdim.pprint_label, '$x'), (ydim.pprint_label, '$y')]
if bokeh_version >= '0.12.16' and not isinstance(element, (RGB, HSV)):
vdim = element.vdims[0]
tooltips.append((vdim.pprint_label, '@image'))
vdims = element.vdims
tooltips.append((vdims[0].pprint_label, '@image'))
for vdim in vdims[1:]:
vname = dimension_sanitizer(vdim.name)
tooltips.append((vdim.pprint_label, '@{0}'.format(vname)))
return tooltips, {}

def __init__(self, *args, **kwargs):
Expand All @@ -38,40 +41,46 @@ def __init__(self, *args, **kwargs):

def get_data(self, element, ranges, style):
mapping = dict(image='image', x='x', y='y', dw='dw', dh='dh')
val_dim = [d for d in element.vdims][0]
val_dim = element.vdims[0]
style['color_mapper'] = self._get_colormapper(val_dim, element, ranges, style)

if self.static_source:
return {}, mapping, style

img = element.dimension_values(2, flat=False)
if img.dtype.kind == 'b':
img = img.astype(np.int8)

if type(element) is Raster:
l, b, r, t = element.extents
if self.invert_axes:
l, b, r, t = b, l, t, r
else:
img = img.T
else:
l, b, r, t = element.bounds.lbrt()
if self.invert_axes:
img = img.T
l, b, r, t = b, l, t, r

if self.invert_xaxis:
l, r = r, l
img = img[:, ::-1]
if self.invert_yaxis:
img = img[::-1]
b, t = t, b
dh, dw = t-b, r-l
data = dict(x=[l], y=[b], dw=[dw], dh=[dh])

for i, vdim in enumerate(element.vdims, 2):
if i > 2 and 'hover' not in self.handles:
continue
img = element.dimension_values(i, flat=False)
if img.dtype.kind == 'b':
img = img.astype(np.int8)
if 0 in img.shape:
img = np.array([[np.NaN]])
if ((self.invert_axes and not type(element) is Raster) or
(not self.invert_axes and type(element) is Raster)):
img = img.T
if self.invert_xaxis:
img = img[:, ::-1]
if self.invert_yaxis:
img = img[::-1]
key = 'image' if i == 2 else dimension_sanitizer(vdim.name)
data[key] = [img]

if 0 in img.shape:
img = np.array([[np.NaN]])

data = dict(image=[img], x=[l], y=[b], dw=[dw], dh=[dh])
return (data, mapping, style)


Expand Down

0 comments on commit 52b4e6c

Please sign in to comment.