hover.tooltip convenience function for 'datetime' info
See original GitHub issueIt would be nice to make it easy to create a “hover” tooltip template that could do some simple conversions/formatting on “standard” data point information: x, y, size, color, etc. Maybe also some convenience conversions for source
attributes of data points.
My particular scenario has to do with providing a hover tooltip which displays a human-readable time stamp for the data point. The x-axis is configured as datetime
, but when I display $x
I get back a float (seconds since the epoch) which isn’t very readable. To get around this, I need to add a ColumnDataSource with a single field, like so:
source = ColumnDataSource(data=dict(
time=df.map(lambda x: x.strftime('%d-%m-%Y'))
))
and then I tell my tooltip to display ("time", "@time")
. This is workable, but it would be nicer if I could just do:
("time", "`stftime('%m-%d-%Y', $x)`"
or something similar to say “do a client-side conversion of $x
into something more human-readable”
Issue Analytics
- State:
- Created 9 years ago
- Reactions:12
- Comments:21 (7 by maintainers)
OK, scaling back to something slightly less ambitious. Will push a PR later today that provide for things like this:
Which yields:
So
formatters
can optionally specify one of"datetime"
,"printf"
, or"numeral"
for a CDS field name, which will usetz
,SPrintf
orNumbro
respectively when displaying values from that field.If no formatter is specified, it defaults to
Numbro
which preserves the current behaviorI think this leaves the door open for custom formatter models in the future, with something like
but I don’t want to tackle that right now because I don’t want to tackle decision about what if anything to do to merge tick formatter and text formatters right now.
There is more work to do than is humanly possible accomplish by the number of people currently available to do it. New contributors are always welcome. That is literally the only thing that can cause any improvement in issue resolution times at this point