Unhandled exception on "ctrl+left/right-click" drag or "shift+right-click" drag on a chart
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 18.3k
- 派生
- 2k
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 28
描述
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:
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
}
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
在 Plotly 的 samples 中,通过按住 ctrl 向左/右拖动或按住 shift 向右拖动来重现该故障,然后跟踪 issue 中所示的 onMove 和 dragTail 函数。验证拖动完成时不会将 undefined 更新传递给 _guiRelayout,并且控制台中不再出现该异常。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100