plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

Option to disable right mouse button events (specifically RMB drag)

Open secretwpn opened this issue 4 years ago • 1 comments

There is an existing bug report (that for some reason did not get any traction): #5311

If fixing this issue specifically is far out of current roadmap or too complex - maybe it would be possible to add an option to disable right mouse button interactions altogether?

I've spent some hours trying to ignore various events (mouseup, oncontextmenu) for my plot and its parent components but was not able to stop Plotly from interacting with right mouse button drag.

secretwpn avatar Nov 19 '21 09:11 secretwpn

I tried to avoid this issue like below: I hope that your issue would be resolved: :^)

  setupRMouseDragBlocker() {
    this.owner.layout.xaxis.last_range = this.owner.layout.xaxis.range;
    this.owner.on(
      "plotly_relayout",
      function (data) {
        if ("xaxis.autorange" in data || "plot_mounted" in data) {
          console.log("data", data, "owner", this.owner.layout);
          if (this.owner.layout.xaxis.range) {
            this.owner.layout.xaxis.last_range = copy(this.owner.layout.xaxis.range);
          }
          return;
        }

        if ("xaxis.range[0]" in data) {
          const begin = data["xaxis.range[0]"];
          const end = data["xaxis.range[1]"];

          if (begin == end) {
            console.log(`prevent: begin:${begin}, end: ${end}`);
            // prevent re
            console.log(
              "plotly_relayout",
              data,
              "get last_range:",
              this.owner.layout.xaxis.last_range
            );
            const new_layout = this.graph.getLayout();
            new_layout.xaxis.range = this.owner.layout.xaxis.last_range;
            new_layout.xaxis.last_range = this.owner.layout.xaxis.last_range;
            Plotly.relayout(this.owner, new_layout);
          } else {
            this.owner.layout.xaxis.last_range = [begin, end];
          }
        }
      }.bind(this)
    );
    Plotly.relayout(this.owner, { plot_mounted: true });
  }

Freddicola avatar Jul 28 '22 07:07 Freddicola