Is is possilble to get mouse/click position?

The goal
I use Python with plot.ly for plotting candlestick charts and I need a measuring tool for getting distance between 2 elements. Example:
Peek 2020-07-09 17-07
The lib doesn’t have such a tool so I tried to write it. My logic is - handle first mouse click on a chart, then handle all mouse moves and plot new line/box on the chart.

I tried:

  1. Get position with clickData and hoverData but it returns only clicked element. I can’t get an exact point, when I click on the candle it returns full candle’s data and I need just point. Also, the events will return nothing when I click outside of an element.
  2. Get mouse position with JavaScript. I’ve tried this example, it works but it returns the position of the mouse inside of browser window and it’s impossible to get data from the chart (price and date).

Also, I was reading about plot.ly plugins. Is it possible to create such a tool with plugin?

Thanks in advance :smiley:.

you might be able to use the new drawing tools cc @Emmanuelle

Are they still in development?

Hi @vovawed you could indeed draw a line or a rectangle on the graph, using one of the drawing dragmodes introduced with plotly 4.7 and write a callback which would compute the length of the line, as in this post.

1 Like

Thanks for your reply. Can you please tell me is it possible to edit drawn shapes from code? I’ve tried to get a graph.figure.shapes via callback but there aren’t drawn shapes.