ABSTRACT

This chapter discusses the addition of custom event handlers in JavaScript. When using onRender() to provide a JS function to be called upon static render of a plotly object, the relevant DOM element (el) has an on() method that accepts a function to be called whenever a plotly.js (or DOM) event occurs on that DOM element. All plotly.js event handlers accept a function with a single argument, and that argument either contains nothing (e.g., "plotly_afterplot", etc.) or a single object with all the relevant information about the event (e.g., "plotly_hover", "plotly_selected", etc.). The chapter illustrates logging and inspection of data emitted during the "plotly_hover", "plotly_click", and "plotly_selected" events. The object emitted for these events includes a key, named points, with information tying the selection back to the input data.