How to persist the hover template if you click whilst hovering?


I’m trying to get it so that if I’m hovering over a marker and the hover template is shown, that I can click to have the template stay where it is when I mouse away. Then you could click again to hide it. When a hover template is persisted the rest of the plot continues to show hover templates as they did before.

The idea is that people can highlight a few markers of interest before downloading an image.

I’ve seen some pointers about creating annotations on click. But it seems awkward to me to try to re-create the hover using an annotation?

This example seemed to do what I wanted: Hover events in JavaScript

I think the idea is to add a new trace when you click, but I don’t see how the new trace is set up to always show the hover text? Also, I found the sheer volume of data points and traces slowed down the tab to the point that the browser complained about the script and offered to kill it for me. I think this is the approach I want? But I couldn’t get it to work with my set up.

Am I on the right track? Is there something else I should be trying? Can anyone help me understand how the example works?


If anyone finds this post, I switched tactics and added an annotation on click, instead of trying to keep the hover template.