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

Add datetime hover information for selector #6023

Merged
merged 7 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ def _apply_datashader(self, dfdata, cvs_fn, agg_fn, agg_kwargs, x, y):
val[neg1] = "-"
elif val.dtype.kind == "O":
val[neg1] = "-"
elif val.dtype.kind == "M":
val[neg1] = np.datetime64("NaT")
else:
val = val.astype(np.float64)
val[neg1] = np.nan
Expand Down
7 changes: 5 additions & 2 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -1784,8 +1784,11 @@ def _postprocess_hover(self, renderer, source):
if not isinstance(hover.tooltips, str) and 'hv_created' in hover.tags:
for k, values in source.data.items():
key = '@{%s}' % k
if ((isinstance(value, np.ndarray) and value.dtype.kind == 'M') or
(len(values) and isinstance(values[0], util.datetime_types))):
if (
(isinstance(value, np.ndarray) and value.dtype.kind == 'M') or
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
(len(values) and isinstance(values[0], util.datetime_types)) or
(len(values) and isinstance(values[0], np.ndarray) and values[0].dtype.kind == 'M')
):
hover.tooltips = [(l, f+'{%F %T}' if f == key else f) for l, f in hover.tooltips]
hover.formatters[key] = "datetime"

Expand Down
18 changes: 15 additions & 3 deletions holoviews/plotting/bokeh/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _hover_opts(self, element):
tooltips.append((vdims[0].pprint_label, '@image'))
for vdim in vdims[1:]:
vname = dimension_sanitizer(vdim.name)
tooltips.append((vdim.pprint_label, f'@{vname}'))
tooltips.append((vdim.pprint_label, f'@{{{vname}}}'))
return tooltips, {}

def _postprocess_hover(self, renderer, source):
Expand All @@ -52,8 +52,6 @@ def _postprocess_hover(self, renderer, source):
if not (hover and isinstance(hover.tooltips, list)):
return

element = self.current_frame
xdim, ydim = (dimension_sanitizer(kd.name) for kd in element.kdims)
xaxis = self.handles['xaxis']
yaxis = self.handles['yaxis']

Expand All @@ -73,6 +71,20 @@ def _postprocess_hover(self, renderer, source):
formatters['$y'] = yhover
formatter += '{custom}'
tooltips.append((name, formatter))

datetime_code = """
if (value === -9223372036854776) {
// NaN value
return "-"
} else {
const date = new Date(value);
return date.toISOString().slice(0, 19).replace('T', ' ')
}
"""
for key in formatters:
if formatters[key].lower() == "datetime":
formatters[key] = CustomJSHover(code=datetime_code)

hover.tooltips = tooltips
hover.formatters = formatters

Expand Down