plotly / plotly/plotly.js

Unhandled exception on "ctrl+left/right-click" drag or "shift+right-click" drag on a chart

Đang mở
#6,879 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug P2
Ngôn ngữ chính
JavaScript
Star
18.3k
Fork
2k
Merge trung bình
2 ngày 12 giờ
Pull request đã merge (30 ngày)
28

Mô tả

On a chart if I hold ctrl and try to drag with left-click or right-click or shift+right-click drag, then getting an exception.

After analyzing the code, I found that ctrl is treated as right-click, and if drag operation and right click then "options.moveFn(dx, dy);" function is not getting called which results in not updating "updates" for the dragTail() function that calls "_guiRelayout" with undefined updates and in that function exception is raised if updates are undefined. Pasting js code of these function below:

This issue can be replicated easily in plotly's samples as well. Just hold ctrl and drag with left/right-click, you can see error in console.

Attaching snapshot:

image

function onMove(e) {
  e.preventDefault();

  var offset = pointerOffset(e);
  var minDrag = options.minDrag || constants.MINDRAG;
  var dxdy = clampFn(offset[0] - startX, offset[1] - startY, minDrag);
  var dx = dxdy[0];
  var dy = dxdy[1];

  if (dx || dy) {
    gd._dragged = true;
    dragElement.unhover(gd);
  }

  if (gd._dragged && options.moveFn && !rightClick) {
    gd._dragdata = {
      element: element,
      dx: dx,
      dy: dy,
    };
    options.moveFn(dx, dy);
  }

  return;
}

// dragTail - finish a drag event with a redraw
function dragTail() {
  // put the subplot viewboxes back to default (Because we're going to)
  // be repositioning the data in the relayout. But DON'T call
  // ticksAndAnnotations again - it's unnecessary and would overwrite `updates`
  updateSubplots([0, 0, pw, ph]);

  // since we may have been redrawing some things during the drag, we may have
  // accumulated MathJax promises - wait for them before we relayout.
  Lib.syncOrAsync(
    [
      Plots.previousPromises,
      function () {
        gd._fullLayout._replotting = false;
        Registry.call("_guiRelayout", gd, updates);
      },
    ],
    gd
  );
}

function relayout(gd, astr, val) {
  gd = Lib.getGraphDiv(gd);
  helpers.clearPromiseQueue(gd);

  if (gd.framework && gd.framework.isPolar) {
    return Promise.resolve(gd);
  }

  var aobj = {};
  if (typeof astr === "string") {
    aobj[astr] = val;
  } else if (Lib.isPlainObject(astr)) {
    aobj = Lib.extendFlat({}, astr);
  } else {
    Lib.warn("Relayout fail.", astr, val);
    return Promise.reject(); // From here exception is raised
  }
  .... Rest of the code
}

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện lỗi trong các sample của Plotly bằng cách nhấn ctrl rồi kéo sang trái/phải hoặc nhấn shift rồi kéo sang phải, sau đó lần theo các hàm onMove và dragTail được hiển thị trong issue. Xác minh rằng thao tác kéo hoàn tất mà không truyền các bản cập nhật undefined vào _guiRelayout và ngoại lệ không còn xuất hiện trong console.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.