I am working with Plotly.js for a project and I would like to know if it was possible to trigger a plot action from a custom element.
For example, I would like to have a custom button somewhere on my page, triggering the Zoom in of my Plotly plot.
I have created a CodePen to explain it: http://codepen.io/anon/pen/ObMXoK
Here’s a couple examples of ways to accomplish this:
You can attach event listeners and call API commands directly:
(Note that you have to use + new Date(...) in order to convert to a unix timestamp. This will change soon in plotly/plotly.js#1078)
It looks like you might be using an older version of plotly. In new versions, there are now updatemenus that can accomplish this by calling API commands from within plotly.js components, as in:
This can be nice if you don’t want to worry about styling buttons etc. yourself. Finally, there are also animations which can make this smooth. See:
I couldn’t’ figure out how to trigger buttons without ‘relayout’. I couldnt even figure out how to trigger the ‘Reset Axes’ button through plotly at all.
If someone can help me understand how to expose the event handlers provided by @etienne, that would be great.
I have same problem and did a “hacky” solution to perform a click at a modebar buttons. Firstly I figured out all ‘datatitles’ of the modebarbuttons to identifiy one and save it in variables:
var modebarButtonDataTitles={//button names of plotly modebar
zoomIn : "Zoom in",
zoomOut : "Zoom out",
zoomMode: "Zoom",
panMode: "Pan",
downloadAsPng: "Download plot as a png",
autoscale: "Autoscale"
}
To perform a click e.g. to zoomIn-Modebar button I iterate over all modebar-btn and perform a click to that button, of that the dataTitle is ‘Zoom in’.