import { PlotlyNotifier } from "../core/utils/PlotlyNotifier";
export { PlotlySelect2dButton }
/**
* Class extending plotly's select2d button.
*/
class PlotlySelect2dButton {
/**
* Creates the select2d button extension.
* @param {HTMLElement} graphDiv - Plotly graphDiv configuration.
*/
constructor(graphDiv) {
this.graphDiv = graphDiv;
this.countSelect = 0;
this.countDeselect = 0;
}
/**
* Include event listeners that react to events triggered by selections inside the plot.
*/
registerEvents() {
const showInfoMessage = (eventData) => {
const triggeredByDeselect = eventData === undefined;
if (triggeredByDeselect)
return
this.countSelect += 1;
if (this.countSelect == 1)
PlotlyNotifier.displayMessage("Double-click to deselect", 4000);
const isTouchDevice = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0);
if (this.countSelect == 2 && !isTouchDevice)
PlotlyNotifier.displayMessage("Hold shift to add multiple selections", 4000);
}
this.graphDiv.on('plotly_selected', showInfoMessage.bind(this));
}
}