Hey team! Looking for the ability to be able to capture a zoom event on a plotly chart in hopes I can preserve the zoom on a rerender.
I have a chart in which the user can pick a start date down to the fractional second. When the user picks a new time, the chart is rendered again to move the vertical line indicating the start time. However, since it was rendered again, the original zoom lost.
I have searched through these forums and saw that a lot of the zoom events aren’t exposed, but just hoping to see if there was a workaround or something that I am missing.
Exactly which component are you using? A screenshot would be very helpful as well.
I was looking at the Event Handlers and it seems we do not expose a 'zoom' option, but I can definitely make a feature request to have a click+zoom event handler to then bind to events.
Hey Jack, thanks for the reply. I am using the Chart component but using the Plotly JSON options to dynamically pass my chart data in. Having the zoom events exposed would be great for my situation.
My usage would be a user can zoom in, select a specific date, this chart updates a line on the chart, but instead of having to do a full re render which causes the zoom to reset, I would be able to ‘save’ whatever zoom is currently in use and reuse it on the re render.
Yes, you can do this without manually saving the zoom.
Since you're using the Chart component with Plotly JSON, just add the uirevision property to your layout. That tells Plotly to keep the current zoom and UI state when the chart updates.
Add this to your layout:
{
"uirevision": "keep-zoom"
}
As long as "keep-zoom" doesn’t change between renders, Plotly will preserve: