It’s been a while since I tried… I poked around at docs and didn’t see it…
Is there any way to generate “tooltips” when using Plot? What i mean is being able to hover over a point and see a “popup” with additional information.
It’s been a while since I tried… I poked around at docs and didn’t see it…
Is there any way to generate “tooltips” when using Plot? What i mean is being able to hover over a point and see a “popup” with additional information.
FWIW, I’m trying to do something simple like this:
Plot.line(output, {
x: "timestamp", y: "psi",
curve: "catmull-rom",
stroke: "blue",
marker: "circle",
title: d => `${d.psi} psi`
}),
Hi!
** Edited this solution based on the reply below from @mbostock **
Hope that helps!
Thank you!
The example you gave should work almost exactly as you’ve written it. However, there are a few things to be aware of with the browser-native tooltips used by the title channel:
On the plus side, browser native tooltips have some nice attributes that cannot be achieved with custom tooltips: they can appear over any other content in the browser (they are not limited to the sandboxed iframe in which your notebook code runs); they can appear outside the browser window entirely; and they disappear automatically whenever you click or move the mouse.
Here’s a screenshot and example:
Plot.plot({
marks: [
Plot.lineY(aapl, {x: "Date", y: "Close"}),
Plot.lineY(aapl, {x: "Date", y: "Close", stroke: "transparent", strokeWidth: 20, title: d => `${d.Close}\n${d.Date.toLocaleDateString("en", {timeZone: "UTC"})}`}),
]
})
Interesting! I’m sure I was moving to quickly, then. I did just bring in @mkfreeman’s tooltips, which act more like I wa expecting and more like what I was getting in Vega-Lite.
I appreciate the buffer idea, too… thanks!